Skip to content

Commit 7ee699c

Browse files
authored
Merge pull request #198 from chughts/ttsfix
Namespace fix in HTML for TTS Node
2 parents 6cacc24 + f87350b commit 7ee699c

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ 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+
11+
### New in version 0.4.18
12+
- Name space fixes to Text to Speech Node
13+
1014
### New in version 0.4.17
1115
- Fixed how Document Conversion node was handling docx files
1216

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.17",
3+
"version": "0.4.18",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"alchemy-api": "^1.3.0",

services/text_to_speech/v1.html

+41-35
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,21 @@
9898
'ja-JP': 'Japanese'
9999
};
100100

101+
// sorting functions
102+
tts.onlyUnique = function (value, index, self) {
103+
return self.indexOf(value) === index;
104+
}
105+
101106
// Called to complete the languages selection table
102-
function processLanguages() {
107+
tts.processLanguages = function () {
103108
if (!tts.languages && tts.voices) {
104109
tts.languages = tts.voices.map(function(m) {
105110
return m.language;
106111
});
107112
}
108113
if (tts.languages) {
109114
$('select#node-input-lang').empty();
110-
var unique_langs = tts.languages.filter(onlyUnique);
115+
var unique_langs = tts.languages.filter(tts.onlyUnique);
111116

112117
unique_langs.forEach(function(l) {
113118
var selectedText = '';
@@ -127,13 +132,13 @@
127132
}
128133

129134
// Populate the Voices selection field
130-
function populateVoices() {
135+
tts.populateVoices = function () {
131136
if (!tts.voicenames && tts.voices) {
132137
tts.voicenames = tts.voices.map(function(m) {
133138
//return m.name.split('_')[1];
134139
return m.name;
135140
});
136-
var unique_voices = tts.voicenames.filter(onlyUnique);
141+
var unique_voices = tts.voicenames.filter(tts.onlyUnique);
137142
tts.voicenames = unique_voices;
138143
}
139144
if (!tts.voicedata && tts.voicenames){
@@ -171,14 +176,14 @@
171176

172177

173178
// Called to work through the voices, completing the dyanmic selection fields.
174-
function processVoices() {
179+
tts.processVoices = function () {
175180
if (tts.voices) {
176-
processLanguages();
177-
populateVoices();
181+
tts.processLanguages();
182+
tts.populateVoices();
178183
}
179184
}
180185

181-
function visibilityCheck()
186+
tts.visibilityCheck = function ()
182187
{
183188
if (tts.voices) {
184189
$('label#node-label-message').parent().hide();
@@ -194,14 +199,14 @@
194199

195200
// Function called when either when the voices have been retrieved, or
196201
// on dialog load, if the voices has already been retrieved
197-
function postVoiceCheck(){
198-
processVoices();
199-
visibilityCheck();
202+
tts.postVoiceCheck = function (){
203+
tts.processVoices();
204+
tts.visibilityCheck();
200205
}
201206

202207
// Retrieve the available voices from the server, if data is returned, then
203208
// can enable the dynamic selection fields.
204-
function getVoices(){
209+
tts.getVoices = function (){
205210
var u = $('#node-input-username').val();
206211
var p = $('#node-input-password').val();
207212

@@ -211,7 +216,7 @@
211216
$('label#node-label-message').text(data.error);
212217
} else if (data.voices) {
213218
tts.voices = data.voices;
214-
postVoiceCheck();
219+
tts.postVoiceCheck();
215220
}
216221
}).fail(function (err) {
217222
$('label#node-label-message').parent().show();
@@ -226,7 +231,7 @@
226231
// restart, the settings for the dynamic fields are lost.
227232
// So hidden (text) fields are being used to squirrel away the values, so that
228233
// they can be restored.
229-
function restoreFromHidden() {
234+
tts.restoreFromHidden = function () {
230235
tts.language_selected = $('#node-input-langhidden').val();
231236
$('select#node-input-lang').val(tts.language_selected);
232237

@@ -236,19 +241,19 @@
236241

237242
// Simple check that is only invoked if the service is not bound into bluemix. In this case the
238243
// user has to provide credentials. Once there are credentials, then the tts.voices are retrieved.
239-
function checkCredentials() {
244+
tts.checkCredentials = function () {
240245
var u = $('#node-input-username').val();
241246
var p = $('#node-input-password').val();
242247

243248
if (u && u.length && p) {
244249
if (!tts.voices) {
245-
getVoices();
250+
tts.getVoices();
246251
}
247252
}
248253
}
249254

250255
// Language Setting has changed, modofy voice options appropriately
251-
function checkLanguage(){
256+
tts.checkLanguage = function (){
252257
//var lang = $('#node-input-lang').val();
253258
//$('#node-input-voice option.' + lang).show();
254259
//$('#node-input-voice option:not(.' + lang + ')').hide();
@@ -259,32 +264,32 @@
259264
}
260265

261266
// Voice Setting has changed, modofy voice options appropriately
262-
function checkVoice(){
267+
tts.checkVoice = function (){
263268
tts.voice_selected = $('#node-input-voice').val();
264269
}
265270

266271

267272
// Register the onchange handlers
268-
function registerHandlers() {
273+
tts.registerHandlers = function () {
269274
$('#node-input-username').change(function(val){
270-
checkCredentials();
275+
tts.checkCredentials();
271276
});
272277
$('#node-input-password').change(function(val){
273-
checkCredentials();
278+
tts.checkCredentials();
274279
});
275280
$('#node-input-lang').change(function () {
276-
checkLanguage();
277-
populateVoices();
281+
tts.checkLanguage();
282+
tts.populateVoices();
278283
});
279284
$('#node-input-voice').change(function () {
280-
checkVoice();
285+
tts.checkVoice();
281286
});
282287

283288
}
284289

285290
// Function to be used at the start, as don't want to expose any fields, unless the models are
286291
// available. The models can only be fetched if the credentials are available.
287-
function hideEverything() {
292+
tts.hideEverything = function () {
288293
if (!stt.models) {
289294
$('label#node-label-message').parent().hide();
290295
$('select#node-input-lang').parent().hide();
@@ -294,17 +299,18 @@
294299

295300
// This is the on edit prepare function, which will be invoked everytime the dialog
296301
// is shown.
297-
function oneditprepare() {
298-
hideEverything();
299-
restoreFromHidden();
300-
registerHandlers();
302+
function ttsoneditprepare() {
303+
console.log('In on Edit Prepare');
304+
tts.hideEverything();
305+
tts.restoreFromHidden();
306+
tts.registerHandlers();
301307

302308
$.getJSON('watson-text-to-speech/vcap/')
303309
.done(function (service) {
304-
restoreFromHidden();
310+
tts.restoreFromHidden();
305311
$('.credentials').toggle(!service);
306-
if (!tts.voices) {getVoices();}
307-
else {postVoiceCheck();}
312+
if (!tts.voices) {tts.getVoices();}
313+
else {tts.postVoiceCheck();}
308314
})
309315
.fail(function () {
310316
$('.credentials').show();
@@ -314,7 +320,7 @@
314320
}
315321

316322
// Save the values in the dyanmic lists to the hidden fields.
317-
function oneditsave(){
323+
function ttsoneditsave(){
318324
$('#node-input-langhidden').val(tts.language_selected);
319325
$('#node-input-voicehidden').val(tts.voice_selected);
320326
}
@@ -346,8 +352,8 @@
346352
labelStyle: function() {
347353
return this.name ? "node_label_italic" : "";
348354
},
349-
oneditsave: oneditsave,
350-
oneditprepare: oneditprepare
355+
oneditsave: ttsoneditsave,
356+
oneditprepare: ttsoneditprepare
351357
});
352358
})();
353359
</script>

0 commit comments

Comments
 (0)