speech recognition python code not working

后端 未结 13 1757
傲寒
傲寒 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 10:58

    have you tried replacing

        print("You said " + r.recognize(audio))
        except LookupError:                          
        print("Could not understand audio")
    

    with

        text = r.recognize_google(audio)
        print("You said : {}".format(text))
        text = r.recognize_google(audio)
        except:
            print("Sorry could not recognize your voice")
    

    ensure pyaudio.h is installed by running the below command

        sudo apt-get install portaudio19-dev python-pyaudio python3-pyaudio
    

提交回复
热议问题