"""Generate audio narration with Piper TTS - English voice with Indonesian text."""
import subprocess
import os

# Script for "Selamat Pagi Senin" - motivational upbeat
# We'll use Indonesian text but English-model phonemes won't work well for Indonesian.
# Alternative: Write English motivational script for Balimentari brand.

script_en = """
Monday morning. The holiday is over. But here is the truth. Today is not just another Monday. Today is your fresh start. Your first chance. Your new beginning. Take that first step. The world is waiting. Selamat pagi. Let's go. Balimentari.
"""

# Simplify and make it punchy
lines = [
    "The holiday is over.",
    "But today... today is your fresh start.",
    "Your first chance to be better.",
    "Take that step.",
    "The world is waiting for you.",
    "Selamat pagi, Senin.",
    "Balimentari.",
]

text = " ".join(lines)

model = os.path.expanduser("~/.piper/models/en_US-lessac-medium.onnx")
out = "/app/working/workspaces/default/OpenMontage/pipeline/balimentari-senin/narration.wav"

print(f"Model: {model}")
print(f"Exists: {os.path.exists(model)}")
print(f"Text: {text}")

cmd = [
    "piper",
    "-m", model,
    "-f", out,
    "--length-scale", "1.0",
]
proc = subprocess.run(cmd, input=text, capture_output=True, text=True, timeout=60)
print("STDOUT:", proc.stdout)
print("STDERR:", proc.stderr)
print("Return code:", proc.returncode)

if os.path.exists(out):
    print(f"Audio generated: {out} ({os.path.getsize(out)} bytes)")
else:
    print("Audio file not created!")
