contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
209 lines (208 loc) โข 9.28 kB
JavaScript
#!/usr/bin/env node
/**
* Test script for Music Generation Features
* Tests the music generation capabilities of AudioGenerationTool
*/
import { AudioGenerationTool } from '../services/tools/AudioGenerationTool.js';
import fs from 'fs/promises';
async function testMusicGeneration() {
console.log('๐ต Testing Music Generation Features...\n');
try {
// Initialize tool
const tool = new AudioGenerationTool(process.cwd());
console.log('๐ Tool Information:');
console.log(`Name: ${tool.getName()}`);
console.log(`Description: ${tool.getDescription()}`);
console.log('\n๐ Parameters:');
tool.getParameters().forEach(param => {
console.log(` - ${param.name} (${param.type}): ${param.description}`);
});
// Test 1: Basic music generation with cloud-first fallback
console.log('\n๐ผ Test 1: Basic Music Generation (Cloud-First Fallback)');
const result1 = await tool.execute({
text: 'A cheerful upbeat acoustic guitar melody with light percussion, perfect for a sunny day',
output_path: 'test-music-basic.wav',
content_type: 'music',
style: 'acoustic',
duration: 30
});
if (result1.success) {
console.log('โ
Basic music generation successful!');
console.log('๐ Result data:', JSON.stringify(result1.data, null, 2));
console.log('๐ฌ Message:', result1.message);
}
else {
console.log('โ Basic music generation failed:', result1.error);
}
// Test 2: Music generation with specific style
console.log('\n๐ผ Test 2: Music Generation with Specific Style');
const result2 = await tool.execute({
text: 'Relaxing ambient soundscape with soft synthesizers and gentle rain sounds',
output_path: 'test-music-ambient.wav',
content_type: 'music',
style: 'ambient',
duration: 30
});
if (result2.success) {
console.log('โ
Styled music generation successful!');
console.log('๐ Provider used:', result2.data.provider);
console.log('๐ฐ Cost estimate:', result2.data.cost_estimate || 'N/A');
}
else {
console.log('โ Styled music generation failed:', result2.error);
}
// Test 3: Music generation with negative prompt (if Lyria 2 is available)
console.log('\n๐ผ Test 3: Music Generation with Negative Prompt');
const result3 = await tool.execute({
text: 'Energetic electronic dance music with strong bass and synthesizers',
output_path: 'test-music-edm.wav',
content_type: 'music',
style: 'electronic',
negative_prompt: 'no vocals, no drums',
seed: 42,
duration: 30
});
if (result3.success) {
console.log('โ
Music generation with negative prompt successful!');
console.log('๐ Provider used:', result3.data.provider);
console.log('๐ฏ Seed used:', result3.data.seed);
}
else {
console.log('โ Music generation with negative prompt failed:', result3.error);
}
// Test 4: Test provider fallback chain
console.log('\n๐ Test 4: Provider Fallback Chain');
console.log('This test demonstrates the cloud-first architecture with automatic fallbacks:');
console.log('1. Lyria 2 (Google Vertex AI) - Premium quality, $0.06/30sec');
console.log('2. Replicate MusicGen - Reliable cloud, ~$0.084/30sec');
console.log('3. HuggingFace MusicGen - Free fallback');
const result4 = await tool.execute({
text: 'Classical piano piece in the style of Chopin, melancholic and expressive',
output_path: 'test-music-classical.wav',
content_type: 'music',
style: 'classical',
duration: 30
});
if (result4.success) {
console.log('โ
Fallback chain test successful!');
console.log('๐ Final provider used:', result4.data.provider);
console.log('๐ฐ Cost:', result4.data.cost_estimate || 'N/A');
console.log('โฑ๏ธ Duration:', result4.data.duration_estimate);
}
else {
console.log('โ Fallback chain test failed:', result4.error);
}
// Test 5: Different music styles
console.log('\n๐จ Test 5: Different Music Styles');
const styles = [
{ style: 'jazz', text: 'Smooth jazz with saxophone and piano' },
{ style: 'rock', text: 'Energetic rock guitar riff with driving rhythm' },
{ style: 'orchestral', text: 'Epic orchestral theme with strings and brass' },
{ style: 'folk', text: 'Traditional folk melody with acoustic instruments' }
];
for (const { style, text } of styles) {
console.log(`\n Testing ${style} style...`);
const result = await tool.execute({
text,
output_path: `test-music-${style}.wav`,
content_type: 'music',
style,
duration: 30
});
if (result.success) {
console.log(` โ
${style} generation successful (${result.data.provider})`);
}
else {
console.log(` โ ${style} generation failed: ${result.error}`);
}
}
// Test 6: Parameter validation
console.log('\n๐ Test 6: Parameter Validation');
// Test missing content_type for music
const invalidResult1 = await tool.execute({
text: 'Test music',
output_path: 'test-invalid.wav',
style: 'jazz'
// Missing content_type
});
if (!invalidResult1.success) {
console.log('โ
Missing content_type correctly handled:', invalidResult1.error);
}
else {
console.log('โ Missing content_type should have been caught');
}
// Test invalid duration
const invalidResult2 = await tool.execute({
text: 'Test music',
output_path: 'test-invalid.wav',
content_type: 'music',
duration: 0 // Invalid duration
});
if (!invalidResult2.success) {
console.log('โ
Invalid duration correctly rejected:', invalidResult2.error);
}
else {
console.log('โ Invalid duration should have been rejected');
}
// Test 7: Provider-specific features
console.log('\n๐ง Test 7: Provider-Specific Features');
console.log('Testing advanced features available with different providers:');
// Test with all advanced parameters
const advancedResult = await tool.execute({
text: 'Cinematic orchestral score with dramatic crescendo and emotional depth',
output_path: 'test-music-advanced.wav',
content_type: 'music',
style: 'cinematic',
negative_prompt: 'no electronic instruments, no modern sounds',
seed: 123,
duration: 30
});
if (advancedResult.success) {
console.log('โ
Advanced features test successful!');
console.log('๐ Advanced result:', {
provider: advancedResult.data.provider,
style: advancedResult.data.style,
seed: advancedResult.data.seed,
negative_prompt: advancedResult.data.negative_prompt
});
}
else {
console.log('โ Advanced features test failed:', advancedResult.error);
}
// Cleanup
console.log('\n๐งน Cleaning up test files...');
const testFiles = [
'test-music-basic.wav',
'test-music-ambient.wav',
'test-music-edm.wav',
'test-music-classical.wav',
'test-music-jazz.wav',
'test-music-rock.wav',
'test-music-orchestral.wav',
'test-music-folk.wav',
'test-music-advanced.wav'
];
for (const file of testFiles) {
try {
await fs.unlink(file);
console.log(`โ
Cleaned up ${file}`);
}
catch (error) {
console.log(`โ ๏ธ Could not clean up ${file}: ${error}`);
}
}
console.log('\n๐ Music Generation tests completed!');
console.log('\n๐ Summary:');
console.log('- โ
Cloud-first architecture with automatic fallbacks');
console.log('- โ
Multiple provider support (Lyria 2, Replicate, HuggingFace)');
console.log('- โ
Style-based music generation');
console.log('- โ
Advanced parameters (negative prompts, seeds)');
console.log('- โ
Comprehensive error handling and validation');
console.log('- โ
Cost-effective fallback chain (premium โ reliable โ free)');
}
catch (error) {
console.error('โ Test failed with error:', error);
}
}
// Run the test
testMusicGeneration().catch(console.error);