zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    android aar Could not find :ucrop-debug2.2.4:.
    OpenGL 实践之贝塞尔曲线绘制
    OpenGL 实现视频编辑中的转场效果
    简单易用的图像解码库介绍 —— stb_image
    博客图床迁移记
    Android 图片加载框架 Glide4.x
    Android 屏幕适配插件 ScreenMatch
    Android .9.png 的介绍
    Android 网络框架 Retrofit2
    Android 网络框架 OKHttp3
  • 原文地址:https://www.cnblogs.com/yeatschen/p/5421016.html
Copyright © 2011-2022 走看看