标签:listening pywin32 you pytho 模块 force future code callback
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(组件对象模型),实现不同应用程序或者不同语言之间的二进制通讯标准
标签:listening pywin32 you pytho 模块 force future code callback
原文地址:https://www.cnblogs.com/konglingxi/p/10217629.html