// 测试音频生成(使用短文本) async function testAudioGeneration() { const bookId = 5; // 测试2个小节,每个用10字左右的文本 const testCases = [ { chapterId: 1214, title: '版本控制的概念与价值', text: '版本控制是软件开发中的重要工具。' }, { chapterId: 1215, title: '版本控制系统的演进历程', text: '版本控制系统从本地发展到分布式。' } ]; console.log('\n🎵 测试音频生成(短文本):\n'); for (let i = 0; i < testCases.length; i++) { const testCase = testCases[i]; console.log(`\n${i + 1}. ${testCase.title}`); console.log(` 文本: ${testCase.text} (${testCase.text.length}字)`); try { const response = await fetch('http://localhost:3000/api/tts/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ text: testCase.text, voiceId: 'cherry', bookId: bookId.toString(), chapterTitle: testCase.title, }), }); const data = await response.json(); if (data.code === 0) { console.log(` ✅ 任务已提交 (audioId: ${data.data.audioId})`); } else { console.log(` ❌ 失败: ${data.message}`); } } catch (error) { console.log(` ❌ 请求错误: ${error.message}`); } // 每个请求间隔2秒 if (i < testCases.length - 1) { await new Promise(resolve => setTimeout(resolve, 2000)); } } console.log('\n💡 等待30秒后检查生成结果...\n'); } testAudioGeneration();