Created
August 21, 2015 09:11
-
-
Save astagi/284ab5bd048a21e7bf4f to your computer and use it in GitHub Desktop.
Revisions
-
astagi created this gist
Aug 21, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ var app = angular.module('demo', ['textToSpeech']); app.controller('demoCtrl', function($scope, $timeout, textToSpeech) { textToSpeech.onVoiceReady(function(){ textToSpeech.speak( 'You worked 9 hours!!', 'UK English Male', {pitch: 2} ).then(function() { alert('Finish!'); }, function(err) { alert('Error! ' + err); }); }); }); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ <!DOCTYPE html> <html ng-app="demo"> <head> <meta charset="utf-8"> <title>ng-nephila demo</title> <script src="lib/angular/angular.min.js"></script> <script src='http://code.responsivevoice.org/responsivevoice.js'></script> <script src="js/text-to-speech.js"></script> <script src="js/appdemo.js"></script> </head> <body ng-controller="demoCtrl"></body> </html> This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ angular.module('textToSpeech', []) .factory('textToSpeech', ['$timeout', '$q', function($timeout, $q) { var ready = false; var readyCallback; responsiveVoice.OnVoiceReady = function() { if (ready === false) { if (readyCallback !== undefined) { readyCallback.call(); } ready = true; } } return { isReady: function() { return ready; }, onVoiceReady: function(callback) { readyCallback = callback; }, speak: function(text, voice, options) { var q = $q.defer(); if (voice === undefined) { voice = 'UK English Male'; } if (options === undefined) { options = {}; } options.onend = function() { q.resolve(); } $timeout(function() { try { responsiveVoice.speak(text, voice, options); } catch (err) { q.reject(err); } }, 1); return q.promise; } } }]);