UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

86 lines (85 loc) โ€ข 4.71 kB
/** * Test script for Echogarden TTS integration * This script tests the local TTS functionality using Echogarden */ import { AudioGenerator } from '../services/audioGenerator.js'; import path from 'path'; async function testEchogardenTTS() { console.log('๐Ÿงช Testing Echogarden TTS Integration'); console.log('='.repeat(50)); try { // Test 1: Basic Echogarden TTS with default settings console.log('\n๐Ÿ“ Test 1: Basic Echogarden TTS (Kokoro engine)'); const audioGenerator1 = new AudioGenerator({ provider: 'echogarden', voice: 'Bella', model: 'kokoro' }); const testText1 = "Hello! This is a test of the Echogarden text-to-speech integration. It runs completely offline without requiring any API keys."; console.log(`๐ŸŽ™๏ธ Generating audio for: "${testText1}"`); const audioBuffer1 = await audioGenerator1.generateAudio(testText1); const outputPath1 = path.join(process.cwd(), 'demo', 'echogarden_test_kokoro.wav'); await audioGenerator1.saveAudioToFile(outputPath1, audioBuffer1); console.log(`โœ… Test 1 passed! Audio saved to: ${outputPath1}`); console.log(`๐Ÿ“Š Audio size: ${audioBuffer1.length} bytes`); // Test 2: Different voice (Nicole) console.log('\n๐Ÿ“ Test 2: Different Voice (Nicole)'); const audioGenerator2 = new AudioGenerator({ provider: 'echogarden', voice: 'Nicole', model: 'kokoro' // Use kokoro for now since vits might not be available }); const testText2 = "This is a test using the Nicole voice, which provides high-quality neural text-to-speech synthesis."; console.log(`๐ŸŽ™๏ธ Generating audio for: "${testText2}"`); const audioBuffer2 = await audioGenerator2.generateAudio(testText2); const outputPath2 = path.join(process.cwd(), 'demo', 'echogarden_test_nicole.wav'); await audioGenerator2.saveAudioToFile(outputPath2, audioBuffer2); console.log(`โœ… Test 2 passed! Audio saved to: ${outputPath2}`); console.log(`๐Ÿ“Š Audio size: ${audioBuffer2.length} bytes`); // Test 3: Sarah voice console.log('\n๐Ÿ“ Test 3: Sarah Voice'); const audioGenerator3 = new AudioGenerator({ provider: 'echogarden', voice: 'Sarah', model: 'kokoro' // Use kokoro for consistency }); const testText3 = "This is a test using the Sarah voice, which provides another variation of high-quality speech synthesis."; console.log(`๐ŸŽ™๏ธ Generating audio for: "${testText3}"`); const audioBuffer3 = await audioGenerator3.generateAudio(testText3); const outputPath3 = path.join(process.cwd(), 'demo', 'echogarden_test_sarah.wav'); await audioGenerator3.saveAudioToFile(outputPath3, audioBuffer3); console.log(`โœ… Test 3 passed! Audio saved to: ${outputPath3}`); console.log(`๐Ÿ“Š Audio size: ${audioBuffer3.length} bytes`); // Test 4: Voice availability check console.log('\n๐Ÿ“ Test 4: Voice Availability Check'); const availableVoices = audioGenerator1.getAvailableVoices(); console.log(`๐ŸŽญ Available voices for Kokoro: ${availableVoices.join(', ')}`); const isVoiceAvailable = audioGenerator1.isVoiceAvailable('Bella'); console.log(`โœ… Voice 'Bella' available: ${isVoiceAvailable}`); console.log('\n๐ŸŽ‰ All Echogarden tests passed successfully!'); console.log('๐Ÿ”ง Echogarden TTS integration is working correctly.'); console.log('\n๐Ÿ’ก Benefits of Echogarden:'); console.log(' โ€ข Runs completely offline (no internet required)'); console.log(' โ€ข No API keys needed'); console.log(' โ€ข High-quality neural voices'); console.log(' โ€ข Multiple engines (Kokoro, VITS, eSpeak)'); console.log(' โ€ข Cross-platform support'); } catch (error) { console.error('โŒ Echogarden test failed:', error); if (error instanceof Error) { if (error.message.includes('echogarden')) { console.log('\n๐Ÿ’ก Troubleshooting tips:'); console.log(' โ€ข Make sure echogarden is installed: npm install echogarden'); console.log(' โ€ข Echogarden may need to download models on first use'); console.log(' โ€ข Check that you have sufficient disk space for models'); } } throw error; } } // Run the test if this file is executed directly if (import.meta.url === `file://${process.argv[1]}`) { testEchogardenTTS().catch(console.error); } export { testEchogardenTTS };