python-3.xpycharmspeech-recognition

I'm not able to see my text output using speech_recognition in Python


I'm working on a VA Project using Python. I need some help when it comes to seeing my text output in the terminal. My code is all correct. And my mic is brand new and set up. Idk why I can't see what I speak as text in the terminal. I think this is easy to answer, but I'm stuck. Here is my code...

import speech_recognition as sr
import pyaudio

r = sr.Recognizer()

with sr.Microphone() as source:
print('Say something')
audio = r.listen(source)
voice_data = r.recognize_google(audio)
print(voice_data)

Again, I don't get an error and this block of code: `

with sr.Microphone() as source:
print('Say something')
audio = r.listen(source)`

runs perfectly well. Do help me out. Thanks.


Solution

  • Your code is working fine in my compiler. But one thing is missing, it does not have a time limit for how many seconds the recognizer will recognize the voice. Maybe this is causing the error, so you can try adding just one thing(time limit) in your code. Refer below code:

    import speech_recognition as sr
    import pyaudio
    
    r = sr.Recognizer()
    
    with sr.Microphone() as source:
        print('Say something')
        audio = r.listen(source, phrase_time_limit = 5)  #recognizer will recognize voice for 5 seconds.
        voice_data = r.recognize_google(audio)
        print(voice_data)