当我运行bingtest.py时,我收到以下错误。
我尝试过使用命令
sudo pip install PyAudio
但它似乎不起作用。
Traceback (most recent call last):
File "bingtest.py", line 8, in <module>
m = sr.Microphone()
File "/usr/local/lib/python2.7/dist-
packages/speech_recognition/__init__.py", line 79, in __init__
self.pyaudio_module = self.get_pyaudio()
File "/usr/local/lib/python2.7/dist-
packages/speech_recognition/__init__.py", line 113, in get_pyaudio
raise AttributeError("PyAudio 0.2.11 or later is required (found
version {})".format(pyaudio.__version__))
AttributeError: PyAudio 0.2.11 or later is required (found version 0.2.8)
bingtest.py
#!/usr/bin/env python3
# NOTE: this example requires PyAudio because it uses the Microphone
class
import os
import speech_recognition as sr
import time
r = sr.Recognizer()
m = sr.Microphone()
def callback(recognizer,audio):
BING_KEY = "xxxxxx" # Microsoft Bing Voice Recognition
try:
var=r.recognize_bing(audio, key=BING_KEY)
print("audio listened...")
print("Microsoft Bing Voice Recognition thinks you said " + var)
if(var=="open chrome"):
os.system("google-chrome")
except sr.UnknownValueError:
print("Microsoft Bing Voice Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))
return
def call_bing():
# obtain audio from the microphone
with m as source:
print ("say something:")
r.adjust_for_ambient_noise(source)
stop_listening = r.listen_in_background(m,callback)
for _ in range(60): time.sleep(0.1)
stop_listening()
call_bing()
print "returned to main from bing function"
call_bing()
call_bing()
答案 0 :(得分:0)
也尝试一下。首先,您必须安装PyAudio,然后使用pip升级
sudo pip install PyAudio
pip install --upgrade PyAudio