#!/usr/bin/env python3 """ Example script demonstrating the kokoro TTS Flask server usage. """ import json import requests from pprint import pprint def test_tts_endpoint(): """Test the TTS endpoint with sample data.""" # Sample text with speakers sample_text = """Alex: Hey everyone, welcome back to Binge & Byte. I'm Alex. Jamie: And I'm Jamie. Today we're diving into the latest AEW Dynamite recap from October 22, 2025 – and trust me, it's not just a wrestling recap. We're talking real‑time data feeds, OTT delivery, fan sentiment, and even some video‑gaming parallels. Alex: First off, the article mentions Forbes' "Real‑Time" platform. That's basically a live‑sports aggregator, pulling in live scores, promos, and instant fan reactions via push notifications.""" # URL of your Flask server (adjust as needed) url = "http://localhost:5012/tts" # Prepare the request payload payload = {"text": sample_text, "title": "aeW_dynamite_recap"} print("Sending request to TTS endpoint...") print(f"Payload: {json.dumps(payload, indent=2)}") try: # Send POST request response = requests.post(url, json=payload) if response.status_code == 200: result = response.json() print("\n✓ Success!") print("Response:") pprint(result) # Show the file path where WAV was generated if "file_path" in result: print(f"\nAudio file generated at: {result['file_path']}") else: print(f"\n✗ Error: {response.status_code}") print(response.text) except requests.exceptions.ConnectionError: print("✗ Cannot connect to server. Make sure Flask app is running on port 5012") except Exception as e: print(f"✗ Unexpected error: {e}") if __name__ == "__main__": test_tts_endpoint()