test-tts.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const axios = require('axios');
  2. const BASE_URL = 'http://localhost:3000';
  3. async function testTTSGenerate() {
  4. console.log('=== 测试 TTS 音频生成 ===\n');
  5. try {
  6. // 1. 先登录获取 token
  7. console.log('1️⃣ 登录获取 Token...');
  8. const login = await axios.post(`${BASE_URL}/api/auth/login`, {
  9. phone: '13800138000',
  10. code: '123456'
  11. });
  12. const token = login.data.data.token;
  13. console.log('✅ 登录成功,用户ID:', login.data.data.user.id);
  14. // 2. 生成音频
  15. console.log('\n2️⃣ 生成音频...');
  16. const result = await axios.post(`${BASE_URL}/api/tts/generate`, {
  17. text: '你好',
  18. voiceId: 'cherry',
  19. voiceParams: {
  20. speed: 1,
  21. pitch: 0,
  22. volume: 50
  23. }
  24. }, {
  25. headers: {
  26. Authorization: `Bearer ${token}`
  27. },
  28. timeout: 60000 // 60秒超时
  29. });
  30. console.log('✅ 音频生成成功!');
  31. console.log('📊 返回数据:', JSON.stringify(result.data, null, 2));
  32. } catch (error) {
  33. console.error('❌ 测试失败:', error.message);
  34. if (error.response) {
  35. console.error('📋 错误响应:', JSON.stringify(error.response.data, null, 2));
  36. }
  37. }
  38. }
  39. testTTSGenerate();