jarvis/frontend/main.py

27 lines
698 B
Python

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)
# TODO: Make api request to backend with resulting text in callback function.