def recognize(source): r = Recognizer() source.stream.start_stream() audio = r.listen(source) source.stream.stop_stream() vprint(4, "Finished recording.") try: vprint(0, "You said " + r.recognize(audio)) except LookupError: vprint(0, "Could not understand audio")
def recognize_wav(filename, language="en-US", show_all=True): recognizer = Recognizer(language=language) with WavFile(filename) as source: audio_data = recognizer.record(source) return recognizer.recognize(audio_data, show_all)