Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Created September 27, 2016 18:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sunnygleason/7a087ab7a8102a74290818b515bef660 to your computer and use it in GitHub Desktop.
AngularJS Speech Recognition
<!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