Using Google Text-To-Speech in Javascript

后端 未结 6 2056
一生所求
一生所求 2020-12-12 10:58

I need to play Google text-to-speech in JavaScript.
The idea is to use the web service:

http://translate.google.com/translate_t

6条回答
  •  渐次进展
    2020-12-12 11:17

    You can use the SpeechSynthesisUtterance with a function like say:

    function say(m) {
      var msg = new SpeechSynthesisUtterance();
      var voices = window.speechSynthesis.getVoices();
      msg.voice = voices[10];
      msg.voiceURI = "native";
      msg.volume = 1;
      msg.rate = 1;
      msg.pitch = 0.8;
      msg.text = m;
      msg.lang = 'en-US';
      speechSynthesis.speak(msg);
    }
    

    Then you only need to call say(msg) when using it.

    Update: Look at Google's Developer Blog that is about Voice Driven Web Apps Introduction to the Web Speech API.

提交回复
热议问题