我只是想开发一个将文本转换为语音的功能。这里的问题是,即使我已将xml:gender指定为男性,转换总是以女性的声音进行。这是我的功能,是否可以将文本转换为男声音频?

textToSpeech("This is a test to check the conversion of text to speech");
function textToSpeech(text: string) {
    const requestOptions: request.CoreOptions = {
        headers: {
            "Ocp-Apim-Subscription-Key": config.speech.bingSpeech.key1,
        }
    };
    request.post(
        `${config.speech.bingSpeech.authEndPoint}/issueToken`,
        requestOptions,
        (err, response, body) => {
            const accessToken = response.body;
            const payLoad = `
            <speak version="1.0" xml:lang="en-US">
            <voice xml:lang="en-US" xml:gender="Male" name="Microsoft Server Speech Text to Speech Voice (en-US, ZiraRus)">
            ${text}
            </voice>
            </speak>
            `;
            const requestOptions: request.CoreOptions = {
                headers: {
                    "X-Microsoft-OutputFormat": "audio-16khz-128kbitrate-mono-mp3",
                    "Content-Type": "application/ssml+xml",
                    "Host": "speech.platform.bing.com",
                    "Content-Length": payLoad.length,
                    "Authorization": "Bearer " + accessToken,
                    "User-Agent": "NodeJS"
                },
                body: payLoad
            };

            request.post(
                config.speech.bingSpeech.synthesizeUrl,
                requestOptions
            ).pipe(fs.createWriteStream(__dirname + "/output.mp3"));
        }
    )
}

最佳答案

根据您的描述,我检查了有关gendername属性的3.2.1 voice Element,如下所示:


  
  性别:可选属性,指示说出所包含文本的首选语音性别。枚举值是:“男性”,“女性”,“中性”或空字符串“”。
  名称:可选属性,指示用于说出所包含文本的特定于处理器的语音名称。该值可以是用空格分隔的名称列表,这些名称从最高优先级降序排列,也可以为空字符串“”。因此,名称不得包含任何空格。
  


根据您的代码,我检查了Supported locales and voice fonts

node.js - 语音xml:lang =“en-US” xml:gender =“Male” name =“Microsoft服务器语音文本始终为女性语音-LMLPHP

对于男性声音,您可能还需要将name元素的voice属性设置为Microsoft Server Speech Text to Speech Voice (en-US, BenjaminRUS)

关于node.js - 语音xml:lang =“en-US” xml:gender =“Male” name =“Microsoft服务器语音文本始终为女性语音,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50334632/

10-13 21:38