I am just trying to develop a function which converts text to speech. The issue here is, the conversion is always happening in the female voice, even though I had specified the xml:gender
to male. Here is my function, is there anyway I can transform my texts to audio in male voice?
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"));
}
)
}
According to your description, I checked the 3.2.1 voice Element about gender
and name
attributes as follows:
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.
Based on your code, I checked the Supported locales and voice fonts:
For male voice, you may also need to set the name
attribute of the voice
element to Microsoft Server Speech Text to Speech Voice (en-US, BenjaminRUS)
.