Skip to content

Commit c208703

Browse files
authored
Merge pull request #244 from chughts/sttwords
STT Customisation - Words Support
2 parents c642d21 + 0826942 commit c208703

File tree

5 files changed

+106
-21
lines changed

5 files changed

+106
-21
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ Node-RED Watson Nodes for IBM Bluemix
77

88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

10+
### New in version 0.4.37
11+
- Added support for word training in Speech to Text Customizations Node.
12+
1013
### New in version 0.4.36
11-
- New Node for Speech to Text Customizations - Initial support for corpus (sentances) training.
14+
- New Node for Speech to Text Customizations - Initial support for corpus (sentences) training.
1215
- Added option to select Customization in Speech to Text Node.
1316

1417
### New in version 0.4.35

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.4.36",
3+
"version": "0.4.37",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"alchemy-api": "^1.3.0",

services/language_translator_identify/v2.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</script>
3636

3737
<script type="text/x-red" data-help-name="watson-language-translator-identify">
38-
<p>Packaged in with release 0.4.36 of node-red-node-watson</p>
38+
<p>Packaged in with release 0.4.37 of node-red-node-watson</p>
3939
<p>The Watson Language Translator service can be used to identify languages used in a text input. <p>
4040
<p>Node input : </p>
4141
<ul>

services/speech_to_text/v1-corpus-builder.html

+33-13
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
<option value="addCorpus">Add Corpus</option>
4949
<option value="getCorpora">Get Corpora</option>
5050
<option value="train">Train</option>
51+
<option value="listCustomWords">List Custom Words</option>
52+
<option value="addWords">Add Words</option>
5153
<option value="deleteCorpus">Delete Corpus</option>
5254
</select>
5355
</div>
@@ -81,6 +83,11 @@
8183
<input type="text" id="node-input-stt-corpus-name" placeholder="">
8284
</div>
8385

86+
<div class="form-row">
87+
<label for="node-input-stt-allow-overwrite"><i class="fa fa-book"></i> Allow Overwrite</label>
88+
<input type="checkbox" id="node-input-stt-allow-overwrite" placeholder="">
89+
</div>
90+
8491

8592
</script>
8693

@@ -125,6 +132,25 @@
125132
by the speech to text service.
126133
</p>
127134
</li>
135+
<li>List Custom Words
136+
<p>In this mode, a list of all the words from a custom model are
137+
retrieved.
138+
</p>
139+
</li>
140+
<li>Add Words
141+
<p>In this mode, the specified custom words are added to the
142+
customization. The input array of words should be passed in
143+
as <code>msg.payload</code> in form of
144+
<code>[{word: String, sounds_like: [String, ...], display_as: String}, ...]</code>
145+
<br/>EG.
146+
<code>
147+
[ {"word": "HHonors", "sounds_like": ["hilton honors", "h honors"],
148+
"display_as": "HHonors"},
149+
{"word": "IEEE", "sounds_like": ["i triple e"]}
150+
]
151+
</code>
152+
</p>
153+
</li>
128154
<li>Delete Corpus
129155
<p>In this mode, the specified corpus is deleted.
130156
</p>
@@ -150,17 +176,6 @@
150176
sttv1qbb.mode_selected = null;
151177
sttv1qbb.model_selected = '';
152178

153-
154-
sttv1qbb.LANGUAGES = { 'en-US': 'US English',
155-
'pt-BR': 'Portuguese Braziilian',
156-
'en-UK': 'UK English' ,
157-
'fr-FR': 'French',
158-
'zh-CN': 'Mandarin',
159-
'es-ES': 'Spanish',
160-
'ar-AR': 'Arablic',
161-
'ja-JP': 'Japanese'
162-
};
163-
164179
// Function to be used at the start, as don't want to expose any fields, unless the models are
165180
// available. The models can only be fetched if the credentials are available.
166181
sttv1qbb.hideEverything = function () {
@@ -173,6 +188,7 @@
173188
$('input#node-input-stt-custom-model-description').parent().hide();
174189
$('input#node-input-stt-custom-id').parent().hide();
175190
$('input#node-input-stt-corpus-name').parent().hide();
191+
$('input#node-input-stt-allow-overwrite').parent().hide();
176192
}
177193

178194
sttv1qbb.showSelectedFields = function(fields) {
@@ -203,12 +219,15 @@
203219
case 'getCustomisation':
204220
case 'getCorpora':
205221
case 'train':
222+
case 'listCustomWords':
223+
case 'addWords':
206224
fields.push('#node-input-stt-custom-id');
207225
break;
208226
case 'addCorpus':
209227
case 'deleteCorpus':
210228
fields.push('#node-input-stt-custom-id'
211-
+ ', #node-input-stt-corpus-name');
229+
+ ', #node-input-stt-corpus-name'
230+
+ ', #node-input-stt-allow-overwrite');
212231
break;
213232
}
214233
sttv1qbb.showSelectedFields(fields);
@@ -366,7 +385,8 @@
366385
'base-model-hidden' : {value: ''},
367386
'stt-custom-model-description' : {value: ''},
368387
'stt-custom-id' : {value: ''},
369-
'stt-corpus-name' : {value: ''}
388+
'stt-corpus-name' : {value: ''},
389+
'stt-allow-overwrite' : {value: false}
370390
},
371391
credentials: {
372392
username: {type:'text'} //,

services/speech_to_text/v1-corpus-builder.js

+67-5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,31 @@ module.exports = function (RED) {
125125
});
126126
}
127127

128+
function executeGetCustomWords(node, stt, params, msg) {
129+
stt.getWords(params, function (err, response) {
130+
node.status({});
131+
if (err) {
132+
reportError(node, msg, err);
133+
} else {
134+
msg['words'] = response.words ? response.words : response ;
135+
}
136+
node.send(msg);
137+
});
138+
}
139+
140+
function executeAddWords(node, stt, params, msg) {
141+
stt.addWords(params, function (err, response) {
142+
node.status({});
143+
if (err) {
144+
reportError(node, msg, err);
145+
} else {
146+
msg['addwordsresponse'] = response ;
147+
}
148+
node.send(msg);
149+
});
150+
}
151+
152+
128153
function executeDeleteCorpus(node, stt, params, msg) {
129154
stt.deleteCorpus(params, function (err, response) {
130155
node.status({});
@@ -164,6 +189,12 @@ module.exports = function (RED) {
164189
case 'train':
165190
executeTrain(node, stt, params, msg);
166191
break;
192+
case 'listCustomWords':
193+
executeGetCustomWords(node, stt, params, msg);
194+
break;
195+
case 'addWords':
196+
executeAddWords(node, stt, params, msg);
197+
break;
167198
case 'deleteCorpus':
168199
executeDeleteCorpus(node, stt, params, msg);
169200
break;
@@ -189,10 +220,25 @@ module.exports = function (RED) {
189220
params['customization_id'] = config['stt-custom-id'];
190221
}
191222

223+
if ('addCorpus' === config['stt-custom-mode']) {
224+
params['allow_overwrite'] = config['stt-allow-overwrite'];
225+
}
226+
192227
return params;
193228
}
194229

195-
function loadCorpusFile(node, method, params, msg) {
230+
function setFileParams(method, params, msg) {
231+
switch (method) {
232+
case 'addCorpus':
233+
params.corpus = msg.payload;
234+
break;
235+
case 'addWords':
236+
params.words = msg.payload;
237+
break;
238+
}
239+
}
240+
241+
function loadFile(node, method, params, msg) {
196242
temp.open({
197243
suffix: '.txt'
198244
}, function(err, info) {
@@ -217,15 +263,28 @@ module.exports = function (RED) {
217263
throw err;
218264
}
219265

220-
params.corpus = fs.createReadStream(info.path);
266+
switch (method) {
267+
case 'addCorpus':
268+
params.corpus = fs.createReadStream(info.path);
269+
break;
270+
case 'addWords':
271+
try {
272+
params.words = JSON.parse(fs.readFileSync(info.path, 'utf8'));
273+
} catch (err) {
274+
params.words = fs.createReadStream(info.path);
275+
}
276+
}
277+
221278
executeMethod(node, method, params, msg);
279+
temp.cleanup();
222280
});
223281
});
224282
}
225283

226284
function checkForFile(method) {
227285
switch (method) {
228286
case 'addCorpus':
287+
case 'addWords':
229288
return true;
230289
}
231290
return false;
@@ -286,11 +345,14 @@ module.exports = function (RED) {
286345
}
287346

288347
if (checkForFile(method)) {
289-
loadCorpusFile(node, method, params, msg);
290-
} else {
291-
executeMethod(node, method, params, msg);
348+
if (msg.payload instanceof Buffer) {
349+
loadFile(node, method, params, msg);
350+
return;
351+
}
352+
setFileParams(method, params, msg);
292353
}
293354

355+
executeMethod(node, method, params, msg);
294356
});
295357
}
296358

0 commit comments

Comments
 (0)