1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/mjTree-voice_chat_robot

В этом репозитории не указан файл с открытой лицензией (LICENSE). При использовании обратитесь к конкретному описанию проекта и его зависимостям в коде.
Клонировать/Скачать
voiceRobot 1.2 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
mjTree Отправлено 31.03.2018 13:17 0880829
#!coding:utf8
import sys
import pyttsx
import requests
import speech
KEY = '**********************'
#在图灵机器人官网注册的一个API-->http://www.tuling123.com
"""
function: 接收用户语音,转成文字
return: 用户的言语文字
"""
def AcceptDialogue():
phrase = speech.input()
return phrase.encode('gb2312')
"""
function: 接收用户对话,返回相应对话
parameter: msg 用户描述的言语
return: 反馈用户的言语
"""
def get_response(msg):
apiUrl = 'http://www.tuling123.com/openapi/api'
data = {
'key' : KEY,
'info' : msg,
'userid' : 'wechat-robot',
}
try:
r = requests.post(apiUrl, data=data).json()
return r.get('text')
except:
return "没听懂你说的啥"
"""
function: 接收文字,转成语音
parameter: 反馈用户的言语
"""
def saySth(content):
reload(sys)
sys.setdefaultencoding("utf-8")
engine = pyttsx.init()
engine.say(content)
engine.runAndWait()
"""
function: 调用子模块实现语音聊天
"""
def main():
while True:
msg = AcceptDialogue()
content = get_response(msg)
saySth(content)
main()

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/mjTree-voice_chat_robot.git
git@api.gitlife.ru:oschina-mirror/mjTree-voice_chat_robot.git
oschina-mirror
mjTree-voice_chat_robot
mjTree-voice_chat_robot
master