node.js - 语音 XML :lang ="en-US" xml:gender ="Male" name="Microsoft Server Speech Text is always in Female voice

标签 node.js speech-recognition text-to-speech azure-cognitive-services bing-speech

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

最佳答案

根据你的描述,我查了3.2.1 voice Element关于gendername属性如下:

  • gender: optional attribute indicating the preferred gender of the voice to speak the contained text. Enumerated values are: "male", "female", "neutral", or the empty string "".

  • name: optional attribute indicating a processor-specific voice name to speak the contained text. The value may be a space-separated list of names ordered from top preference down or the empty string "". As a result a name must not contain any white space.

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

enter image description here

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

关于node.js - 语音 XML :lang ="en-US" xml:gender ="Male" name="Microsoft Server Speech Text is always in Female voice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50334632/

相关文章:

workflow - 有人成功使用CMU Sphinx进行语音识别编程吗

android - 为什么不可用语音列表总是空的?

audio - 直接从python程序播放音频(文本到语音)

javascript - Node.js/ express : respond immediately to client request and continue tasks in nextTick

node.js - Node.js 的自然模板 .html(如 Thymeleaf)

node.js - 如何使用 Mongoose 删除子文档?

android - TextToSpeech.isSpeaking() 在什么情况下返回 true?

node.js - 释放 Node.js 中 Buffer 实例的内存

macos - 是否有 API(或任何 hack)可以访问 Mac OS X Mavericks 中的增强听写功能?

java - Google识别器和pocketsphinx在两个不同的类中,如何循环它们?