contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
86 lines (85 loc) โข 4.71 kB
JavaScript
/**
* 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 };