【问题标题】:Speech to Text (Webkit) just visible in console. How to print into text field?Speech to Text (Webkit) 仅在控制台中可见。如何打印到文本字段?
【发布时间】:2018-05-20 20:50:01
【问题描述】:

我想用 chrome 的 webkit 做一个语音到文本的应用程序。它工作正常,但我无法将我的口语文本放入专用字段,但它显示在控制台上......它应该出现在我也可以写的同一个文本字段中。附上你可以找到我的 HTML/JS 的一部分。如果需要,我也可以发布整个文件。

        <label for="textInput" class="inputOutline">
          <input id="textInput" class="input responsive-column"
            placeholder="Type something" type="text"
            onkeydown="/*globals CanvasJS */
            ConversationPanel.inputKeyDown(event, this)">
        </label>


<button onclick="startConverting();"><i class="fa fa-microphone"></button> <!-- NEW TILL /SCRIPT-->
<script type="text/javascript">

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

	function startConverting (){

		if('webkitSpeechRecognition' in window){
	var speechRecognizer = new webkitSpeechRecognition();
	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.innerHTML = finalTranscripts + '<span style="color#999' +interimTranscripts + '</span>'; 
	};

	speechRecognizer.onerror = function (event) {

	};
}else {
	r.innerHTML = 'use google chrome';
}

	}



</script>

控制台正在向我显示这个....但是文本需要出现在屏幕上。

<input id="textInput" class="input responsive-column" placeholder="Type something" type="text" onkeydown="/*globals CanvasJS */
            ConversationPanel.inputKeyDown(event, this)" style="width:100%">this text should appear in the text area not just in the console</input> ==$0

我非常感谢任何形式的帮助。

【问题讨论】:

    标签: javascript html webkit speech-recognition speech-to-text


    【解决方案1】:

    您使用输入字段错误,它没有结束标记。你应该有:

    <input id="textInput" class="input responsive-column" placeholder="Type something" type="text" onkeydown="/*globals CanvasJS */
                ConversationPanel.inputKeyDown(event, this)" style="width:100%" value="this text should appear in the text area not just in the console"/>

    你也可以使用 textarea 元素:

    <textarea id="textInput" class="input responsive-column" placeholder="Type something" type="text" onkeydown="/*globals CanvasJS */
                ConversationPanel.inputKeyDown(event, this)" style="width:100%">this text should appear in the text area not just in the console</textarea>

    【讨论】:

    • 您好 chinloyal,非常感谢您的帮助! ...我需要用稍微不同的方法来解决这个问题
    猜你喜欢
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2019-04-07
    • 1970-01-01
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 2021-04-09
    相关资源
    最近更新 更多