`bash OS/01/start.sh`
This commit is contained in:
parent
64fc5285fb
commit
61dd64f469
|
@ -1 +1 @@
|
||||||
[{"role": "user", "type": "message", "content": "Disgusting.\n"}]
|
[{"role": "user", "type": "message", "content": "And it works really well.\n"}]
|
|
@ -19,9 +19,9 @@ def tts(text):
|
||||||
with tempfile.NamedTemporaryFile() as temp_file:
|
with tempfile.NamedTemporaryFile() as temp_file:
|
||||||
response.stream_to_file(temp_file.name)
|
response.stream_to_file(temp_file.name)
|
||||||
|
|
||||||
# audio = AudioSegment.from_file(temp_file.name, format="mp3")
|
audio = AudioSegment.from_file(temp_file.name, format="mp3")
|
||||||
# # Gradual fade in and out over 0.2 seconds
|
# Gradual fade in and out over 0.2 seconds
|
||||||
# audio = audio.fade_in(200).fade_out(200)
|
audio = audio.fade_in(200).fade_out(200)
|
||||||
# play(audio)
|
play(audio)
|
||||||
|
|
||||||
return temp_file.read()
|
return temp_file.read()
|
||||||
|
|
|
@ -10,6 +10,9 @@ import websockets
|
||||||
import queue
|
import queue
|
||||||
import pydub
|
import pydub
|
||||||
import ast
|
import ast
|
||||||
|
from pydub import AudioSegment
|
||||||
|
from pydub.playback import play
|
||||||
|
import io
|
||||||
|
|
||||||
# Configuration for Audio Recording
|
# Configuration for Audio Recording
|
||||||
CHUNK = 1024 # Record in chunks of 1024 samples
|
CHUNK = 1024 # Record in chunks of 1024 samples
|
||||||
|
@ -109,7 +112,18 @@ async def websocket_communication(WS_URL):
|
||||||
|
|
||||||
async for message in websocket:
|
async for message in websocket:
|
||||||
print(message)
|
print(message)
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
if message["type"] == "audio" and "content" in message:
|
||||||
|
audio_bytes = bytes(ast.literal_eval(message["content"]))
|
||||||
|
|
||||||
|
# Convert bytes to audio file
|
||||||
|
audio_file = io.BytesIO(audio_bytes)
|
||||||
|
audio = AudioSegment.from_mp3(audio_file)
|
||||||
|
|
||||||
|
# Play the audio
|
||||||
|
play(audio)
|
||||||
|
|
||||||
|
await asyncio.sleep(1)
|
||||||
except:
|
except:
|
||||||
print("Connecting...")
|
print("Connecting...")
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
|
|
Loading…
Reference in New Issue