700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python使用微软公司语音识别功能 进行语音识别

python使用微软公司语音识别功能 进行语音识别

时间:2022-02-18 16:40:00

相关推荐

python使用微软公司语音识别功能 进行语音识别

1,实现语音操控的原理

语音操控分为语音识别和语音朗读两部分

我们使用speech模块实现语音模块(python 3.8.6)

用pip进行安装

2,启动语音识别,进行相关设置

此处仅为启动和关闭语音系统

import speechwhile True:phrase =speech.input()speech.say("You said %s"%phrase)if phrase =="turn off":break

3,用speech进行语音识别

import osimport sysimport speechimport webbrowserphrase = {"closeMainSystem" : "关闭人机交互", "film" : "我要看电影", "listenMusic" : "我好累啊", "blog" : "看博客", "cmd" : "cmd" }def callback(phr, phrase):if phr == phrase["closeMainSystem"]:speech.say("Goodbye. 人机交互即将关闭,谢谢使用")speech.stoplistening() sys.exit()elif phr == phrase["film"]:speech.say("正在为您打开优酷")webbrowser.open_new("/")elif phr == phrase["listenMusic"]:speech.say("即将为你启动豆瓣电台")webbrowser.open_new("http://douban.fm/")elif phr == phrase["blog"]:speech.say("即将进入Dreamforce.me")webbrowser.open_new("/darksouls/")elif phr == phrase["cmd"]:speech.say("即将打开CMD")os.popen("C:\Windows\System32\cmd.exe")# 可以继续用 elif 写对应的自制中文库中的对应操作while True:phr = speech.input()speech.say("You said %s" % phr)callback(phr, phrase)

4,测试

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。