-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
549 additions
and
34 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Custom Voice - Watson Text to Speech</title> | ||
</head> | ||
<body> | ||
|
||
<section> | ||
<h2>Text to Speech with Custom Voice Example</h2> | ||
<textarea id="text" rows="6" cols="80">Hello from IBM Watson</textarea> | ||
<p>Voice: <select id="voice"></select></p> | ||
<p><button id="button">Synthesize Text</button></p> | ||
</section> | ||
|
||
<script src="watson-speech.js"></script> | ||
<script src="http://code.jquery.com/jquery-2.2.0.min.js"></script> | ||
|
||
<h2>Code for this demo:</h2> | ||
<pre><code><script style="display: block;"> | ||
$(function() { | ||
$.get('/api/text-to-speech/token').then(function (token) { | ||
WatsonSpeech.TextToSpeech.getVoices({token: token}).then(function (voices) { | ||
$('#voice').html(voices.map(function(v) { | ||
return '<option value="' + v.name + '"' + (v.name == 'en-GB_KateVoice' ? ' selected' : '') + '>' + v.name + '</option>'; | ||
}).join('\n')); | ||
}).catch(console.error.bind(console)); | ||
}); | ||
|
||
$('#button').click(function () { | ||
$.get('/api/text-to-speech/token').then(function (token) { | ||
WatsonSpeech.TextToSpeech.synthesize({ | ||
text: $('#text').val(), | ||
voice: $('#voice').val(), | ||
token: token | ||
}) | ||
}); | ||
}); | ||
}); | ||
</script></code></pre> | ||
</body> | ||
</html> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use strict"; | ||
require('whatwg-fetch'); // pollyfill - most supported browsers have this built-in | ||
|
||
module.exports = function getVoices(options) { | ||
if (!options || !options.token) { | ||
throw new Error("Watson TextToSpeech: missing required parameter: options.token"); | ||
} | ||
var reqOpts = { | ||
credentials: 'omit', | ||
headers: { | ||
'accept': 'application/json' | ||
} | ||
}; | ||
return fetch('https://stream.watsonplatform.net/text-to-speech/api/v1/voices?watson-token=' + options.token, reqOpts) | ||
.then(function(response){ | ||
return response.json(); | ||
}).then(function(obj) { | ||
return obj.voices; | ||
}); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,5 @@ | ||
"use strict"; | ||
var qs = require('../util/querystring.js'); | ||
|
||
module.exports.synthesize = function(options) { | ||
if (!options || !options.token) { | ||
throw new Error("Watson TextToSpeech: missing required parameter: options.token"); | ||
} | ||
options['watson-token'] = options.token; | ||
delete options.token; | ||
var audio = new Audio(); | ||
audio.crossOrigin = true; | ||
audio.src = 'https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?' + qs.stringify(options); | ||
audio.play(); | ||
return audio; | ||
}; | ||
exports.synthesize = require('./synthesize'); | ||
|
||
exports.getVoices = require('./get-voices'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use strict"; | ||
var qs = require('../util/querystring.js'); | ||
|
||
/** | ||
* voice=en-US_AllisonVoice | ||
text=Conscious%20of%20its%20spiritual%20and%20moral%20heritage%2C%20the%20Union%20is%20founded%20on%20the%20indivisible%2C%20universal%20values%20of%20human%20dignity%2C%20freedom%2C%20equality%20and%20solidarity%3B%20it%20is%20based%20on%20the%20principles%20of%20democracy%20and%20the%20rule%20of%20law.%20It%20places%20the%20individual%20at%20the%20heart%20of%20its%20activities%2C%20by%20establishing%20the%20citizenship%20of%20the%20Union%20and%20by%20creating%20an%20area%20of%20freedom%2C%20security%20and%20justice. | ||
=0 | ||
* @param options | ||
* @param options.token auth token | ||
* @param options.text text ty speak | ||
* @param [options.voice=en-US_MichaelVoice] what voice to use - call TextToSpeech.getVoices() for a complete list. | ||
* @param [options.X-WDC-PL-OPT-OUT=0] set to 1 to opt-out of allowing Watson to use this request to improve it's services | ||
* @returns {Audio} | ||
*/ | ||
module.exports = function synthesize(options) { | ||
if (!options || !options.token) { | ||
throw new Error("Watson TextToSpeech: missing required parameter: options.token"); | ||
} | ||
options['watson-token'] = options.token; | ||
delete options.token; | ||
var audio = new Audio(); | ||
audio.crossOrigin = true; | ||
audio.src = 'https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?' + qs.stringify(options); | ||
audio.play(); | ||
return audio; | ||
}; | ||
|