0

I'm trying to follow this example: https://www.thepythoncode.com/article/using-speech-recognition-to-convert-speech-to-text-python

I try to follow the example with speech recognition with microphone. I made this code below:

class Voice:
    def __init__(self) -> None:
        import speech_recognition as sr

        r = sr.Recognizer()

        print("Recognizing...")
        with sr.Microphone() as source:
            # read the audio data from the default microphone
            audio_data = r.record(source, duration=5)

            # convert speech to text
            text = r.recognize_google(audio_data, language="es-ES")
            print(text)
new_voice = Voice() 

I just get the right result when I use r.record with a specific duration like 5 sec:

audio_data = r.record(source, duration=5)

But I want something similar as the google, that recognize when the user stop to talk.

I tried this 3 others way, but without return:

            audio_data = r.listen(source)
            audio_data = r.listen(source, timeout=2)
            audio_data = r.record(source)

The terminal doesn't give me any error, it's like it's waiting for me to talk or something.

I fount in the record method documentation:

Records up to duration seconds of audio from source (an AudioSource instance) starting at offset (or at the beginning if not specified) into an AudioData instance, which it returns.

If duration is not specified, then it will record until there is no more audio input.

However i literally mute the mic after speaking and even then the terminal stayed the same.

  • "The terminal doesn't give me any error, it's like it's waiting for me to talk or something." Well, did you try talking? Is the microphone working? *How* do you want the program to determine that you have finished talking? – Karl Knechtel Nov 14 '21 at 18:16
  • @KarlKnechtel like I said, I'd like him to recognize when I'm done talking, maybe when the input volume goes down – Felipe Cristiano Nov 14 '21 at 18:19
  • Okay. What if you aren't already talking when the program gets to that point? It should use some similar rule to make sure you *started* talking first? Do you see anything in the documentation about this? How about if you search for information or tutorials? Please see https://meta.stackoverflow.com/questions/261592. – Karl Knechtel Nov 14 '21 at 18:21
  • @KarlKnechtel I search in this 3 topics: https://stackoverflow.com/questions/56200907/can-i-control-the-start-finish-time-when-i-use-speech-recognition-in-python https://stackoverflow.com/questions/56200907/can-i-control-the-start-finish-time-when-i-use-speech-recognition-in-python https://stackoverflow.com/questions/65641455/how-do-i-give-the-time-duration-of-listening-to-python-speech-recognition-librar but they didn't solve my problem. – Felipe Cristiano Nov 14 '21 at 18:28

0 Answers0