kokorotts-server/example_usage.py
2025-10-25 02:04:42 -05:00

53 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 realtime data feeds, OTT delivery, fan sentiment, and even some videogaming parallels.
Alex: First off, the article mentions Forbes' "RealTime" platform. That's basically a livesports aggregator, pulling in live scores, promos, and instant fan reactions via push notifications."""
# URL of your Flask server (adjust as needed)
url = "http://localhost:5010/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 5010")
except Exception as e:
print(f"✗ Unexpected error: {e}")
if __name__ == "__main__":
test_tts_endpoint()