Node.js 语音xml:lang=";“美国”;xml:gender=";男";名称=“名称”;Microsoft服务器语音文本始终为女性语音
我只是想开发一个将文本转换为语音的功能。这里的问题是,转换总是发生在女性声音中,尽管我已经将Node.js 语音xml:lang=";“美国”;xml:gender=";男";名称=“名称”;Microsoft服务器语音文本始终为女性语音,node.js,speech-recognition,text-to-speech,azure-cognitive-services,bing-speech,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 = {
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"));
}
)
}
textToSpeech(“这是检查文本到语音转换的测试”);
函数textToSpeech(文本:字符串){
const requestOptions:request.corepoptions={
标题:{
“Ocp Apim订阅密钥”:config.speech.bingSpeech.key1,
}
};
请寄(
`${config.speech.bingSpeech.authEndPoint}/issueToken`,
请求选项,
(错误、响应、正文)=>{
const accessToken=response.body;
常数有效载荷=`
${text}
`;
const requestOptions:request.corepoptions={
标题:{
“X-Microsoft-OutputFormat”:“audio-16khz-128kbitrate-mono-mp3”,
“内容类型”:“应用程序/ssml+xml”,
“主持人”:“speech.platform.bing.com”,
“内容长度”:payLoad.Length,
“授权”:“持票人”+accessToken,
“用户代理”:“NodeJS”
},
车身:有效载荷
};
请寄(
config.speech.bingSpeech.synthesizeUrl,
请求选项
).pipe(fs.createWriteStream(uu dirname+“/output.mp3”);
}
)
}
根据您的描述,我检查了aboutgender
和name
属性,如下所示:
- 性别:可选属性,指示要说出包含文本的语音的首选性别。枚举值为:“阳性”、“阴性”、“中性”或空字符串“”
- 名称:可选属性,指示处理器特定的语音名称,以说出包含的文本。该值可以是一个以空格分隔的名称列表,从上到下排列,也可以是空字符串“”。因此,名称不得包含任何空格
voice
元素的name
属性设置为Microsoft Server Speech Text-to-Speech voice(en-US,BenjaminRUS)