Python Speech_recognition pyaudio错误

时间:2018-08-07 13:18:18

标签: python anaconda

我正在编写python代码来检测我的麦克风,但是Speech_recognition无法检测到我的输入设备。

import speech_recognition as sr
mic_index = 11
    for index, name in enumerate(sr.Microphone.list_microphone_names()):
        if("USB Device" in name):
            mic_index = index
            break

但这给了我错误。因此,我通过运行命令Speech Recognition检查了python -m speech_recognition模块,并收到以下错误:

Traceback (most recent call last):

File "/home/arqam/anaconda3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/arqam/anaconda3/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/arqam/anaconda3/lib/python3.6/site-packages/speech_recognition/__main__.py", line 4, in <module>
    m = sr.Microphone()
  File "/home/arqam/anaconda3/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/arqam/anaconda3/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

我检查了我的IO设备编号和pyAudio文件的位置,并给出了以下位置:

>>> pa.get_device_count()
0
>>> pyaudio.pa.__file__
'/home/arqam/anaconda3/lib/python3.6/site-packages/_portaudio.cpython-36m-x86_64-linux-gnu.so'

我已经看到了所有stackoverflow的答案,并且花了一整天的时间解决了这个问题,但是仍然找不到答案。

1 个答案:

答案 0 :(得分:-1)

以下内容为我解决了这个问题。

使用Anaconda:
安装speechrecognition类以及pyaudio

请确保您的麦克风处于活动状态并检查音频输入 设备。

使用以下简单代码:

import speech_recognition as sr

# obtain audio from the microphone r = sr.Recognizer() with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)
    enter code here
    try:
        text = r.recognize_google(audio)
        print('You said: {}'.format(text))
    except:
        print('Sorry google could not recognize your voice')