对着电脑吼一声,自动打开谷歌网站或者自动打开命令行终端--使用google speech 语音识别程序操作电脑
1)更新源文件:@ubuntu:~$ sudo vim /etc/apt/sources.list
deb http://cn.archive.ubuntu.com/ubuntu precise main restricted universe
2)更新源文件后,要 update:sudo aptitude update
3)我自己数据库有问题,重新安装mysql数据库:
@ubuntu:~$ aptitude search mysql-server
sudo aptitude reinstall mysql-server
@ubuntu:~$ aptitude install mysql-server
@ubuntu:~$ aptitude purge mysql-server
4)安装相关的包以及依赖环境:
sudo easy_install wave
~/pyvoice$ sudo aptitude install flac 此工具将 wav 转换成 flac
5)思路:
输入--处理--输出
1:获取电脑录音-->WAV文件
python record wav
2:录音文件-->文本
STT: Speech to Text
STT API Google API
TTS: Text to Speech
3:文本-->电脑命令
6)代码:
#coding=utf-8import osf = open("1.txt","r")cmds = f.read()f.close()def run_browser(cmds): if cmds.find("谷歌") > -1: os.system("firefox www.google.com") if cmds.find("百度") > -1: os.system("firefox www.baidu.com") if cmds.find("新浪") > -1: os.system("firefox www.sina.com.cn")def run_term(cmds): if cmds.find("终端") > -1: os.system("gnome-terminal")def run_gedit(cmds): if cmds.find("编程") > -1: os.system("gedit test.py")def run_jeap(cmds): count = 0 if cmds.find("智") > -1: count += 1 if cmds.find("志") > -1: count += 1 if cmds.find("只") > -1: count += 1 if cmds.find("支") > -1: count += 1 if cmds.find("普") > -1: count += 1 if cmds.find("扑") > -1: count += 1 if cmds.find("谱") > -1: count += 1 if count > 1: os.system("firefox www.jeapedu.com")run_browser(cmds)run_jeap(cmds)run_term(cmds)run_gedit(cmds)
7)运行:
jiangge@ubuntu:~/pycode/pyvoice$ python recordtest.py 1.wav;python stt_google.py ;python runcmd.py
然后对着电脑喊"新浪"
会看到命令行变化:
flac 1.2.1, Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
welcome to redistribute it under certain conditions. Type `flac' for details.
1.wav: wrote 23004 bytes, ratio=0.621
新浪网
新浪吗
新浪
如果正常的话,你就会在浏览器上看到已经打开新浪网首页了.不正常的情况...嗯,Fuck GFW
----------------------------
参考文献:
http://uliweb.clkg.org/forum/3/210
代码作者为@hejiasheng