speech模組實現語音識別
阿新 • • 發佈:2019-01-04
1.pip安裝speech、pywin32
pip install speech pip install pywin32
2.例子
#!/usr/bin/python # coding:utf-8 from __future__ import unicode_literals import speech import os import sys import webbrowser __author__ = "klx" # Create your views here. phrase = { "closeMainSystem": "關閉", "film": "電影", "listenMusic": "好累", "blog": "部落格", "cmd": "命令", "baidu": "百度", } def callback(phr, phrase): if phr == phrase["closeMainSystem"]: speech.say("Goodbye. 人機互動即將關閉,謝謝使用") speech.stoplistening() sys.exit() elif phr == phrase["film"]: speech.say("正在為您開啟優酷") webbrowser.open_new("http://www.youku.com/") elif phr == phrase["listenMusic"]: speech.say("即將為你啟動豆瓣電臺") webbrowser.open_new("http://douban.fm/") elif phr == phrase["blog"]: speech.say("即將進入Dreamforce.me") webbrowser.open_new("http://www.cnblogs.com/darksouls/") elif phr == phrase["cmd"]: speech.say("即將開啟CMD") os.popen("C:\Windows\System32\cmd.exe") elif phr == phrase["baidu"]: speech.say("百度一下") webbrowser.open_new("http://www.baidu.com/") else: speech.say("say again") webbrowser.open_new("http://www.baidu.com/s?wd=" + phr) def main(): while True: phr = speech.input() speech.say("You said %s" % phr) callback(phr, phrase) def test(request): main()
ps:
pywin32模組實現com(元件物件模型),實現不同應用程式或者不同語言之間的二進位制通訊標準