#!/usr/bin/env python3
"""
Test client for Soprano server
"""

import zmq
import json
import uuid
import numpy as np

# Connect to Soprano server
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5555")

print("Testing Soprano server...")

# Send request
job_id = str(uuid.uuid4())
request = {
    'job_id': job_id,
    'text': 'This is a test of the Soprano server running on the GTX 1660 GPU.'
}

print(f"Sending request: {request['text']}")
socket.send_json(request)

# Wait for response
print("Waiting for response...")
response = socket.recv_json()

if 'error' in response:
    print(f"Error: {response['error']}")
else:
    audio = np.array(response['audio'])
    print(f"✓ Received audio: {len(audio)} samples @ {response['sample_rate']}Hz")
    print(f"  Duration: {response['audio_duration']:.2f}s")
    print(f"  Generation time: {response['elapsed']:.2f}s")
    print(f"  Realtime factor: {response['audio_duration'] / response['elapsed']:.2f}x")

socket.close()
context.term()
