test-voice-synthesis-mock.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env node
  2. /**
  3. * 语音合成端到端模拟测试
  4. * 测试流程:模拟配置 → 创建测试文本 → 验证调用链路
  5. */
  6. const path = require('path');
  7. const fs = require('fs');
  8. console.log('🧪 语音合成端到端模拟测试\n');
  9. // 测试 1: 验证配置
  10. console.log('【测试 1】验证环境配置...');
  11. const envPath = path.resolve('D:', 'qiwei-training', '.env.local');
  12. if (!fs.existsSync(envPath)) {
  13. console.error(' ❌ 配置文件不存在:', envPath);
  14. process.exit(1);
  15. }
  16. const envContent = fs.readFileSync(envPath, 'utf8');
  17. const tokenMatch = envContent.match(/^QIWEI_AUTH_TOKEN=(.+)$/m);
  18. if (!tokenMatch || !tokenMatch[1].trim()) {
  19. console.error(' ❌ 未配置 QIWEI_AUTH_TOKEN');
  20. process.exit(1);
  21. }
  22. const token = tokenMatch[1].trim();
  23. console.log(' ✅ Token 已配置(内容已隐藏)');
  24. // 测试 2: 加载语音服务模块
  25. console.log('\n【测试 2】加载语音服务模块...');
  26. try {
  27. const { VoiceCloneService } = require('../mcp/src/core/voice-clone-service.js');
  28. console.log(' ✅ VoiceCloneService 类加载成功');
  29. // 测试 3: 实例化服务
  30. console.log('\n【测试 3】实例化语音服务...');
  31. const service = new VoiceCloneService({
  32. config: {
  33. endpoint: 'https://server.fmode.cn/api/voice/indextts2',
  34. authToken: token
  35. },
  36. qiwei: { uid: 'test-uid', guid: 'test-guid' }
  37. });
  38. console.log(' ✅ 服务实例化成功');
  39. console.log(' 端点:', service.config.endpoint);
  40. console.log(' 超时:', service.config.requestTimeoutMs, 'ms');
  41. // 测试 4: 验证依赖
  42. console.log('\n【测试 4】验证音频处理依赖...');
  43. const ffmpeg = require('@ffmpeg-installer/ffmpeg');
  44. const ffprobe = require('@ffprobe-installer/ffprobe');
  45. const WxVoice = require('@binsee/wx-voice');
  46. console.log(' ✅ ffmpeg:', fs.existsSync(ffmpeg.path) ? '可用' : '不可用');
  47. console.log(' ✅ ffprobe:', fs.existsSync(ffprobe.path) ? '可用' : '不可用');
  48. console.log(' ✅ wx-voice:', typeof WxVoice.WxVoice === 'function' ? '可用' : '不可用');
  49. console.log('\n' + '='.repeat(60));
  50. console.log('✅ 所有模拟测试通过!');
  51. console.log('='.repeat(60));
  52. console.log('\n📝 下一步:真实语音测试需要:');
  53. console.log(' 1. 准备 5-30 秒参考音频(WAV/MP3)');
  54. console.log(' 2. 启动工作台: D:\\qiwei-training\\qiwei-workbench.exe');
  55. console.log(' 3. 在工作台上传参考音频初始化档案');
  56. console.log(' 4. 输入测试文本并发送到测试联系人');
  57. } catch (err) {
  58. console.error(' ❌ 测试失败:', err.message);
  59. process.exit(1);
  60. }