Skip to content

Commit 08d8b6c

Browse files
committed
Adding support for setting X-Watson-Learning-Opt-Out on TextToSpeech.synthesize
Fixes watson-developer-cloud#226
1 parent 23bb02b commit 08d8b6c

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

services/text_to_speech/v1.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ var requestFactory = require('../../lib/requestwrapper');
2828
function TextToSpeech(options) {
2929
// Default URL
3030
var serviceDefaults = {
31-
url: 'https://stream.watsonplatform.net/text-to-speech/api',
32-
headers: {
33-
'content-type': 'application/json'
34-
}
31+
url: 'https://stream.watsonplatform.net/text-to-speech/api'
3532
};
3633

3734
// Replace default options with user provided
@@ -40,6 +37,13 @@ function TextToSpeech(options) {
4037

4138
/**
4239
* Streaming speech synthesis of the text in a query parameter
40+
*
41+
* @param {Object} options
42+
* @param {String} options.text
43+
* @param {String} [options.voice]
44+
* @param {String} [options.accept]
45+
* @param {Boolean} [options.X-Watson-Learning-Opt-Out]
46+
* @param {Function} callback
4347
*/
4448
TextToSpeech.prototype.synthesize = function(params, callback) {
4549
params = extend({accept:'audio/ogg; codecs=opus'}, params);
@@ -54,9 +58,9 @@ TextToSpeech.prototype.synthesize = function(params, callback) {
5458
url: '/v1/synthesize',
5559
body: JSON.stringify(pick(params, ['text'])),
5660
qs: pick(params, ['accept', 'voice']),
57-
headers: {
61+
headers: extend({
5862
'content-type': 'application/json'
59-
},
63+
}, pick(params, ['X-Watson-Learning-Opt-Out'])),
6064
encoding: null
6165
},
6266
defaultOptions: this._options

test/test.text_to_speech.v1.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ describe('text_to_speech', function() {
9494
assert.equal(req.headers['content-type'], 'application/json');
9595
});
9696

97+
it('should support the X-Watson-Learning-Opt-Out option', function() {
98+
var params = {'X-Watson-Learning-Opt-Out': true, text: 'test'};
99+
var req = text_to_speech.synthesize(params, noop);
100+
assert.equal(req.headers['X-Watson-Learning-Opt-Out'], '1');
101+
});
102+
97103
});
98104

99105
describe('voices()', function(){

0 commit comments

Comments
 (0)