File size: 1,587 Bytes
673435a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

import requests
import time
import json

URL = "http://localhost:8000/api/v1/tts/stream"
PAYLOAD = {
    "text": "The quick brown fox jumps over the lazy dog.",
    "voice": "en-US-AriaNeural",
    "speaking_rate": 1.0,
    "pitch": 0.0
}

def test_api_stream():
    print(f"Connecting to {URL}...")
    start = time.time()
    try:
        with requests.post(URL, json=PAYLOAD, stream=True) as r:
            print(f"Status: {r.status_code}")
            if r.status_code != 200:
                print(r.text)
                return

            iterator = r.iter_content(chunk_size=None)
            print("Request sent. Waiting for first chunk...")
            
            try:
                first_chunk = next(iterator)
                ttfb = time.time() - start
                print(f"FIRST CHUNK received after: {ttfb:.4f}s")
                print(f"First chunk size: {len(first_chunk)} bytes")
            except StopIteration:
                print("No content received.")
                return

            print("Consuming rest of stream...")
            total_bytes = len(first_chunk)
            chunks = 1
            for chunk in iterator:
                total_bytes += len(chunk)
                chunks += 1
            
            total_time = time.time() - start
            print(f"Total time: {total_time:.4f}s")
            print(f"Total bytes: {total_bytes}")
            print(f"Chunks: {chunks}")

    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    # Wait for server to be ready
    time.sleep(2)
    test_api_stream()