import soundfile as sf
from voxcpm import VoxCPM

print("Loading VoxCPM1.5 model (will download on first run)...")
model = VoxCPM.from_pretrained("openbmb/VoxCPM1.5")
print("Model loaded successfully!")

print("\nGenerating speech...")
wav = model.generate(
    text="Hello! VoxCPM is an amazing text to speech model. Let me test how it sounds with this sentence.",
    prompt_wav_path=None,
    prompt_text=None,
    cfg_value=2.0,
    inference_timesteps=10,
    normalize=False,
    denoise=False,
    retry_badcase=True,
    retry_badcase_max_times=3,
    retry_badcase_ratio_threshold=6.0,
)

output_path = "/home/ubuntu/voxcpm_test_output.wav"
sf.write(output_path, wav, model.tts_model.sample_rate)
print(f"\nSaved output to: {output_path}")
print(f"Sample rate: {model.tts_model.sample_rate}")
print(f"Duration: {len(wav) / model.tts_model.sample_rate:.2f}s")
