from TTS.api import TTS
import time

print("Loading XTTS model...")

# Load model once
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)

print("Model loaded successfully")

speaker_wav = "female.wav"

def generate_audio(text, output_file):
    start = time.time()

    tts.tts_to_file(
        text=text,
        speaker_wav=speaker_wav,
        language="en",
        file_path=output_file
    )

    end = time.time()
    print("Generated:", output_file, "Time:", round(end-start,2), "seconds")


# Example text
generate_audio(
    "The presentation outlines a global corrective action plan initiated by Sun Pharmaceutical in response to a USFDA observation at its Dadra site, where multiple unaddressed deviations related to missing GMP documents were found. The core issue was inadequate documentation practices and limited training, which prompted the development of a comprehensive training module on documentation control. This module will be extended to all departments across all US supply sites, covering topics like document handling, error correction, and logbook maintenance. The training will be delivered through instructor-led sessions and online modules, with a completion timeline of 240 days and oversight by Corporate Quality to ensure compliance and consistency.",
    "fast_output.wav"
)