Skip to content

Commit 4e25f2f

Browse files
committed
2 parents 5db8db3 + 71380bc commit 4e25f2f

13 files changed

Lines changed: 796 additions & 1082 deletions

File tree

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
node_modules/*
1+
node_modules
22
npm-debug.log
3+
npm-debug.log.*
34
coverage
45
.DS_Store
56
test/resources/auth.js
@@ -10,5 +11,3 @@ doc/
1011
.vscode/
1112
dist/
1213
.env
13-
examples/browserify/node_modules/
14-

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# v2.2.0
2+
* Added support for creating and managing TTS Customizations
3+
4+
# v2.1.3
5+
* Deprecation warning for Dialog
6+
* Added TTS .voice() and .pronunciation() methods
7+
* Added support for `customization_id` to existing TTS methods
8+
* Typo and JSDoc fixes
9+
* Fixed bug with pulling api key from env properties for alchemy services
10+
111
# v2.1.2
212
* Added profanity_filter support to STT RecognizeStream
313

README.md

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ Watson Developer Cloud Node.js SDK
77
[![npm-version](https://img.shields.io/npm/v/watson-developer-cloud.svg)](https://www.npmjs.com/package/watson-developer-cloud)
88
[![npm-downloads](https://img.shields.io/npm/dm/watson-developer-cloud.svg)](https://www.npmjs.com/package/watson-developer-cloud)
99

10-
Node client library to use the [Watson Developer Cloud][wdc] services, a collection of REST
11-
APIs and SDKs that use cognitive computing to solve complex problems.
10+
Node.js client library to use the [Watson Developer Cloud][wdc] services, a collection of APIs that use cognitive computing to solve complex problems.
1211

1312
## Table of Contents
1413
* [Major Changes for v2](#major-changes-for-v2)
@@ -67,7 +66,7 @@ Note: not all services currently support CORS, and therefore not all services ca
6766
Of those that do, most require an auth token to be generated server-side via the [Authorization Service](#authorization).
6867

6968
### New recommended method for instantiating services:
70-
69+
7170
```js
7271
var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');
7372

@@ -220,7 +219,7 @@ alchemy_data_news.getNews(params, function (err, news) {
220219
### Authorization
221220
The Authorization service can generates auth tokens for situations where providing the service username/password is undesirable.
222221

223-
Tokens are valid for 1 hour and may be sent using the `X-Watson-Authorization-Token` header or the `watson-token` query param.
222+
Tokens are valid for 1 hour and may be sent using the `X-Watson-Authorization-Token` header or the `watson-token` query param.
224223

225224
Note that the token is supplied URL-encoded, and will not be accepted if it is double-encoded in a querystring.
226225

@@ -275,24 +274,7 @@ conversation.message({
275274
```
276275

277276
### Dialog
278-
Use the Dialog service to list all the dialogs you have.
279-
280-
```javascript
281-
var DialogV1 = require('watson-developer-cloud/dialog/v1');
282-
283-
var dialog = new DialogV1({
284-
username: '<username>',
285-
password: '<password>',
286-
version_date: '2015-12-01'
287-
});
288-
289-
dialog.getDialogs({}, function (err, dialogs) {
290-
if (err)
291-
console.log('error:', err);
292-
else
293-
console.log(JSON.stringify(dialogs, null, 2));
294-
});
295-
```
277+
The Dialog service was deprecated on August 15, 2016, existing instances of the service will continue to function until August 9, 2017. Users of the Dialog service should migrate their applications to use the Conversation service. See the [migration documentation][dialog_migration] to learn how to migrate your dialogs to the Conversation service.
296278

297279
### Document Conversion
298280

@@ -671,6 +653,7 @@ See [CONTRIBUTING](https://github.com/watson-developer-cloud/node-sdk/blob/maste
671653
[bluemix]: https://console.ng.bluemix.net
672654
[npm_link]: https://www.npmjs.com/package/watson-developer-cloud
673655
[request_github]: https://github.com/request/request
656+
[dialog_migration]: https://www.ibm.com/watson/developercloud/doc/conversation/migration.shtml
674657

675658
[examples]: https://github.com/watson-developer-cloud/node-sdk/tree/master/examples
676659
[document_conversion_integration_example]: https://github.com/watson-developer-cloud/node-sdk/tree/master/examples/document_conversion_integration.v1.js

dialog/v1.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ var BaseService = require('../lib/base_service');
3131
*/
3232
function DialogV1(options) {
3333
BaseService.call(this, options);
34+
35+
if (!options.silent) {
36+
//eslint-disable-next-line no-console
37+
console.warn('WARNING: The Dialog service was deprecated, existing instances of the service will continue to function until August 9, 2017. See https://www.ibm.com/watson/developercloud/doc/conversation/migration.shtml. Set {silent: true} to disable this message.');
38+
}
3439
}
3540
util.inherits(DialogV1, BaseService);
3641
DialogV1.prototype.name = 'dialog';

examples/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "wdc-examples",
3+
"version": "1.0.0",
4+
"description": "Examples of using the IBM Watson Developer Cloud Node.js SDK",
5+
"private": true,
6+
"license": "Apache-2.0",
7+
"dependencies": {
8+
"watson-developer-cloud":"*"
9+
}
10+
}

examples/text_to_speech.v1.js

Lines changed: 224 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,232 @@
33
var TextToSpeechV1 = require('watson-developer-cloud/text-to-speech/v1');
44
var fs = require('fs');
55

6-
var text_to_speech = new TextToSpeechV1({
7-
username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
8-
password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE'
6+
var textToSpeech = new TextToSpeechV1({
7+
// if left unspecified here, the SDK will fall back to the TEXT_TO_SPEECH_USERNAME and TEXT_TO_SPEECH_PASSWORD
8+
// environment properties, and then Bluemix's VCAP_SERVICES environment property
9+
//username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
10+
//password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE'
911
});
1012

11-
var params = {
13+
// Synthesize speech and then pipe the results to a file
14+
textToSpeech.synthesize({
1215
text: 'Hello from IBM Watson',
1316
voice: 'en-US_AllisonVoice', // Optional voice
14-
accept: 'audio/wav'
15-
};
17+
accept: 'audio/wav' // default is audio/ogg; codec=opus
18+
}).pipe(fs.createWriteStream('output.wav'));
1619

17-
// Pipe the synthesized text to a file
18-
text_to_speech.synthesize(params).pipe(fs.createWriteStream('output.wav'));
20+
// Retrieve details of all available voices
21+
textToSpeech.voices({}, function(err, res){
22+
if (err) {
23+
return console.log(err);
24+
}
25+
console.log(JSON.stringify(res, null, 2));
26+
});
27+
28+
// Retrieve details of a specific voice
29+
textToSpeech.voice({
30+
voice: 'en-GB_KateVoice'
31+
}, function(err, res){
32+
if (err) {
33+
return console.log(err);
34+
}
35+
console.log(JSON.stringify(res, null, 2));
36+
});
37+
38+
// Pronunciation details for a word
39+
textToSpeech.pronunciation({
40+
text: 'iPhone',
41+
format: 'spr', // 'ipa' (default) is only for english voices
42+
voice: 'de-DE_DieterVoice' // optional, defaults to en-US_MichaelVoice
43+
}, function(err, res){
44+
if (err) {
45+
return console.log(err);
46+
}
47+
console.log(JSON.stringify(res, null, 2));
48+
});
49+
50+
// create a customization model to change pronunciation of words
51+
textToSpeech.createCustomization({
52+
name: 'my custom alt language pronunciation model',
53+
language: 'en-US', // currently, only en-US is accepted
54+
description: 'Test model to try out custom pronunciations'
55+
}, function(err, res){
56+
if (err) {
57+
return console.log(err);
58+
}
59+
console.log(JSON.stringify(res, null, 2));
60+
/*
61+
{
62+
"customization_id": "6666451d-a23e-485c-9bc5-c7ce722550d6"
63+
}
64+
*/
65+
});
66+
67+
// update a customization model
68+
textToSpeech.updateCustomization({
69+
customization_id: "6666451d-a23e-485c-9bc5-c7ce722550d6",
70+
name: 'new name', // optional
71+
description: 'new description', // optional
72+
words: [ // required - replaces existing words list
73+
{"word":"NCAA", "translation":"N C double A"},
74+
{"word":"iPhone", "translation":"I phone"}
75+
]
76+
}, function(err){
77+
if (err) {
78+
return console.log(err);
79+
}
80+
console.log('updated');
81+
});
82+
83+
// get a list of custom voice models
84+
textToSpeech.getCustomizations({
85+
language: 'en-US' // optional filter (currently only accepts en-US)
86+
}, function(err, res){
87+
if (err) {
88+
return console.log(err);
89+
}
90+
console.log(JSON.stringify(res, null, 2));
91+
/*
92+
{
93+
"customizations": [
94+
{
95+
"last_modified": 1472067196711,
96+
"customization_id": "10ba7c7c-ce2d-447f-9724-72da0d6f1e66",
97+
"created": 1472067196711,
98+
"description": "Test model to try out custom pronunciations",
99+
"name": "my custom pronunciation model",
100+
"language": "en-US",
101+
"owner": "7f966201-2afd-48ea-b5c1-d6981d50633e"
102+
},
103+
{
104+
"last_modified": 1465475563937,
105+
"customization_id": "e24536fd-b1b4-48f3-95fe-c2d93e7f5c45",
106+
"created": 1465475563937,
107+
"description": "a simple model for testing purposes",
108+
"name": "test model",
109+
"language": "en-US",
110+
"owner": "7f966201-2afd-48ea-b5c1-d6981d50633e"
111+
}
112+
//...
113+
]
114+
}
115+
*/
116+
});
117+
118+
// get details of a custom voice model
119+
textToSpeech.getCustomization({
120+
customization_id: "6666451d-a23e-485c-9bc5-c7ce722550d6"
121+
}, function(err, res){
122+
if (err) {
123+
return console.log(err);
124+
}
125+
console.log(JSON.stringify(res, null, 2));
126+
/*
127+
{
128+
"last_modified": 1472067165812,
129+
"customization_id": "6666451d-a23e-485c-9bc5-c7ce722550d6",
130+
"created": 1472066628780,
131+
"words": [
132+
{
133+
"word": "NCAA",
134+
"translation": "N C double A"
135+
},
136+
{
137+
"word": "iPhone",
138+
"translation": "I phone"
139+
}
140+
],
141+
"description": "new description",
142+
"name": "new name",
143+
"language": "en-US",
144+
"owner": "7f966201-2afd-48ea-b5c1-d6981d50633e"
145+
}
146+
*/
147+
});
148+
149+
// delete a custom voice model
150+
textToSpeech.deleteCustomization({
151+
customization_id: "9d153f61-a9c4-4b73-8eaf-63951c6dd77d"
152+
}, function(err){
153+
if (err) {
154+
return console.log(err);
155+
}
156+
console.log('deleted');
157+
});
158+
159+
// add multiple words to an existing model
160+
textToSpeech.addWords({
161+
customization_id: "7c7f8ba7-2f83-48f2-ae52-3a70825f9899",
162+
words: [
163+
{"word":"NCAA", "translation":"N C double A"},
164+
{"word":"iPhone", "translation":"I phone"}
165+
]
166+
}, function(err){
167+
if (err) {
168+
return console.log(err);
169+
}
170+
console.log('added');
171+
});
172+
173+
// add a single word to an existing model
174+
textToSpeech.updateCustomization({
175+
customization_id: "7c7f8ba7-2f83-48f2-ae52-3a70825f9899",
176+
word:"NCAA",
177+
translation:"N C double A"
178+
}, function(err){
179+
if (err) {
180+
return console.log(err);
181+
}
182+
console.log('added');
183+
});
184+
185+
// get all words in a customization
186+
textToSpeech.getWords({
187+
customization_id: "7c7f8ba7-2f83-48f2-ae52-3a70825f9899"
188+
}, function(err, res){
189+
if (err) {
190+
return console.log(err);
191+
}
192+
console.log(JSON.stringify(res, null, 2));
193+
/*
194+
{
195+
"words": [
196+
{
197+
"word": "NCAA",
198+
"translation": "N C double A"
199+
},
200+
{
201+
"word": "iPhone",
202+
"translation": "I phone"
203+
}
204+
]
205+
}
206+
*/
207+
});
208+
209+
// get a single word from a customization
210+
textToSpeech.getWord({
211+
customization_id: "7c7f8ba7-2f83-48f2-ae52-3a70825f9899",
212+
word: "iPhone"
213+
}, function(err, res){
214+
if (err) {
215+
return console.log(err);
216+
}
217+
console.log(JSON.stringify(res, null, 2));
218+
/*
219+
{
220+
"translation": "I phone"
221+
}
222+
*/
223+
});
224+
225+
// delete a word from a customization
226+
textToSpeech.deleteWord({
227+
customization_id: "7c7f8ba7-2f83-48f2-ae52-3a70825f9899",
228+
word: "iPhone"
229+
}, function(err){
230+
if (err) {
231+
return console.log(err);
232+
}
233+
console.log('deleted word');
234+
});

0 commit comments

Comments
 (0)