2023-06-12 16:06:24 +00:00
|
|
|
import time
|
|
|
|
import speech_recognition as sr
|
|
|
|
|
|
|
|
def callback(recognizer, audio):
|
|
|
|
try:
|
|
|
|
print("Processing...")
|
|
|
|
text = r.recognize_whisper(audio, language="english")
|
|
|
|
print(f"Apollo (Whisper Model) thinks you said: {text}")
|
|
|
|
except sr.UnknownValueError:
|
|
|
|
print("Could not understand audio.")
|
|
|
|
except sr.RequestError as e:
|
|
|
|
print("Could not request result from Whisper")
|
|
|
|
|
|
|
|
r = sr.Recognizer()
|
|
|
|
m = sr.Microphone()
|
|
|
|
|
|
|
|
with m as source:
|
|
|
|
r.adjust_for_ambient_noise(source)
|
|
|
|
|
|
|
|
stop_listening = r.listen_in_background(m, callback)
|
|
|
|
|
|
|
|
print("Listening...")
|
|
|
|
while True:
|
|
|
|
time.sleep(0.1)
|
2023-06-14 15:57:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
# TODO: Make api request to backend with resulting text in callback function.
|