语音浏览器不适用于Chrome浏览器(版本83.0.4103.61)

时间:2020-05-31 20:26:20

标签: javascript

我一直在尝试许多脚本来使这些脚本可用于SpeechRecognition。我什至已经复制并粘贴了一些作者声称最终会使用的脚本。到目前为止没有运气。我很茫然。 我正在使用Live Server打开。当我在Wordpress中开发网站时,我也尝试了使用代码添加插件在wordpress中进行尝试。没有运气!请看一下我的代码摘录之一。 谢谢。

    <html>  
 <head>
 <title> Speech to TextEditor App </title>
 <style>

  body {
        font-family: verdata;
   }

   #result{

       height: 150px;
       border:1px solid #ccc;
       padding: 10px;
       box-shadow: 0 0 10px 0 #bbb;
       margin-bottom: 30px;
       font-size: 14px;
       line-height:25px;

     }

     button{

       font-size:40px;
       position: absolute;
       top: 240px;
       left: 50%;
     }
   </style>

  </head>

  <body>
  <h4> Speech to text converter in JS</h4>
  <div id ="result"></div>
 <button onclik = "startConverting();" ()><i class="fa fa-microphone"i></button>

<script type ="text/javascript">

 var r = document.getElementById('result');

function startConverting (){

  if('webkitSpeechRecognition' in window){

     var speechRecongnition = new webkitSpeechRecognition();
     speechRecongnition.continuous = true;
     speechRecongnition.interimresults = true;
      speechRecongnition.lang = 'en-IN';
     speechRecongnition.start();

      var finalTranscripts = '';

     speechrecognizer.onresult = function(event){

       var interimTranscripts = '';

         for (var i = event.resultIndex; i < event.results.lenght; i++){

       var transcript = event.result[i][0].transcript;

       transcript.replace("\n", "<br>");

       if(event.results[i].isFinal){

        finaltranscripts +=transcript;
       }else{
        interimTranscripts += transcript;
       }
       }
      r.innerHTML = finalTranscripts + '<span style="color:#999">' + interimTranscripts + 
      '</span>';

       };

       speechRecognizer.onerror = function(event){

        };
       }

        else{

         r.innerHTML = 'Your browser is not supported If google chrome, please upgrade';

            }



              }


               </script>

              </body>
          </html>

0 个答案:

没有答案