Web Speech API - 语音文本转换的Web解决方案

3320阅读 0评论2014-02-18 2930031850
分类:Web开发

分类

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

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

基本说明

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

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

    该协议由Speech API Community Group维护;

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

要点说明

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

Speech Recognition

Demo可以参考:41ZONE测试代码


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    
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

注意:当前没有浏览器对此接口方案支持
1
2
3
4
5
6
7
    
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);
上一篇:Windows Server 2012 R2 Hyper-v 虚拟机连接增强会话模式(通过 VMBus 远程访问)
下一篇:javascript中live支持多次click事件