参考
W3C , https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html
41ZONE , http://blog.41zone.cc/20140215/168/
分类
为语音转换为文本提供可能,Speech Recognition;
将文本输出为语音提供可能,Speech Synthesis;
基本说明
目前Chrome新版本浏览器支持该方案;
经过测试FF、Opera、IE、Safari没有对此进行支持;
该协议由Speech API Community Group维护;
当前规范不属于正式规范,但是以后以此作为参考方案;
要点说明
对于将语音与文本相互转换的技术是需要通过网络数据来实现的,也就是说,该API必须在网络条件下才能运行
Speech Recognition
Demo可以参考:41ZONE测试代码
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);