15
15
**/
16
16
17
17
module . exports = function ( RED ) {
18
+ const SERVICE_IDENTIFIER = 'text-to-speech' ;
18
19
var cfenv = require ( 'cfenv' ) ;
19
- var watson = require ( 'watson-developer-cloud' ) ;
20
+ var TextToSpeechV1 = require ( 'watson-developer-cloud/text-to-speech/v1' ) ;
21
+ var serviceutils = require ( '../../utilities/service-utils' ) ;
20
22
21
23
// Require the Cloud Foundry Module to pull credentials from bound service
22
24
// If they are found then the username and password will be stored in
@@ -30,7 +32,8 @@ module.exports = function(RED) {
30
32
31
33
var username , password , sUsername , sPassword ;
32
34
33
- var service = cfenv . getAppEnv ( ) . getServiceCreds ( / t e x t t o s p e e c h / i)
35
+ //var service = cfenv.getAppEnv().getServiceCreds(/text to speech/i)
36
+ var service = serviceutils . getServiceCreds ( SERVICE_IDENTIFIER ) ;
34
37
35
38
if ( service ) {
36
39
sUsername = service . username ;
@@ -44,11 +47,9 @@ module.exports = function(RED) {
44
47
45
48
// API used by widget to fetch available models
46
49
RED . httpAdmin . get ( '/watson-text-to-speech/voices' , function ( req , res ) {
47
- var tts = watson . text_to_speech ( {
50
+ var tts = new TextToSpeechV1 ( {
48
51
username : sUsername ? sUsername : req . query . un ,
49
- password : sPassword ? sPassword : req . query . pwd ,
50
- version : 'v1' ,
51
- url : 'https://stream.watsonplatform.net/text-to-speech/api'
52
+ password : sPassword ? sPassword : req . query . pwd
52
53
} ) ;
53
54
54
55
tts . voices ( { } , function ( err , voices ) {
@@ -75,19 +76,17 @@ module.exports = function(RED) {
75
76
}
76
77
77
78
username = sUsername || this . credentials . username ;
78
- password = sPassword || this . credentials . password || config . password ;
79
+ password = sPassword || this . credentials . password || config . password ;
79
80
80
81
if ( ! username || ! password ) {
81
82
var message = 'Missing Speech To Text service credentials' ;
82
83
node . error ( message , msg ) ;
83
84
return ;
84
85
}
85
86
86
- var text_to_speech = watson . text_to_speech ( {
87
+ var text_to_speech = new TextToSpeechV1 ( {
87
88
username : username ,
88
- password : password ,
89
- version : 'v1' ,
90
- url : 'https://stream.watsonplatform.net/text-to-speech/api'
89
+ password : password
91
90
} ) ;
92
91
93
92
var params = {
0 commit comments