change edge tts _SSMLTemplate

This commit is contained in:
afred 2025-01-04 15:20:36 +08:00
parent 641078744d
commit 4e6800b8f4

View File

@ -233,15 +233,23 @@ export class MsEdgeTTS {
} }
private _SSMLTemplate(input: string, options: ProsodyOptions = {}): string { private _SSMLTemplate(input: string, options: ProsodyOptions = {}): string {
// in case future updates to the edge API block these elements, we'll be concatenating strings. // 对 input 进行特殊字符替换
input = input
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
// 合并默认选项与传入选项
options = { ...new ProsodyOptions(), ...options }; options = { ...new ProsodyOptions(), ...options };
return `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="${this._voiceLocale}">
<voice name="${this._voice}"> return `
<prosody pitch="${options.pitch}" rate="${options.rate}" volume="${options.volume}"> <speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="${this._voiceLocale}">
${input} <voice name="${this._voice}">
</prosody> <prosody pitch="${options.pitch}" rate="${options.rate}" volume="${options.volume}">
</voice> ${input}
</speak>`; </prosody>
</voice>
</speak>`;
} }
/** /**