Speech Synthesis API离线语言

时间:2017-05-30 13:10:09

标签: text-to-speech offline speech-synthesis

是否可以离线使用语音合成API?如果是这样,我可以使用多种语言还是只使用默认语言? 我已经尝试过这个代码并且它可以在线工作,但它不能脱机工作。我怎样才能让它在线工作?

  <html>
    <head>
      <title>Index</title>
    </head>

<p id = "1"></p>


 <script src="../js/jquery-3.2.1.js"></script>         


<script type="text/javascript">

     $(document).ready(function() {
        document.addEventListener("keydown", function (e) {
          var audio = document.getElementById("myAudio");
            if (e.keyCode ===49 || e.keyCode ===97) {  //1 is pressed                
            mySpeech();
          }              
        });
      })
     function mySpeech(){
      var msg = new SpeechSynthesisUtterance();
      var voices = window.speechSynthesis.getVoices();
      msg.voiceURI = 'native';
      msg.lang = 'it-IT'
      //msg.voice = voices[$('#voices').val()];
      msg.rate = 1; // 0 to 1 
      msg.pitch = 1; // 0 to 2
      msg.text = "hello world";    
      speechSynthesis.speak(msg);
    }   

    </script>

 </body>

1 个答案:

答案 0 :(得分:1)

离线工作的唯一语言是浏览器的本地语音。