390ea5d0fca0907f19dd638ad91969a4.png

参考

分类

为语音转换为文本提供可能,Speech Recognition;

将文本输出为语音提供可能,Speech Synthesis;

基本说明

目前Chrome新版本浏览器支持该方案;

经过测试FF、Opera、IE、Safari没有对此进行支持;

该协议由Speech API Community Group维护;

当前规范不属于正式规范,但是以后以此作为参考方案;

要点说明

对于将语音与文本相互转换的技术是需要通过网络数据来实现的,也就是说,该API必须在网络条件下才能运行

Speech Recognition

var SpeechRecognition = window.SpeechRecognition ||

window.mozSpeechRecognition ||

window.webkitSpeechRecognition ||

window.msSpeechRecognition ||

window.oSpeechRecognition;

if(!SpeechRecognition) return ;

var speechRecognition = new SpeechRecognition();

speechRecognition.addEventListener("result",function(event) {

var results = event.results;

if(results.length > 0) {

for(var i = 0;i<results.length;i++) {

console.log(results[i][0].transcript);

}

}

},false);

speechRecognition.continuous = true; speechRecognition.start();

Speech Synthesis

注意:当前没有浏览器对此接口方案支持

var ssu = new SpeechSynthesisUtterance();

ssu.text = 'Hello World';

ssu.lang = 'en-US';

ssu.rate = 1.2;

ssu.addEventListener("end",function(event) { console.log("finished"); },false);

var su = new SpeechSynthesis();

su.speak(ssu);

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐