如何在输入字段中获取结果文本?我需要在输入字段中获取文本,因为我在我的python代码中使用form.getvalue

时间:2018-03-29 13:37:27

标签: javascript

这是我在javascript中进行语音识别的代码吗?我想在表格的输入字段中获得结果的值。结果将在r.innerhtml中出现。 我怎么能这样做?

我在下面分享代码。

    <form>
    <input style="font-size: 14px;" id="result">
    </form>
    <button onmousedown="startConverting()" onmouseup="stopConverting()"><i class="fa fa-microphone"></i></button>
    <script type="text/javascript">

        var r = document.getElementById('result');
                    var speechRecognizer = new webkitSpeechRecognition();
        function startConverting(){
            if('webkitSpeechRecognition' in window){

                speechRecognizer.continuous = true;
                speechRecognizer.interimResults = true;
                speechRecognizer.lang = 'en-IN';
                speechRecognizer.start();

                var finalTranscripts = '';

                speechRecognizer.onresult = function(event){
                    var interimTranscripts = '';
                    for(var i = event.resultIndex; i < event.results.length; i++){
                        var transcript = event.results[i][0].transcript;
                        transcript.replace("\\n", "<br>");
                        if(event.results[i].isFinal){
                            finalTranscripts += transcript;
                        }else{
                            interimTranscripts += transcript;
                        }
                    }
                    r.innerText = finalTranscripts + '<span style="color:#999">' + interimTranscripts + '</span>';
                };
                speechRecognizer.onerror = function (event) {
                };
            }else{
                r.innerText = 'Your browser is not supported. If google chrome, please upgrade!';
            }
        }

        function stopConverting()
        {
                        speechRecognizer.stop();

        }

    </script>

0 个答案:

没有答案