SpeechRecognition产生OSError:无默认输入设备可用

时间:2019-05-12 05:23:10

标签: python python-3.6 speech-recognition pyaudio

此:

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("Sorry could not recognize what you said")

产生这个:

Traceback (most recent call last):
  File "magic.py", line 5, in <module>
    with sr.Microphone() as source:
  File "/home/myPorfile/anaconda3/envs/customEnv/lib/python3.6/site-packages/speech_recognition/__init__.py", line 86, in __init__
    device_info = audio.get_device_info_by_index(device_index) if device_index is not None else audio.get_default_input_device_info()
  File "/home/myPorfile/anaconda3/envs/customEnv/lib/python3.6/site-packages/pyaudio.py", line 949, in get_default_input_device_info
    device_index = pa.get_default_input_device()
OSError: No Default Input Device Available

很明显,Pyaudio没有检测到我的耳机或计算机的麦克风。

sr.Microphone.list_microphone_names()通过返回一个空列表[]进行验证。

我还尝试安装Pyaudio和portaudio。

使用:Ubuntu 18.04.2 LTS / python 3.6

0 个答案:

没有答案