python 实现简单语音聊天机器人,, 1 # -*- c
python 实现简单语音聊天机器人,, 1 # -*- c
1 # -*- coding:utf-8 -*- 2 import sys 3 import requests 4 import json 5 import mp3play 6 import time 7 8 def talk(info): 9 appkey = "e5ccc9c7c8834ec3b08940e290ff1559"10 headers = {11 ‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit‘12 ‘/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safar‘13 ‘i/537.36‘,14 }15 url = "http://www.tuling123.com/openapi/api?key=%s&info=%s" %(appkey, info)16 content = requests.get(url, headers=headers)17 answer = json.loads(content.text)18 baidu_api = ‘http://tts.baidu.com/text2audio?idx=1&tex={0}&cuid=baidu_speech_‘ 19 ‘demo&cod=2&lan=zh&ctp=1&pdt=1&spd=4&per=4&vol=5&pit=5‘.format(answer[‘text‘])20 res = requests.get(baidu_api, headers=headers)21 with open(r‘E:\python_demo\tuling.mp3‘, ‘wb‘) as f:22 f.write(res.content)23 return answer[‘text‘]24 25 def main(info):26 info = info.decode(‘gb2312‘).encode(‘utf-8‘)27 answer = talk(info)28 mp3 = mp3play.load(r‘E:\python_demo\tuling.mp3‘)29 mp3.play()30 time.sleep(min(40, mp3.seconds()))31 mp3.stop()32 try:33 print ‘Tuling: %s‘ % answer34 except UnicodeEncodeError:35 print u‘我说了个啥子哟。‘36 37 if __name__ == ‘__main__‘:38 print u‘开始你的表演。‘39 while True:40 info = raw_input(‘Studog:‘)41 if info == ‘88‘:42 break43 main(info)
python 实现简单语音聊天机器人
相关内容
- 在.Net Framework中调用Python的脚本方法 (以VB和C#为例),
- python中检测mysql的主键唯一性异常,,有两种方法:1.直
- Python3之harbor sdk api,,环境python3源
- python中requests库get方法带参数请求,,起因是想爬五等分
- Python中where()函数的用法,,where()的用法
- VS2013中Python学习笔记[环境搭建],,前言 Python
- 使用python检测wifi中指定ip,并执行预设命令--手机连接
- python3 rsa 加解密 支持长字符串,,# rsa 加密de
- Python中for else和while else语句学习心得,,先比较两段代码
- 【python系统学习05】input函数——实现人机交互,,inpu
评论关闭