1

我只是想开发一个将文本转换为语音的功能。这里的问题是,转换总是发生在女声中,即使我已经指定了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"));
        }
    )
}
4

1 回答 1

1

根据你的描述,我检查了3.2.1 voice Element aboutgendername属性如下:

  • 性别:可选属性,指示说出包含文本的声音的首选性别。枚举值为:“male”、“female”、“neutral”或空字符串“”。

  • name:可选属性,指示特定于处理器的语音名称,用于说出包含的文本。该值可以是空格分隔的名称列表,从上至下排序或空字符串“”。因此,名称不得包含任何空格。

根据您的代码,我检查了支持的语言环境和语音字体

在此处输入图像描述

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

于 2018-05-21T05:52:28.460 回答