2

I was wondering whether there is a way to output words as soon as possible. For example if I say "hello world" it should output:

hello 
world 

Currently I'm using this code

import speech_recognition as sr

r = sr.Recognizer()

with sr.Microphone() as source:
    while True:
        r.pause_threshold=0.1 ##i tried playing with these 3 but no luck
        r.phrase_threshold=0.5
        r.non_speaking_duration=0.1
        audio = r.listen(source)
        try:
            text = r.recognize_google(audio)
            print(text)
        except Exception as e:
            print("-")

What this does is that it records until the mic doesn't hear anything and then outputs everything that it heard in one line, I want to see what has been said as quickly as possible.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Won't this kind of information be found in the documentation for the library you're using? Also, don't use `except Exception:` like that, see https://stackoverflow.com/questions/54948548/what-is-wrong-with-using-a-bare-except. – AMC Mar 14 '20 at 16:38

0 Answers0