Created
August 21, 2015 09:11
-
-
Save astagi/284ab5bd048a21e7bf4f to your computer and use it in GitHub Desktop.
Text to speech Angular Service
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 characters
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 characters
<!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 characters
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; | |
} | |
} | |
}]); |
is there a demo with angular 6 ?
thanks for help
Hi @kastour there's no Angular 6 demo for TTS. This code is 4 years old, anyway Angular.js is just a wrapper, the core of textToSpeech is this library: http://code.responsivevoice.org/responsivevoice.js
You can make your own Angualr 6 application starting from scratch, you just need to:
- include responsivevoice.js as an external dependency (https://www.truecodex.com/course/angular-6/how-to-use-external-js-files-and-javascript-code-in-angular)
- create a service that wraps
text to speech
functions (https://angular.io/tutorial/toh-pt4)
If you need help, let me know!
AS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is there a demo with angular 6 ?
thanks for help