参考代码
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | const fs = require('fs'); const axios = require('axios'); const path = require('path') async function sendRequest() {   const url = `http://127.0.0.1:9880/tts`   const data = {     "text": "先帝创业未半而中道蹦迪", // str.(必需) 要合成的文本     "text_lang": "zh", // str.(必需) 要合成的文本的语言     "ref_audio_path": "2.mp3", // str.(必需) 参考音频的路径     "prompt_lang": "zh",  // str.(必需) 参考音频的提示文本的语言     "top_k": 5, // int.(可选) 前 k 采样     "top_p": 1, // float.(可选) 前 p 采样     "temperature": 1, // float.(可选) 采样的温度     "text_split_method": "cut5", // str.(可选) 文本分割方法,详见 text_segmentation_method.py     "batch_size": 1, // int.(可选) 推理的批量大小     "batch_threshold": 0.75, // float.(可选) 批量拆分的阈值     "split_bucket": true, // bool.(可选) 是否将批量拆分为多个桶     "speed_factor": 1.0, // float.(可选) 控制合成音频的速度     "fragment_interval": 0.3, // float.(可选) 控制音频片段的间隔     "seed": -1, // int.(可选) 用于可重复性的随机种子     "media_type": "wav", // str.(可选) 输出音频的媒体类型,支持 "wav", "raw", "ogg", "aac"     "streaming_mode": false, // bool.(可选) 是否返回一个流式响应     "parallel_infer": true, // bool.(可选) 是否使用并行推理     "repetition_penalty": 1.35, // float.(可选) T2S 模型的重复罚项     "tts_infer_yaml_path": "GPT_SoVITS/configs/tts_infer.yaml" // str.(可选) TTS 推理的 YAML 配置文件路径   };   const options = {     method: 'POST',     url,     data,     headers: {       'Content-Type': 'application/json'     },     responseType: 'stream'   };   axios(options)     .then(async (response) => {       const filePath = 'out.wav';       const writer = fs.createWriteStream(filePath);       response.data.pipe(writer);       writer.on('finish', () => console.log('File saved successfully!'));       writer.on('error', error => console.error('Error writing file:', error));     })     .catch(error => console.error('Error:', error)); } sendRequest(); | 
 雅荷心语博客
雅荷心语博客 
		        
		    