Itration 0 from deepseek
This commit is contained in:
54
client/client.py
Normal file
54
client/client.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import asyncio
|
||||
import sounddevice as sd
|
||||
import numpy as np
|
||||
import websockets
|
||||
import json
|
||||
import requests
|
||||
|
||||
# Настройки
|
||||
VAD_URL = "ws://localhost:8001/audio-stream"
|
||||
TTS_URL = "http://localhost:8005/synthesize"
|
||||
SAMPLE_RATE = 16000
|
||||
BLOCK_SIZE = 1600 # 100 мс при 16 кГц
|
||||
|
||||
async def audio_stream():
|
||||
"""Захватывает аудио с микрофона и отправляет в VAD сервис."""
|
||||
async with websockets.connect(VAD_URL) as websocket:
|
||||
print("Подключен к VAD сервису. Говорите...")
|
||||
|
||||
def callback(indata, frames, time, status):
|
||||
"""Отправляет аудио-блок в WebSocket."""
|
||||
audio_bytes = indata.tobytes()
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
websocket.send(audio_bytes), loop
|
||||
)
|
||||
|
||||
stream = sd.InputStream(
|
||||
samplerate=SAMPLE_RATE,
|
||||
channels=1,
|
||||
dtype='int16',
|
||||
blocksize=BLOCK_SIZE,
|
||||
callback=callback
|
||||
)
|
||||
|
||||
with stream:
|
||||
while True:
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
def play_audio(audio_data):
|
||||
"""Воспроизводит аудио (полученное от TTS)."""
|
||||
audio_array = np.frombuffer(audio_data, dtype=np.int16)
|
||||
sd.play(audio_array, samplerate=SAMPLE_RATE)
|
||||
sd.wait()
|
||||
|
||||
async def main():
|
||||
# Запускаем поток аудио в фоне
|
||||
asyncio.create_task(audio_stream())
|
||||
|
||||
# Основной цикл не нужен, так как всё работает через WebSocket
|
||||
await asyncio.Future() # бесконечное ожидание
|
||||
|
||||
if __name__ == "__main__":
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
loop.run_until_complete(main())
|
||||
Reference in New Issue
Block a user