python的语音接入

阿里云语音服务zabbix告警

[TOC]

参考地址:https://www.gl.sh.cn/2019/06/21/python_jiao_ben_bo_da_dian_hua_gao_jing.html
官网:https://help.aliyun.com/document_detail/393517.html?spm=a2c4g.11186623.0.0.4a792b82Brqni2

一 准备工作

1.1 sdk下载

https://open.aliyun.com/sdk?language=python&product=dyvmsapi

或者

pip install aliyun-python-sdk-dyvmsapi

1.2 语音模版

1.3 样例

https://help.aliyun.com/document_detail/147108.html

二 代码

#!/usr/bin/env python
#coding=utf-8

import sys
import datetime
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
client = AcsClient('dX************Q', '00**********vw', 'default')

src = sys.argv[1]
title = sys.argv[2]
note = sys.argv[3]
phone = sys.argv[4]
data = "{\"src\": \""+src+"\",\'title\': \'"+title+"\',\"note\": \""+note+"\"}"
print(data)
request = CommonRequest()
request.set_accept_format('json')
request.set_domain('dyvmsapi.aliyuncs.com')
request.set_method('POST')
request.set_protocol_type('https') # https | http
request.set_version('2017-05-25')
request.set_action_name('SingleCallByTts')

request.add_query_param('CalledShowNumber', "021*******6")
request.add_query_param('CalledNumber', phone)
request.add_query_param('TtsCode', "TTS_168285137")
request.add_query_param('TtsParam', data)

response = client.do_action(request)
#print(response)
file = r'/tmp/'+datetime.datetime.now().strftime('%Y-%m-%d')+'_call.log'
date = time1 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
with open(file, 'a+') as f:
     f.write(date+':'+response+'\n'+data+'\n')
#print(str(response, encoding = 'utf-8'))

twili电话调用

[TOC]

官网:https://www.twilio.com/docs/libraries/python
参考文档:https://daimajiaoliu.com/daima/476240b91100409

一 准备工作

1 安装库

安装库的最简单方法是从 PyPi 中使用pip,这是 Python 的包管理器。只需在终端中运行它:

pip3 install twilio

如果出现pip: command not found错误,也可以使用easy_install. 在您的终端中运行它:

easy_install twilio

2手动安装

或者,您可以下载 的源代码 (ZIP),twilio-python然后运行以下命令安装库:

python3 setup.py install

在包含 twilio-python 库的文件夹中。

3“没有权限”

如果命令行给您一个很长的错误消息,中间显示Permission Deniedsudo ,请尝试使用(例如, )运行上述命令sudo pip3 install twilio。

4 验证客户端

from twilio.rest import Client

account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

二 代码

# coding:utf-8
from twilio.rest import Client  # 先导入

# sid和token都是在twilio网站的个人设置中看到的
account_sid ='AC4d79e18fd3a75ab644598348e510375e'
auth_token ='6893b0ce47570760803ad5db4cc210ac'
# 实例化
client = Client(account_sid, auth_token)

# 开始发短信
def send_msg(message):
    u'自定义短信内容message'
    msg = client.messages.create(
        to='+8615651797525',  # 要给谁发短信, 必须带区号, 中国要加上+86
        from_='+12013351008', # 你自己twilio网站申请的手机号码, 必须带上+号
        body=message  # 你的短信内容
    )

# 开始打电话
def call_num(number):
    u'自定义打电话的号码'
    call = client.calls.create(
        to='+86'+number,  # 要给谁打电话, 必须带区号, 中国要加上+86
        from_='+12013351008', # 你自己twilio网站申请的手机号码, 必须带上+号
        url="http://demo.twilio.com/docs/voice.xml" # 要播放的mp3
    )

if __name__ == '__main__':
    send_msg('伤心')

钉钉电话调用

[TOC]

1 钉钉开发者平台

https://open-dev.dingtalk.com/#/

2 发送应用内钉

https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.41e63ae8XBGGw5#/?devType=org&api=exclusive_1.0%23SendAppDing

2.1 获取access——token

https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.41e63ae8XBGGw5#/?devType=org&api=dingtalk.oapi.gettoken

2.2 填写小程序内的

appkey和appsecret


https://open-dev.dingtalk.com/fe/app?spm=a2q3p.21071111.0.0.261e65eexsrrd6#/appMgr/inner/eapp/1529833365/1

3 钉钉管理后台

https://oa.dingtalk.com/#/welcome

4 需要开通专属钉功能

https://page.dingtalk.com/wow/dingtalk/act/zsdd?spm=a311a.7996332.0.0.42ab15b5L2fJj3