| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- const axios = require('axios');
- const BASE_URL = 'http://localhost:3000';
- async function testTTSGenerate() {
- console.log('=== 测试 TTS 音频生成 ===\n');
- try {
- // 1. 先登录获取 token
- console.log('1️⃣ 登录获取 Token...');
- const login = await axios.post(`${BASE_URL}/api/auth/login`, {
- phone: '13800138000',
- code: '123456'
- });
- const token = login.data.data.token;
- console.log('✅ 登录成功,用户ID:', login.data.data.user.id);
- // 2. 生成音频
- console.log('\n2️⃣ 生成音频...');
- const result = await axios.post(`${BASE_URL}/api/tts/generate`, {
- text: '你好',
- voiceId: 'cherry',
- voiceParams: {
- speed: 1,
- pitch: 0,
- volume: 50
- }
- }, {
- headers: {
- Authorization: `Bearer ${token}`
- },
- timeout: 60000 // 60秒超时
- });
- console.log('✅ 音频生成成功!');
- console.log('📊 返回数据:', JSON.stringify(result.data, null, 2));
- } catch (error) {
- console.error('❌ 测试失败:', error.message);
- if (error.response) {
- console.error('📋 错误响应:', JSON.stringify(error.response.data, null, 2));
- }
- }
- }
- testTTSGenerate();
|