我只是想开发一个将文本转换为语音的功能。这里的问题是,转换总是以女性声音发生,即使我已将 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关于gender
和name
属性如下:
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 :
对于男声,您可能还需要将 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/