借助百度api,用python实现. 思路 使用python录音并保存为文件 调用api,得到识别结果 根据结果打开对应url 只贴了关键代码,完整代码请移步:https://github.com/missyoursmile/Command-a-computer-with-sound #定义命令字典(不知道为何百度会识别成这样,牛客识别不出来,用了部分识别) url_dict = { u'baidu': "https://www.baidu.com", u'牛': "https://www.nowcoder.com" } #录音并保存到文件(在另外一个文件中) wavfile = record_wave() #获取token access_token = requests.post(auth_url).json()['access_token'] res = None with open(wavfile,'rb') as f: r = requests.post(api_url+access_token, headers={'Content-Type': "audio/wav;rate=8000"}, data=f) res = r.json() if res['err_no'] != 0: #识别错误 res = None if not res: print "识别错误" exit() open_url = None for k in url_dict: if k in res['result'][0]: open_url = url_dict[k] print "识别结果: ",res['result'][0] if not open_url: print "没有对应的命令." exit() #调用系统命令,打开浏览器 os.system("explorer "+ open_url) 注意 只实现了Windows平台,其他平台请自行修改最后的系统调用 部分词汇可能难以识别,使用了部分匹配 公开了api key, 方便大家使用,请不要滥用,谢谢 如有好的离线语音识别库,请告诉我
点赞 2

相关推荐

千千倩倩:简历问题有点多,加v细聊
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务