今天反过来,试试文字转换语音的范例
跟前天的语音服务-语音转换文字范例(from-file)一样
把index.html
跟token.php
部署到一个Azure Web App中
完成的页面如下,介面就类似前两天的范例
基本上就跟昨天的程序类似
只是要先在Input Text的文字框中输入文字
按下按钮让结果显示在Result的文字框中
程序码的部分
到speechConfig的建立为止就跟昨天一样
接着不需要指定辨识语言以及建立audioConfig
而是使用SDK的SpeechSynthesizer物件
synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig);
首先先new一个SpeechSDK.SpeechSynthesizer物件
并将上面建立的speechConfig作为参数传入
接着使用speakTextAsync以非同步的将语音转换为文字
并将文字框的内容(phraseDiv.value)传入
let inputText = phraseDiv.value;
synthesizer.speakTextAsync(
inputText,
function (result) {
startSpeakTextAsyncButton.disabled = false;
if (result.reason === SpeechSDK.ResultReason.SynthesizingAudioCompleted) {
resultDiv.innerHTML += "synthesis finished for [" + inputText + "].\n";
} else if (result.reason === SpeechSDK.ResultReason.Canceled) {
resultDiv.innerHTML += "synthesis failed. Error detail: " + result.errorDetails + "\n";
}
window.console.log(result);
synthesizer.close();
synthesizer = undefined;
},
function (err) {
startSpeakTextAsyncButton.disabled = false;
resultDiv.innerHTML += "Error: ";
resultDiv.innerHTML += err;
resultDiv.innerHTML += "\n";
window.console.log(err);
synthesizer.close();
synthesizer = undefined;
});
结果(result)便会显示在Result的文字框中
<<: Day 28 -- Rails 实作 Ransack 简易搜寻及排序功能
终於完赛了,很感谢iT邦帮忙铁人赛这个活动,让我在30天内因为要发文而不断的学习,原本是一个下了班...
不管是问卷分析还是在看用户的使用资料,都充斥着许多密密麻麻的资料,这些值化的资料最後都会转换成量化的...
在前一篇文章中,我们有提到如果要搜寻部分字元的话,可以使用 _ 以及 % 这两种 但是如果想要将 _...
11.3 一些 Leetcode 例题 再来看一些有趣的最短路径变化题吧! Leetcode 882...
在开发专案时你一定会使用到 Service 的技巧,Service 是一个广泛的类别,包括 app ...