speech recognition python code not working

后端 未结 13 1750
傲寒
傲寒 2020-12-15 10:23

I am running the following code in Python 2.7 with pyAudio installed.

import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:             


        
相关标签:
13条回答
  • 2020-12-15 11:13

    try this code:

    r = sr.Recognizer()
    
    with sr.Microphone() as source:
            r.adjust_for_ambient_noise(source=source)
            audio = r.listen(source,timeout=3)
            
    
        
        data = ''
        try :
            data = r.recognize_google(audio)
            print(data)
    
        except sr.UnknownValueError:
            print(" Error")
            
        except sr.RequestError as e:
            print("Request Error")
    

    or add timeout and r.adjust_for_ambient_noise(source=source) to your code as above.please can anyone help me with this

    0 讨论(0)
  • 2020-12-15 11:14

    check the input volume of your microphone. It is by default set to 0 in ubuntu (in my case). Since your program got stuck on the line audio = r.listen(source), which simply means that the microphone is not able to listen to any voice input. Hope this helps.

    0 讨论(0)
  • 2020-12-15 11:16

    The possible reason could be that the recognizer_instance.energy_threshold property is probably set to a value that is too high to start off with. You should decrease this threshold, or call recognizer_instance.adjust_for_ambient_noise(source, duration = 1). You can learn more about it at Speech Recognition

    0 讨论(0)
  • 2020-12-15 11:20

    just try;

    pip install sounddevice
    

    it works.

    0 讨论(0)
  • 2020-12-15 11:21

    In addition to Tushar's answer, I suggest trying a nicer external USB microphone. PyAudio can have issues with a simple built-in laptop microphone.

    0 讨论(0)
  • 2020-12-15 11:21

    Please set minimum threshold.

    After running commend python -m speech_recognition. Set minimum energy threshold which it display.

    Setting procedure: press Ctrl then click mouse Recognizer(). Now set energy threshold.

    0 讨论(0)
提交回复
热议问题