TakwayBoard/tools/easy_client.py

31 lines
831 B
Python
Raw Permalink Normal View History

2024-05-23 20:00:40 +08:00
from takway.clients.client_utils import BaseWebSocketClient
from takway.audio_utils import AudioPlayer
if __name__ == '__main__':
server_url = 'ws://takway-ai.top:8001/chat/streaming/temporary'
session_id = '469f4a99-12a5-45a6-bc91-353df07423b6' # 新
client = BaseWebSocketClient(server_url, session_id)
client.wakeup_client()
wave_file = 'example_recording.wav'
player = AudioPlayer()
frames = player.load_audio_file(wave_file)
client.send_per_data(audio=frames, voice_synthesize=True, is_end=True, encoding='base64')
while True:
try:
response, data_type = client.receive_per_data()
print(response[0], len(response[1]))
2024-05-23 20:05:05 +08:00
pritn(type(response[0]), type(response[1]))
2024-05-23 20:00:40 +08:00
except:
pass