| |
| |
| |
| |
| |
| |
| |
|
|
| import { |
| initVoiceClient, |
| VoiceRecordingTool, |
| VoiceSynthesisTool, |
| VoiceCloneTool, |
| VoiceStatusTool, |
| } from '../voice/index.js' |
| import { log } from '../utils/logger.js' |
|
|
| |
| |
| |
| async function checkVoiceStatus() { |
| log('Checking voice service status...') |
|
|
| |
| const client = initVoiceClient({ |
| apiUrl: process.env.VOICE_API_URL ?? 'http://localhost:8000', |
| }) |
|
|
| const statusTool = new VoiceStatusTool() |
| const result = await statusTool.execute() |
|
|
| log('Voice status:', result) |
| return result |
| } |
|
|
| |
| |
| |
| async function cloneVoiceExample() { |
| log('Cloning voice from sample...') |
|
|
| const client = initVoiceClient({ |
| apiUrl: process.env.VOICE_API_URL ?? 'http://localhost:8000', |
| }) |
|
|
| const cloneTool = new VoiceCloneTool() |
| const result = await cloneTool.execute({ |
| voiceName: 'my_voice', |
| audioPath: './audio_samples/my_voice.wav', |
| }) |
|
|
| log('Clone result:', result) |
| return result |
| } |
|
|
| |
| |
| |
| async function recordVoiceCommand() { |
| log('Starting voice recording...') |
|
|
| const recordingTool = new VoiceRecordingTool() |
|
|
| |
| const result = await recordingTool.execute({ maxDuration: 30000 }) |
|
|
| if (result.success) { |
| const data = result.data as { duration?: number; sampleRate?: number } | undefined |
| log('Recording captured:', { |
| duration: data?.duration, |
| sampleRate: data?.sampleRate, |
| }) |
| } else { |
| log('Recording failed:', result.error) |
| } |
|
|
| return result |
| } |
|
|
| |
| |
| |
| async function synthesizeResponse(text: string) { |
| log(`Synthesizing: "${text}"`) |
|
|
| const client = initVoiceClient({ |
| apiUrl: process.env.VOICE_API_URL ?? 'http://localhost:8000', |
| }) |
|
|
| const synthTool = new VoiceSynthesisTool() |
| const result = await synthTool.execute({ |
| text, |
| voiceName: 'my_voice', |
| }) |
|
|
| if (result.success) { |
| log('Audio generated successfully') |
| } else { |
| log('Synthesis failed:', result.error) |
| } |
|
|
| return result |
| } |
|
|
| |
| |
| |
| async function voiceConversation() { |
| |
| await checkVoiceStatus() |
|
|
| |
| const recording = await recordVoiceCommand() |
| if (!recording.success) { |
| log('Cannot proceed without voice input') |
| return |
| } |
|
|
| |
| |
|
|
| |
| const responseText = 'I have analyzed your code and found 3 potential improvements.' |
|
|
| |
| await synthesizeResponse(responseText) |
| } |
|
|
| |
| if (import.meta.url === `file://${process.argv[1]}`) { |
| log('Running voice integration examples...') |
|
|
| |
| await checkVoiceStatus() |
|
|
| |
| |
| |
| |
| |
| } |
|
|
| export default { |
| checkVoiceStatus, |
| cloneVoiceExample, |
| recordVoiceCommand, |
| synthesizeResponse, |
| voiceConversation, |
| } |