|
|
@@ -77,8 +77,7 @@ export class AliyunTtsProvider implements ITtsProvider {
|
|
|
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
|
try {
|
|
|
// 构建请求体(参考 tonggan/scripts/generate-tts.mjs 的成功调用格式)
|
|
|
- // ⚠️ 重要:cosyvoice 不传 format/sample_rate,否则返回 400 InvalidParameter
|
|
|
- // 阿里云百炼新版本会自动用 wav 格式(.wav 扩展名)作为默认
|
|
|
+ // cosyvoice 传 format='mp3' + sample_rate=48000(tonggan 验证可用的格式)
|
|
|
const requestBody: any = {
|
|
|
model: activeModel,
|
|
|
input: {
|
|
|
@@ -88,6 +87,8 @@ export class AliyunTtsProvider implements ITtsProvider {
|
|
|
},
|
|
|
};
|
|
|
if (isCosyVoice) {
|
|
|
+ requestBody.input.format = 'mp3';
|
|
|
+ requestBody.input.sample_rate = 48000;
|
|
|
// CosyVoice v3-flash 系统音色支持 instruction 情感控制(固定格式 设置情感:{emotion}。)
|
|
|
if ((params as any).instructText) {
|
|
|
requestBody.input.instruction = (params as any).instructText;
|
|
|
@@ -101,18 +102,10 @@ export class AliyunTtsProvider implements ITtsProvider {
|
|
|
if (instructions.length > 0) requestBody.input.instructions = instructions.join(',');
|
|
|
}
|
|
|
|
|
|
- console.log(`📤 [Aliyun TTS] ${isCosyVoice?'CosyVoice SSE':'Qwen'} ${attempt}/${retries}, model: ${activeModel}, voice: ${voiceId || this.voice}, text: ${text.length}字`);
|
|
|
+ console.log(`📤 [Aliyun TTS] ${isCosyVoice?'CosyVoice':'Qwen'} ${attempt}/${retries}, model: ${activeModel}, voice: ${voiceId || this.voice}, text: ${text.length}字`);
|
|
|
|
|
|
- // CosyVoice: SSE 流式,边收边存,无超时
|
|
|
- if (isCosyVoice) {
|
|
|
- const result = await withAiLog(
|
|
|
- () => this.synthesizeStream(requestBody, outputPath),
|
|
|
- { callType: 'tts_synthesize', provider: this.vendor, model: activeModel, textLen: text.length }
|
|
|
- );
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- // 千问: 同步非流式
|
|
|
+ // 统一走同步非流式(返回 audio.url,由 downloadAudio 下载到本地)
|
|
|
+ // CosyVoice v3-flash SSE 流式会返回空音频(audioEvents=0),必须用同步模式
|
|
|
// 根据模型动态选择 endpoint
|
|
|
const apiPath = activeModel.includes('cosyvoice')
|
|
|
? 'https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer'
|