test-audio-gen.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // 测试音频生成
  2. async function testAudioGeneration() {
  3. const bookId = 5;
  4. const chapterId = 1214; // 版本控制的概念与价值
  5. const testText = "版本控制的概念与价值\n\n版本控制是软件开发中不可或缺的工具,它帮助我们追踪文件的变化历史,支持多人协作开发,并允许我们在出现问题时回退到之前的状态。";
  6. console.log('\n🎵 测试音频生成:\n');
  7. console.log(`书籍ID: ${bookId}`);
  8. console.log(`章节ID: ${chapterId}`);
  9. console.log(`测试文本: ${testText.substring(0, 50)}...\n`);
  10. try {
  11. // 调用音频生成API
  12. const response = await fetch('http://localhost:3000/api/tts/generate', {
  13. method: 'POST',
  14. headers: {
  15. 'Content-Type': 'application/json',
  16. },
  17. body: JSON.stringify({
  18. text: testText,
  19. voiceId: 'cherry',
  20. bookId: bookId.toString(),
  21. chapterTitle: '版本控制的概念与价值',
  22. }),
  23. });
  24. const data = await response.json();
  25. console.log('📤 API响应:');
  26. console.log(JSON.stringify(data, null, 2));
  27. if (data.code === 0) {
  28. console.log('\n✅ 音频生成任务已提交!');
  29. console.log(`\n💡 等待30-60秒后检查音频是否生成成功`);
  30. } else {
  31. console.log('\n❌ 音频生成失败:', data.message);
  32. }
  33. } catch (error) {
  34. console.error('\n❌ 请求失败:', error.message);
  35. }
  36. }
  37. testAudioGeneration();