Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
AngularJS Text-To-Speech from PubNub Channel
<!doctype html>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<link rel="stylesheet" href="//" />
<link rel="stylesheet" href="" />
<div class="container" ng-app="PubNubAngularApp" ng-controller="MySpeechCtrl">
<pre>NOTE: make sure to update the PubNub keys below with your keys!</pre>
<h3>MyText to Speech</h3>
<input ng-model="toSend" />
<input type="button" ng-click="publish()" value="Send!" />
<br /><br />
<li ng-repeat="message in messages track by $index">
<a ng-click="sayIt(">(speak again)</a>
angular.module('PubNubAngularApp', ["pubnub.angular.service"])
.controller('MySpeechCtrl', function($rootScope, $scope, Pubnub) {
$scope.messages = [{data:"testing 1 2 3"}];
$scope.msgChannel = 'MySpeech';
if (!$rootScope.initialized) {
publish_key: 'YOUR_PUB_KEY',
subscribe_key: 'YOUR_SUB_KEY',
$rootScope.initialized = true;
var msgCallback = function(payload) {
$scope.$apply(function() {
$scope.publish = function() {
channel: $scope.msgChannel,
message: {data:$scope.toSend}
$scope.toSend = "";
Pubnub.subscribe({ channel: [$scope.msgChannel, $scope.prsChannel], message: msgCallback });
$scope.sayIt = function (theText) {
window.speechSynthesis.speak(new SpeechSynthesisUtterance(theText));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment