test-short-audio.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // 测试音频生成(使用短文本)
  2. async function testAudioGeneration() {
  3. const bookId = 5;
  4. // 测试2个小节,每个用10字左右的文本
  5. const testCases = [
  6. {
  7. chapterId: 1214,
  8. title: '版本控制的概念与价值',
  9. text: '版本控制是软件开发中的重要工具。'
  10. },
  11. {
  12. chapterId: 1215,
  13. title: '版本控制系统的演进历程',
  14. text: '版本控制系统从本地发展到分布式。'
  15. }
  16. ];
  17. console.log('\n🎵 测试音频生成(短文本):\n');
  18. for (let i = 0; i < testCases.length; i++) {
  19. const testCase = testCases[i];
  20. console.log(`\n${i + 1}. ${testCase.title}`);
  21. console.log(` 文本: ${testCase.text} (${testCase.text.length}字)`);
  22. try {
  23. const response = await fetch('http://localhost:3000/api/tts/generate', {
  24. method: 'POST',
  25. headers: { 'Content-Type': 'application/json' },
  26. body: JSON.stringify({
  27. text: testCase.text,
  28. voiceId: 'cherry',
  29. bookId: bookId.toString(),
  30. chapterTitle: testCase.title,
  31. }),
  32. });
  33. const data = await response.json();
  34. if (data.code === 0) {
  35. console.log(` ✅ 任务已提交 (audioId: ${data.data.audioId})`);
  36. } else {
  37. console.log(` ❌ 失败: ${data.message}`);
  38. }
  39. } catch (error) {
  40. console.log(` ❌ 请求错误: ${error.message}`);
  41. }
  42. // 每个请求间隔2秒
  43. if (i < testCases.length - 1) {
  44. await new Promise(resolve => setTimeout(resolve, 2000));
  45. }
  46. }
  47. console.log('\n💡 等待30秒后检查生成结果...\n');
  48. }
  49. testAudioGeneration();