前一段学习了Python的语音识别,感觉超级强大,我本来想写出来一个简易的Siri,但是对于学习算法掌握太差,不知从何写起,就暂时先写了一个简易的语音助手,但是是手动定义控制语句,不清楚已经商业化的语音助手是如何实现的,感觉写的特别菜,大家可以交流一下这方面的心得。
首先,实现代码:
import speech
import win32api
import os
##while True:
## words=raw_input("Please input some words:")
## if words.lower()=='stop':
## break
## speech.say(words)
##contents=speech.input("Say something,please.")
##speech.say(contents)
##print(contents)
if __name__=='__main__':
Start='你在哪'.decode('gbk')
Hello='你好'.decode('gbk')
Control='关闭语音控制'.decode('gbk')
openPython='我要写代码'.decode('gbk')
openMusic='我要听音乐'.decode('gbk')
stormPlayer='我要看电影'.decode('gbk')
tencentQQ='我要'.decode('gbk')
listenMusic='我累了'.decode('gbk')
Hawk='你是谁'.decode('gbk')
Users='你知道我是谁么'.decode('gbk')
Love='你喜欢我么'.decode('gbk')
## judge=speech.input()
## while True:
## if(judge == Start):
## speech.say("我在这呢,你说吧")
## break
while True:
words=speech.input("Say you want to do.")
##print(words)
if(words == Control):
speech.say("已关闭语音控制")
break
elif(words == Hello):
speech.say("你也好,今天过得怎么样")
elif(words == openPython):
os.system('D:\Python\python.exee')
## win32.api.ShellExecute(0,'open','D:\Python\python.exe','','',0)
## win32.api.ShellExecute(0,'open','D:\Python\python.exe','','',1)
elif(words == openMusic):
os.system('D:\QQ音乐\QQMusic\QQMusic.exe')
## win32.api.ShellExecute(0,'open','D:\QQ音乐\QQMusic\QQMusic.exe','','',0)
## win32.api.ShellExecute(0,'open','D:\QQ音乐\QQMusic\QQMusic.exe','','',1)
elif(words == stormPlayer):