0

getting no text output of what I speak when I run this program, it just shows: Listening...

I am not getting any errors, but the program don't give any voice to text output I don't understand what am I doing wrong, I have also installed pyaudio to connect my microphone so that's not the issue here, is it because I have not provided any delay if so then how can I do that?

import speech_recognition as sr

recognizer = sr.Recognizer()    #created recognizer object

#using microphone as source
with sr.Microphone() as source:
    print("Listening...")

    # Adjust for ambient noise
    recognizer.adjust_for_ambient_noise(source, duration=0.2)
    
    # Capture the audio
    audio = recognizer.listen(source)

#convert speech to text
try:
    # Recognize the speech
    text = recognizer.recognize_google(audio)   
    #using google speech recogonition api

    print("You said:", text)
except:
    print("Unable to recognize speech.")

I was expecting after some time when I speak, I may get a text output of what I spoke or and exception

Sanmeet
  • 1,191
  • 1
  • 7
  • 15
  • First make sure your microphone is working , second add timeout , if you're thinking your code gets stuck ( just another measure ) ... to add timeout just add timeout=2 kwarg in `.listen()` and then check for any errors again – Sanmeet Jun 24 '23 at 18:50

0 Answers0