test-minimax-tts.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * 快速测试 MiniMax TTS API 直接调用
  3. */
  4. import axios from 'axios';
  5. const API_KEY = 'sk-cp-BOVwOolqOEmHycg8MzDX_UgQ_bDEK3snjPUFuwolUCb_TxMxhhlAfYhTT0_tqRvEz5K56xpl-aOoJtj97MuAY4UIA-PCQLVetUCY56i8LFimNuQqrrq5xWA';
  6. const API_BASE = 'https://api.minimaxi.com';
  7. async function testMiniMaxTTS() {
  8. console.log('===== 测试 MiniMax TTS API =====');
  9. const body = {
  10. model: 'speech-2.8-hd',
  11. text: '你好,欢迎使用AI有声书',
  12. voice_setting: {
  13. voice_id: 'audiobook_female_1',
  14. speed: 1,
  15. vol: 1,
  16. pitch: 1,
  17. },
  18. audio_setting: {
  19. audio_sample_rate: 32000,
  20. bitrate: 128000,
  21. format: 'mp3',
  22. channel: 1,
  23. },
  24. };
  25. console.log('请求体:', JSON.stringify(body, null, 2));
  26. try {
  27. const response = await axios.post(`${API_BASE}/v1/t2a_async_v2`, body, {
  28. headers: {
  29. 'Authorization': `Bearer ${API_KEY}`,
  30. 'Content-Type': 'application/json',
  31. },
  32. timeout: 30000,
  33. });
  34. console.log('✅ 成功:', JSON.stringify(response.data, null, 2));
  35. } catch (error: any) {
  36. console.error('❌ 失败:', error.response?.data || error.message);
  37. }
  38. }
  39. testMiniMaxTTS().catch(console.error);