A Pen by Carl Boneri on CodePen.
Created
July 12, 2016 14:21
-
-
Save CarlBoneri/51b0c18014bc04ea437009468a4d3ad5 to your computer and use it in GitHub Desktop.
Speech input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Say something</h1> | |
<div id="inter"></div> | |
<div id="final"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var final_transcript = ''; | |
var speech = new webkitSpeechRecognition(); | |
speech.continuous = true; | |
speech.maxAlternatives = 5; | |
speech.interimResults = true; | |
setTimeout(function() {speech.start()}, 2000); | |
//speech.stop(); | |
speech.onresult = function(e) { | |
var interim_transcript = ''; | |
if (typeof(e.results) == 'undefined') { | |
return; | |
} | |
for (var i = e.resultIndex; i < e.results.length; ++i) { | |
var val = e.results[i][0].transcript; | |
if (e.results[i].isFinal) { | |
final_transcript += " " + val; | |
$('#final').text(final_transcript); | |
} | |
interim_transcript += val; | |
$('#inter').text(interim_transcript); | |
} | |
} | |
$().ready(function() { | |
$('#say').on('click', function(e) { | |
e.preventDefault(); | |
speech.start(); | |
}) | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 { | |
font: bold 12pt arial; | |
color: #666; | |
} | |
a { | |
font: normal 12pt arial; | |
} | |
div { | |
font: bold 28pt arial; | |
} | |
#inter { | |
font: normal 12pt arial; | |
color: #999; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment