diff --git a/README.md b/README.md
index cf40f7e0..852365f5 100644
--- a/README.md
+++ b/README.md
@@ -136,6 +136,9 @@ For use with `.recognizeBlob({play: true})` - slows the results down to match th
## Changelog
+### v0.9
+* Added basic text to speech support
+
### v0.8
* deprecated `result` events in favor of `objectMode`.
* renamed the `autoplay` option to `autoPlay` on `recognizeElement()` (capital P)
diff --git a/examples/package.json b/examples/package.json
index f31b17fc..449b1d81 100644
--- a/examples/package.json
+++ b/examples/package.json
@@ -2,9 +2,8 @@
"name": "watson-speech-examples",
"version": "1.0.0",
"description": "Examples showing the IBM Watson Speech Javascript SDK in action.",
- "main": "token-server.js",
"scripts": {
- "start": "node token-server.js"
+ "start": "node server.js"
},
"dependencies": {
"express": "^4.13.3",
diff --git a/examples/public/Us_English_Narrowband_Sample_1.wav b/examples/public/Us_English_Narrowband_Sample_1.wav
deleted file mode 100644
index 2ed7bbe7..00000000
Binary files a/examples/public/Us_English_Narrowband_Sample_1.wav and /dev/null differ
diff --git a/examples/public/Us_English_Narrowband_Sample_2.wav b/examples/public/Us_English_Narrowband_Sample_2.wav
deleted file mode 100644
index 1e963602..00000000
Binary files a/examples/public/Us_English_Narrowband_Sample_2.wav and /dev/null differ
diff --git a/examples/public/audio-element-programmatic.html b/examples/public/audio-element-programmatic.html
index a3db5cb1..ce908bfa 100644
--- a/examples/public/audio-element-programmatic.html
+++ b/examples/public/audio-element-programmatic.html
@@ -25,7 +25,7 @@
Code for this demo:
var $output = $('#output');
$('#button').click(function () {
- $.get('/token').then(function (token) {
+ $.get('/api/speech-to-text/token').then(function (token) {
$output.html('');
var audioElement = new Audio(); // document.createElement('video'); also works here
diff --git a/examples/public/audio-element.html b/examples/public/audio-element.html
index fb86ed6c..0caeedee 100644
--- a/examples/public/audio-element.html
+++ b/examples/public/audio-element.html
@@ -27,7 +27,7 @@ Code for this demo:
var $output = $('#output');
$('#button').click(function () {
- $.get('/token').then(function (token) {
+ $.get('/api/speech-to-text/token').then(function (token) {
$output.html('');
var stream = WatsonSpeech.SpeechToText.recognizeElement({
diff --git a/examples/public/blob-realtime-vs-no-realtime.html b/examples/public/blob-realtime-vs-no-realtime.html
index 5d00c663..731e6e53 100644
--- a/examples/public/blob-realtime-vs-no-realtime.html
+++ b/examples/public/blob-realtime-vs-no-realtime.html
@@ -56,7 +56,7 @@ Code for this demo:
var stream;
$('#button').click(function () {
- $.get('/token').then(function (token) {
+ $.get('/api/speech-to-text/token').then(function (token) {
stream = WatsonSpeech.SpeechToText.recognizeBlob({
token: token,
diff --git a/examples/public/file-promise.html b/examples/public/file-promise.html
index 5d35ddcd..e90d5014 100644
--- a/examples/public/file-promise.html
+++ b/examples/public/file-promise.html
@@ -24,7 +24,7 @@ Code for this demo:
var $output = $('#output');
$('#button').click(function () {
- $.get('/token').then(function (token) {
+ $.get('/api/speech-to-text/token').then(function (token) {
$output.html('Processing...');
WatsonSpeech.SpeechToText.recognizeBlob({
diff --git a/examples/public/file-streaming.html b/examples/public/file-streaming.html
index f09722ee..f3693a21 100644
--- a/examples/public/file-streaming.html
+++ b/examples/public/file-streaming.html
@@ -27,7 +27,7 @@ Code for this demo:
$('#button').click(function () {
$output.html('');
- $.get('/token').then(function (token) {
+ $.get('/api/speech-to-text/token').then(function (token) {
stream = WatsonSpeech.SpeechToText.recognizeBlob({
token: token,
diff --git a/examples/public/microphone-streaming-auto-stop.html b/examples/public/microphone-streaming-auto-stop.html
index 3cdeea0e..51f52d05 100644
--- a/examples/public/microphone-streaming-auto-stop.html
+++ b/examples/public/microphone-streaming-auto-stop.html
@@ -26,7 +26,7 @@ Code for this demo:
$('#button').click(function () {
$output.html('');
- $.get('/token').then(function (token) {
+ $.get('/api/speech-to-text/token').then(function (token) {
var stream = WatsonSpeech.SpeechToText.recognizeMicrophone({
token: token,
continuous: false, // false = automatically stop transcription the first time a pause is detected
diff --git a/examples/public/microphone-streaming.html b/examples/public/microphone-streaming.html
index 02b898ee..64a45667 100644
--- a/examples/public/microphone-streaming.html
+++ b/examples/public/microphone-streaming.html
@@ -27,7 +27,7 @@ Code for this demo:
$('#button').click(function () {
$output.html('');
- $.get('/token').then(function (token) {
+ $.get('/api/speech-to-text/token').then(function (token) {
var stream = WatsonSpeech.SpeechToText.recognizeMicrophone({
token: token,
objectMode: true // necessary to receive interim results
diff --git a/examples/server.js b/examples/server.js
new file mode 100644
index 00000000..f62d3eed
--- /dev/null
+++ b/examples/server.js
@@ -0,0 +1,51 @@
+/**
+ * Copyright 2015 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+'use strict';
+
+var express = require('express'),
+ app = express();
+
+app.use(express.static(__dirname + '/public'));
+app.use(express.static(__dirname + '/../dist')); // normally these files would also go into public/ but this way the example always has the latest code
+
+// token endpoints
+// **Warning**: these endpoints should be guarded with additional authentication & authorization for production use
+app.use('/api/speech-to-text/', require('./stt-token.js'));
+app.use('/api/text-to-speech/', require('./tts-token.js'));
+
+var port = process.env.VCAP_APP_PORT || 3000;
+app.listen(port, function() {
+ console.log('Example IBM Watson Speech JS SDK client app & token server live at http://localhost:%s/', port);
+});
+
+// chrome requires https to access the user's microphone unless it's a localhost url so
+// this sets up a basic server at https://localhost3001/ using an included self-signed certificate
+// note: this is not suitable for production use
+// however bluemix automatically adds https support at http://.mybluemix.net
+if (!process.env.VCAP_APP_PORT) {
+ var fs = require("fs"),
+ https = require("https"),
+ HTTPS_PORT = 3001;
+
+ var options = {
+ key: fs.readFileSync(__dirname + '/keys/localhost.pem'),
+ cert: fs.readFileSync(__dirname + '/keys/localhost.cert')
+ };
+ https.createServer(options, app).listen(HTTPS_PORT, function () {
+ console.log('Secure server live at https://localhost:%s/', port)
+ });
+}
diff --git a/examples/stt-token.js b/examples/stt-token.js
new file mode 100644
index 00000000..b2b6f6ad
--- /dev/null
+++ b/examples/stt-token.js
@@ -0,0 +1,34 @@
+'use strict';
+
+var express = require('express'),
+ router = express.Router(),
+ vcapServices = require('vcap_services'),
+ extend = require('util')._extend,
+ watson = require('watson-developer-cloud');
+
+// set up an endpoint to serve speech-to-text auth tokens
+
+// For local development, replace username and password
+var sttConfig = extend({
+ version: 'v1',
+ url: 'https://stream.watsonplatform.net/speech-to-text/api',
+ username: '',
+ password: ''
+}, vcapServices.getCredentials('speech_to_text'));
+
+// quick hack to make development easier
+try { extend(sttConfig, require('../test/resources/stt-auth.json')) } catch (ex) {console.log(ex)}
+
+var sttAuthService = watson.authorization(sttConfig);
+
+router.get('/token', function(req, res) {
+ sttAuthService.getToken({url: sttConfig.url}, function(err, token) {
+ if (err) {
+ console.log('Error retrieving token: ', err);
+ return res.status(500).send('Error retrieving token')
+ }
+ res.send(token);
+ });
+});
+
+module.exports = router;
diff --git a/examples/token-server.js b/examples/token-server.js
deleted file mode 100644
index 1b4ad828..00000000
--- a/examples/token-server.js
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * Copyright 2015 IBM Corp. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-'use strict';
-
-var express = require('express'),
- app = express(),
- vcapServices = require('vcap_services'),
- extend = require('util')._extend,
- watson = require('watson-developer-cloud');
-
-app.use(express.static(__dirname + '/public'));
-app.use(express.static(__dirname + '/../dist')); // normally these files would also go into public/ but this way the example always has the latest code
-
-
-// set up an endpoint to serve speech-to-text auth tokens
-
-// For local development, replace username and password
-var sttConfig = extend({
- version: 'v1',
- url: 'https://stream.watsonplatform.net/speech-to-text/api',
- username: '',
- password: ''
-}, vcapServices.getCredentials('speech_to_text'));
-
-// quick hack to make development easier
-try { extend(sttConfig, require('../test/resources/stt-auth.json')) } catch (ex) {}
-
-var sttAuthService = watson.authorization(sttConfig);
-
-// Get token using your credentials
-// **Warning**: these endpoints should be guarded with additional authentication & authorization for production use
-app.get('/api/speech-to-text/token', function(req, res) {
- sttAuthService.getToken({url: sttConfig.url}, function(err, token) {
- if (err) {
- console.log('Error retrieving token: ', err);
- return res.status(500).send('Error retrieving token')
- }
- res.send(token);
- });
-});
-
-// and, do it all again for the text to speech service
-var ttsConfig = extend({
- version: 'v1',
- url: 'https://stream.watsonplatform.net/text-to-speech/api',
- username: '',
- password: ''
-}, vcapServices.getCredentials('text_to_speech'));
-
-// quick hack to make development easier
-try { extend(ttsConfig, require('../test/resources/tts-auth.json')) } catch (ex) {}
-
-var ttsAuthService = watson.authorization(ttsConfig);
-
-app.get('/api/text-to-speech/token', function(req, res) {
- ttsAuthService.getToken({url: ttsConfig.url}, function(err, token) {
- if (err) {
- console.log('Error retrieving token: ', err);
- return res.status(500).send('Error retrieving token')
- }
- res.send(token);
- });
-});
-
-var port = process.env.VCAP_APP_PORT || 3000;
-app.listen(port, function() {
- console.log('Example IBM Watson Speech JS SDK client app & token server live at http://localhost:%s/', port);
-});
-
-// chrome requires https to access the user's mic unless it's a localhost url
-if (!process.env.VCAP_APP_PORT) {
- var fs = require("fs"),
- https = require("https"),
- HTTPS_PORT = 3001;
-
- var options = {
- key: fs.readFileSync(__dirname + '/keys/localhost.pem'),
- cert: fs.readFileSync(__dirname + '/keys/localhost.cert')
- };
- https.createServer(options, app).listen(HTTPS_PORT, function () {
- console.log('Secure server live at https://localhost:%s/', port)
- });
-}
diff --git a/examples/tts-token.js b/examples/tts-token.js
new file mode 100644
index 00000000..dc424732
--- /dev/null
+++ b/examples/tts-token.js
@@ -0,0 +1,34 @@
+'use strict';
+
+var express = require('express'),
+ router = express.Router(),
+ vcapServices = require('vcap_services'),
+ extend = require('util')._extend,
+ watson = require('watson-developer-cloud');
+
+// another endpoint for the text to speech service
+
+// For local development, replace username and password
+var ttsConfig = extend({
+ version: 'v1',
+ url: 'https://stream.watsonplatform.net/text-to-speech/api',
+ username: '',
+ password: ''
+}, vcapServices.getCredentials('text_to_speech'));
+
+// quick hack to make development easier
+try { extend(ttsConfig, require('../test/resources/tts-auth.json')) } catch (ex) {}
+
+var ttsAuthService = watson.authorization(ttsConfig);
+
+router.get('/token', function(req, res) {
+ ttsAuthService.getToken({url: ttsConfig.url}, function(err, token) {
+ if (err) {
+ console.log('Error retrieving token: ', err);
+ return res.status(500).send('Error retrieving token')
+ }
+ res.send(token);
+ });
+});
+
+module.exports = router;