Update.
This commit is contained in:
parent
84c83cfd70
commit
a292f571cb
@ -122,4 +122,4 @@ async def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
24
play.py
24
play.py
@ -29,12 +29,21 @@ import functools
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@functools.cache
|
|
||||||
def get_py_audio():
|
|
||||||
return pyaudio.PyAudio()
|
|
||||||
|
|
||||||
def play_audio(filename):
|
def play_audio(filename):
|
||||||
|
pygame.mixer.init()
|
||||||
|
pygame.mixer.music.load(filename)
|
||||||
|
pygame.mixer.music.play()
|
||||||
|
while pygame.mixer.music.get_busy():
|
||||||
|
pygame.time.Clock().tick(10)
|
||||||
|
|
||||||
|
|
||||||
|
def play_audio2(filename):
|
||||||
ffmpeg_cmd = [
|
ffmpeg_cmd = [
|
||||||
"ffmpeg",
|
"ffmpeg",
|
||||||
"-i", filename,
|
"-i", filename,
|
||||||
@ -45,9 +54,9 @@ def play_audio(filename):
|
|||||||
]
|
]
|
||||||
process = subprocess.Popen(ffmpeg_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=10**6)
|
process = subprocess.Popen(ffmpeg_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=10**6)
|
||||||
|
|
||||||
py_audio = get_py_audio()
|
p = pyaudio.PyAudio()
|
||||||
stream = py_audio.open(
|
stream = p.open(
|
||||||
format=py_audio.get_format_from_width(2),
|
format=p.get_format_from_width(2),
|
||||||
channels=2,
|
channels=2,
|
||||||
rate=44100,
|
rate=44100,
|
||||||
output=True
|
output=True
|
||||||
@ -62,5 +71,6 @@ def play_audio(filename):
|
|||||||
finally:
|
finally:
|
||||||
stream.stop_stream()
|
stream.stop_stream()
|
||||||
stream.close()
|
stream.close()
|
||||||
|
p.terminate()
|
||||||
process.stdout.close()
|
process.stdout.close()
|
||||||
process.wait()
|
process.wait()
|
||||||
|
@ -3,3 +3,4 @@ SpeechRecognition
|
|||||||
google-cloud-speech
|
google-cloud-speech
|
||||||
google-cloud-texttospeech
|
google-cloud-texttospeech
|
||||||
google-auth
|
google-auth
|
||||||
|
pygame
|
||||||
|
27
tts.py
27
tts.py
@ -33,23 +33,22 @@ import gcloud
|
|||||||
|
|
||||||
molodetz = ServerProxy("https://api.molodetz.nl/rpc")
|
molodetz = ServerProxy("https://api.molodetz.nl/rpc")
|
||||||
|
|
||||||
async def main():
|
def listen():
|
||||||
recognizer = sr.Recognizer()
|
recognizer = sr.Recognizer()
|
||||||
|
|
||||||
with sr.Microphone() as source:
|
with sr.Microphone() as source:
|
||||||
print("Adjusting to surroundings for a five seconds.")
|
print("Adjusting to surroundings for a five seconds.")
|
||||||
recognizer.adjust_for_ambient_noise(source, duration=5)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#recognizer.non_speaking_duration = 60*60
|
||||||
while True:
|
while True:
|
||||||
print("Listening...")
|
print("Listening...")
|
||||||
try:
|
try:
|
||||||
audio_data = recognizer.listen(source, timeout=10)
|
audio_data = recognizer.listen(source, timeout=10)
|
||||||
text = recognizer.recognize_google(audio_data, language="nl-NL") #en-US
|
text = recognizer.recognize_google(audio_data, language="nl-NL") #en-US
|
||||||
print(f"You said:\n\t{text}")
|
source = None
|
||||||
response_llm = molodetz.gpt4o_mini(text)
|
recognizer = None
|
||||||
print(f"GPT4o mini said:\n\t{response_llm}")
|
return text
|
||||||
await gcloud.tts(response_llm)
|
|
||||||
except sr.WaitTimeoutError:
|
except sr.WaitTimeoutError:
|
||||||
continue
|
continue
|
||||||
except sr.UnknownValueError:
|
except sr.UnknownValueError:
|
||||||
@ -57,6 +56,20 @@ async def main():
|
|||||||
except sr.RequestError:
|
except sr.RequestError:
|
||||||
continue
|
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__":
|
if __name__ == "__main__":
|
||||||
import asyncio
|
import asyncio
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
Loading…
Reference in New Issue
Block a user