feat: replace pyaudio playback with pygame mixer and refactor listen loop into separate function

This commit is contained in:
2025-01-18 09:02:13 +00:00
parent 5c64bb8414
commit 7cd4fdb155
4 changed files with 39 additions and 15 deletions
+20 -7
View File
@@ -33,23 +33,22 @@ import gcloud
molodetz = ServerProxy("https://api.molodetz.nl/rpc")
async def main():
def listen():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Adjusting to surroundings for a five seconds.")
recognizer.adjust_for_ambient_noise(source, duration=5)
#recognizer.non_speaking_duration = 60*60
while True:
print("Listening...")
try:
audio_data = recognizer.listen(source, timeout=10)
text = recognizer.recognize_google(audio_data, language="nl-NL") #en-US
print(f"You said:\n\t{text}")
response_llm = molodetz.gpt4o_mini(text)
print(f"GPT4o mini said:\n\t{response_llm}")
await gcloud.tts(response_llm)
source = None
recognizer = None
return text
except sr.WaitTimeoutError:
continue
except sr.UnknownValueError:
@@ -57,6 +56,20 @@ async def main():
except sr.RequestError:
continue
async def main():
#recognizer.adjust_for_ambient_noise(source, duration=5)
while True:
text = listen()
print(f"You said:\n\t{text}")
response_llm = molodetz.gpt4o_mini(text)
print(f"GPT4o mini said:\n\t{response_llm}")
await gcloud.tts(response_llm)
if __name__ == "__main__":
import asyncio
asyncio.run(main())