代码拉取完成,页面将自动刷新
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from Recorder import recorder as rd
from SpeechRecognition import speechRecognition as sR
from RobotInteraction import robotInteraction as rI
from SpeechSynthesis import speechSynthesis as sS
"""
function: 接收用户语音,存储为wav音频文件
"""
def get_UserAudio():
rd.recording()
"""
function: 将音频文件转成文字信息
return: 转化成功后的文字信息
"""
def audio_word():
filename = "say_voice.wav"
userInfo = sR.speechRecognition(filename)
return userInfo
"""
function: 接收用户对话,返回相应对话
parameter: userInfo 用户描述的言语
return: 反馈用户的交互文字信息
"""
def getInteractiveInfo(userInfo):
feedbackInfo = rI.get_response(userInfo)
return feedbackInfo
"""
function: 接收用户语音,转成文字
return: 用户的言语文字
"""
def AcceptDialogue():
phrase = speech.input()
return phrase.encode('gb2312')
"""
function: 接收文字,转成语音播出
parameter: 反馈用户的言语
"""
def speechSyn(feedbackInfo):
sS.synthesisInfo(feedbackInfo)
sS.voiceBroadcast('hello.wav')
"""
function: 借用高级接口实现语音聊天
"""
def main():
while True:
get_UserAudio()
userInfo = audio_word()
print(userInfo)
feedbackInfo = getInteractiveInfo(userInfo)
print(feedbackInfo)
speechSyn(feedbackInfo)
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。