science-storyteller / tests /test_kokoro.py
tuhulab's picture
chore: Organize repository structure - move docs to docs/ and tests to tests/
28b3cfa
"""
Quick test script for Kokoro-82M TTS integration via HF Inference API
"""
import asyncio
import logging
from agents.audio_agent import AudioAgent
logging.basicConfig(level=logging.INFO)
async def test_kokoro():
"""Test Kokoro-82M audio generation via HF API"""
print("🎀 Testing Kokoro-82M Integration (HF Inference API)...\n")
agent = AudioAgent()
test_text = """
Welcome to Science Storyteller! This is a test of our Kokoro-82M integration.
Kokoro is an open-source, Apache-licensed TTS model with 82 million parameters.
It delivers high-quality, natural-sounding speech that's perfect for podcasts.
Let's hear how it sounds!
"""
print(f"Model: hexgrad/Kokoro-82M")
print(f"Text length: {len(test_text)} characters\n")
print("Generating audio with Kokoro-82M via HF Inference API...")
audio_path = await agent.text_to_speech(test_text, "test_kokoro.wav")
if audio_path:
print(f"\nβœ… SUCCESS! Audio saved to: {audio_path}")
# Check file size
from pathlib import Path
file_size = Path(audio_path).stat().st_size / 1024 # KB
print(f"πŸ“¦ File size: {file_size:.2f} KB")
print("\n🎧 You can play the audio file to verify quality!")
return True
else:
print("\n❌ FAILED to generate audio")
return False
if __name__ == "__main__":
success = asyncio.run(test_kokoro())
exit(0 if success else 1)