无法在CoLAB中使用SpeechRecognition库。
代码:
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak Anything: ")
audio = r.listen(source)
try:
text = r.recognize_google(audio)
print("You said: {}".format(text))
except:
print('Wrong')
我点安装了以下内容:
!apt install libasound2-dev portaudio19-dev libportaudio2 libportaudiocpp0 ffmpeg
!pip install pyaudio
!pip install ConfigParser
!apt-get install python-gnuradio-audio-portaudio
!python -m pip install pyaudio
!pip install SpeechRecognition
错误显示:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-34-65e65421018d> in <module>()
4 r = sr.Recognizer()
5
----> 6 with sr.Microphone() as source:
7 print("Speak Anything: ")
8 audio = r.listen(source)
1 frames
/usr/local/lib/python3.6/dist-packages/pyaudio.py in get_default_input_device_info(self)
947 """
948
--> 949 device_index = pa.get_default_input_device()
950 return self.get_device_info_by_index(device_index)
951
OSError: No Default Input Device Available
-------------------------------------------------------------------------
仅供参考,我正在为此使用Google CoLAB。 -提前感谢!