Created
September 27, 2016 18:49
Star
You must be signed in to star a gist
AngularJS Speech Recognition
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
<!doctype html> | |
<html> | |
<head> | |
<script src="https://cdn.pubnub.com/pubnub-3.15.1.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> | |
<script src="https://cdn.pubnub.com/sdk/pubnub-angular/pubnub-angular-3.2.1.min.js"></script> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" /> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" /> | |
</head> | |
<body> | |
<div class="container" ng-app="PubNubAngularApp" ng-controller="MySpeechCtrl"> | |
<pre>NOTE: Requires Chrome Desktop or Android Browser</pre> | |
<h3>MySpeech to Text</h3> | |
<textarea ng-model="theText" rows="10" cols="40"></textarea> | |
<input type="button" ng-click="dictateIt()" value="Dictate it!" /> | |
</div> | |
<script> | |
angular.module('PubNubAngularApp', ["pubnub.angular.service"]) | |
.controller('MySpeechCtrl', function($rootScope, $scope, Pubnub) { | |
$scope.theText = "Don't just stand there, say something!"; | |
$scope.dictateIt = function () { | |
$scope.theText = ""; | |
var recognition = new webkitSpeechRecognition(); | |
recognition.onresult = function (event) { | |
$scope.$apply(function() { | |
for (var i = event.resultIndex; i < event.results.length; i++) { | |
if (event.results[i].isFinal) { | |
$scope.theText += event.results[i][0].transcript; | |
} | |
} | |
}); | |
}; | |
recognition.start(); | |
}; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment