File size: 988 Bytes
a3419b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# src/pyttsx3_client.py
# TTS client for pyttsx3 (Windows SAPI5 backend).
# Baseline rule-based system — no neural net, no GPU.

import pyttsx3
import time


def synthesize(text: str, output_path: str, rate: int = 150, volume: float = 1.0) -> dict:
    """
    Synthesize text to a .wav file using pyttsx3.

    Args:
        text: the string to synthesize
        output_path: where to save the .wav file
        rate: speaking rate in words per minute (default 150)
        volume: volume level 0.0 to 1.0 (default 1.0)

    Returns:
        dict with keys: output_path, latency_seconds, engine
    """
    engine = pyttsx3.init()
    engine.setProperty("rate", rate)
    engine.setProperty("volume", volume)

    start = time.time()
    engine.save_to_file(text, output_path)
    engine.runAndWait()
    latency = time.time() - start

    engine.stop()

    return {
        "output_path": output_path,
        "latency_seconds": round(latency, 3),
        "engine": "pyttsx3",
    }