无法通过python SpeechRecognition模块中的麦克风识别语音

问题描述 投票:0回答:2

运行该程序时,如果使用头戴式耳机或外接麦克风,语音将被识别。但是,如果我使用笔记本电脑的麦克风(Microphone Array(Realtek(R)Audio)),则语音无法识别。就像程序挂在audio = r.listen(source)行上一样。如果我说了些什么然后插入耳机,则该程序可以工作。笔记本电脑中的麦克风运行正常。

import speech_recognition as sr
import pyaudio

r = sr.Recognizer()
with sr.Microphone() as source:
    print("Listening......")
    audio = r.listen(source)

    try:
        print("Recognizing...")    
        query = r.recognize_google(audio, language='en-in')
        print(f"USER: {query}\n")

    except Exception:
        print("Did not catch that")  

为什么会这样?有人可以帮我吗?

谢谢。

python speech-recognition microphone
2个回答
1
投票

r.adjust_for_ambient_noise(source)我使用了此功能,并且现在可以使用。这会增加识别音频的范围。

谢谢大家。


0
投票

我猜。

可能它使用外接麦克风作为默认设备,并且您必须手动设置其他设备。

documentation中您可以看到

Microphone(device_index = None)

A device index is an integer between 0 and pyaudio.get_device_count() - 1 

您也可以看到

import speech_recognition as sr

for index, name in enumerate(sr.Microphone.list_microphone_names()):
    print("Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))

BTW:您也可以阅读Troubleshooting-也许它提供了更多的想法。

© www.soinside.com 2019 - 2024. All rights reserved.