• SST and TTS


    SST : speech to text;  TTS: text to speech;

    *SST:

          var u = new SpeechSynthesisUtterance();
          u.text = 'The quick brown chrome jumps over the lazy dog';
          u.lang = 'en-AU';
          u.rate = 0.75;
          u.pitch = 2.0;
          u.volume = 0.5;
          window.speechSynthesis.speak(u);     

    *TTS:

    <script>
    if (!('webkitSpeechRecognition' in window)) {
      upgrade();
    } else {
      start_button.style.display = 'inline-block';
      var recognition = new webkitSpeechRecognition();
      recognition.continuous = true;
      recognition.interimResults = true;
      recognition.onstart = function() {
        recognizing = true;
        showInfo('info_speak_now');
        start_img.src = 'mic-animate.gif';
      };
      recognition.onerror = function(event) {
        if (event.error == 'no-speech') {
          start_img.src = 'mic.gif';
          showInfo('info_no_speech');
          ignore_onend = true;
        }
        if (event.error == 'audio-capture') {
          start_img.src = 'mic.gif';
          showInfo('info_no_microphone');
          ignore_onend = true;
        }
        if (event.error == 'not-allowed') {
          if (event.timeStamp - start_timestamp < 100) {
            showInfo('info_blocked');
          } else {
            showInfo('info_denied');
          }
          ignore_onend = true;
        }
      };
      recognition.onend = function() {
        recognizing = false;
        if (ignore_onend) {
          return;
        }
        start_img.src = 'mic.gif';
        if (!final_transcript) {
          showInfo('info_start');
          return;
        }
        showInfo('');
        if (window.getSelection) {
          window.getSelection().removeAllRanges();
          var range = document.createRange();
          range.selectNode(document.getElementById('final_span'));
          window.getSelection().addRange(range);
        }
        if (create_email) {
          create_email = false;
          createEmail();
        }
      };
      recognition.onresult = function(event) {
        var interim_transcript = '';
        for (var i = event.resultIndex; i < event.results.length; ++i) {
          if (event.results[i].isFinal) {
            final_transcript += event.results[i][0].transcript;
          } else {
            interim_transcript += event.results[i][0].transcript;
          }
        }
        final_transcript = capitalize(final_transcript);
        final_span.innerHTML = linebreak(final_transcript);
        interim_span.innerHTML = linebreak(interim_transcript);
        if (final_transcript || interim_transcript) {
          showButtons('inline-block');
        }
      };
    }
    function upgrade() {
      start_button.style.visibility = 'hidden';
      showInfo('info_upgrade');
    }
    </script>
  • 相关阅读:
    为什么会需要消息队列(MQ)?
    RBAC用户角色权限设计方案
    转:jquery 父、子页面之间页面元素的获取,方法的调用
    LeetCode Wiggle Subsequence
    LeetCode Longest Arithmetic Sequence
    LeetCode Continuous Subarray Sum
    LeetCode Maximum Length of Repeated Subarray
    LeetCode Is Subsequence
    LeetCode Integer Break
    LeetCode Largest Sum of Averages
  • 原文地址:https://www.cnblogs.com/yeatschen/p/5421016.html
Copyright © 2020-2023  润新知