Skip to content

Commit ed31361

Browse files
committed
adding element option to TTS.synthesize()
1 parent fce214a commit ed31361

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ Accepts input from `RecognizeStream()` and friends, writes text to supplied `out
161161

162162
## Changelog
163163

164+
### v next
165+
* Added `options.element` to TextToSpeech.synthesize() to support playing through exiting elements
166+
164167
### v0.14
165168
* Moved getUserMedia shim to a [standalone library](https://www.npmjs.com/package/get-user-media-promise)
166169
* added a python token server example

text-to-speech/synthesize.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var QUERY_PARAMS_ALLOWED = ['voice', 'X-WDC-PL-OPT-OUT', 'text', 'watson-token']
3434
* @param {String} [options.voice=en-US_MichaelVoice] what voice to use - call getVoices() for a complete list.
3535
* @param {Number} [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
3636
* @param {Boolean} [options.autoPlay=true] automatically play the audio
37+
* @param {DOMAudioElement} [options.element] <audio> element - will be used instead of creating a new one if provided
3738
* @returns {Audio}
3839
* @see module:watson-speech/text-to-speech/get-voices
3940
*/
@@ -43,7 +44,7 @@ module.exports = function synthesize(options) {
4344
}
4445
options['watson-token'] = options.token;
4546
delete options.token;
46-
var audio = new Audio();
47+
var audio = options.element || new Audio();
4748
audio.crossOrigin = true;
4849
audio.src = 'https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?' + qs.stringify(pick(options, QUERY_PARAMS_ALLOWED));
4950
if (options.autoPlay !== false) {

0 commit comments

Comments
 (0)