can Bing Text-to-Speech take a javascript variable value and convert it to speech?

时间:2018-03-09 19:16:24

标签: javascript azure text-to-speech microsoft-cognitive bing-speech

I am using Bing text to speech api in javascript and generating random numbers for addition. Just for support I wanted to integrate bing text-to-speech to my code but I am not able to find a documentation on microsoft page which says that you can pass dynamic parameter to api. By far it is able to to this:

var bingClientTTS = newBingSpeech.TTSClient("API KEY");
document.getElementById("speakBtn").addEventListener("click", function () {
bingClientTTS.synthesize("5 + 7");
});

But when I do this it gives Type error:

var randomNum1 = getRandom(),
var randomNum2 = getRandom();
total =randomNum1 + randomNum2;
$( "#question" ).text( randomNum1 + " + " + randomNum2 + "=" );  
document.getElementById("speakBtn").addEventListener("click", function () {
bingClientTTS.synthesize(randomNum1.value);
});

TypeError: Cannot read property 'encodeHTML' of undefined

Is there any way to pass variable to bing tts api or should I use google tts.

To avoid api calls I have used a javascript client librarygithub link

1 个答案:

答案 0 :(得分:0)

If it works with a string, it does not matter how you obtain that string.

Try randomNum1 instead of randomNum1.value.