-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot.py
44 lines (33 loc) · 1.06 KB
/
robot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
"""
__autor__ : AnE
"""
from voice import Voice
import voiceAPI
def main():
voice = Voice()
baiduAPI = voiceAPI.BaiDuAPI()
turlingAPI = voiceAPI.TurLingAPI()
baiduAPI.getToken()
while True:
voice.recordVoice()
recognition_result = baiduAPI.voiceRecognition()
if recognition_result:
if "退出对话" in recognition_result:
break
reply_result = turlingAPI.turlingReply(recognition_result)
if reply_result:
url = baiduAPI.voiceSynthesis(reply_result)
voice.playVoice(url)
else:
url = baiduAPI.voiceSynthesis("对不起,获取回复失败")
voice.playVoice(url)
continue
else:
url = baiduAPI.voiceSynthesis("对不起,识别失败")
voice.playVoice(url)
continue
url = baiduAPI.voiceSynthesis("退出成功")
voice.playVoice(url)
if __name__ == '__main__':
main()