Skip to content

Commit

Permalink
Merge pull request #246 from chughts/tonefix
Browse files Browse the repository at this point in the history
Migrate Tone Analysis Node to new service detection utility
  • Loading branch information
chughts committed Jan 28, 2017
2 parents 7214c79 + 67221fb commit 6874c0c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 24 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Node-RED Watson Nodes for IBM Bluemix

<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>

### New in version 0.4.39
- Add description to Info panel for Text to Speech Customizations Node
- Tone node updated to use url based services utility to detect bound service.

### New in version 0.4.38
- New Node for Text to Speech Customizations
- Added option to select Customization in Text To Speech Node.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-node-watson",
"version": "0.4.38",
"version": "0.4.39",
"description": "A collection of Node-RED nodes for IBM Watson services",
"dependencies": {
"alchemy-api": "^1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion services/language_translator_identify/v2.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</script>

<script type="text/x-red" data-help-name="watson-language-translator-identify">
<p>Packaged in with release 0.4.38 of node-red-node-watson</p>
<p>Packaged in with release 0.4.39 of node-red-node-watson</p>
<p>The Watson Language Translator service can be used to identify languages used in a text input. <p>
<p>Node input : </p>
<ul>
Expand Down
37 changes: 37 additions & 0 deletions services/text_to_speech/v1-corpus-builder.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,49 @@
<p>The Speech To Text Custom Builder is used to create customisations
for Speech to Text. It supports the following modes </p>
<ul>

<li>Create Custom Language Model
<p>In this mode, a new empty custom model is created. The
new customization id is returned on
<code>msg.customization_id</code>
</p>
</li>

<li>List Customizations
<p> Use this mode to list customizations such as the name and description
for all custom voice models that you own for all languages.
Data is returned on <code>msg.customizations</code>
</p>
</li>

<li>Get Customization
<p> Use this mode to list all information about a specifid
custom voice model. The response includes the words in the model
and their translations as defined in the model.
Data is returned on <code>msg.customization</code>
</p>
</li>

<li>Add Words
<p> Adds one or more words and their translations to the
specified custom voice model. The input corpus content should be
provided as buffer or JSoN Array of Words on
<code>msg.payload</code>
</p>
</li>

<li>Get Words
<p> Lists all of the words and their translations for the specified
custom voice model.
Data is returned on <code>msg.words</code>
</p>
</li>

<li>Delete Word
<p> Deletes a single word from the specified custom voice model.
</p>
</li>

</ul>

<p>For more information about Speech To Text customisation,
Expand Down
42 changes: 20 additions & 22 deletions services/tone_analyzer/v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,28 @@
**/

module.exports = function (RED) {
var watson = require('watson-developer-cloud');
var cfenv = require('cfenv');
var toneutils = require('../../utilities/tone-utils');

// Require the Cloud Foundry Module to pull credentials from bound service
// If they are found then they are stored in sUsername and sPassword, as the
// service credentials. This separation from sUsername and username to allow
const SERVICE_IDENTIFIER = 'tone-analyzer';
var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3'),
serviceutils = require('../../utilities/service-utils'),
toneutils = require('../../utilities/tone-utils'),
username = '', password = '', sUsername = '', sPassword = '',
service = null;

// Require the Cloud Foundry Module to pull credentials from bound service
// If they are found then they are stored in sUsername and sPassword, as the
// service credentials. This separation from sUsername and username to allow
// the end user to modify the node credentials when the service is not bound.
// Otherwise, once set username would never get reset, resulting in a frustrated
// user who, when he errenously enters bad credentials, can't figure out why
// the edited ones are not being taken.

// Not ever used, and codeacy complains about it.

var username, password, sUsername, sPassword;

var service = cfenv.getAppEnv().getServiceCreds(/tone analyzer/i)
service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER);

if (service) {
sUsername = service.username;
sPassword = service.password;
}


// Node RED Admin - fetch and set vcap services
RED.httpAdmin.get('/watson-tone-analyzer/vcap', function (req, res) {
res.json(service ? {bound_service: true} : null);
Expand All @@ -51,7 +49,7 @@ module.exports = function (RED) {
var taSettings = null;

username = sUsername || credentials.username;
password = sPassword || credentials.password;
password = sPassword || credentials.password;

if (username && password) {
taSettings = {};
Expand All @@ -66,7 +64,7 @@ module.exports = function (RED) {
// Function that checks the configuration to make sure that credentials,
// payload and options have been provied in the correct format.
var checkConfiguration = function(msg, node, cb) {
var message = null;
var message = null;
var taSettings = null;

taSettings = checkCreds(node.credentials);
Expand All @@ -85,24 +83,24 @@ module.exports = function (RED) {
};


// function when the node recieves input inside a flow.
// function when the node recieves input inside a flow.
// Configuration is first checked before the service is invoked.
var processOnInput = function(msg, config, node) {
checkConfiguration (msg, node, function(err, settings){
if (err) {
node.status({fill:'red', shape:'dot', text:err});
node.status({fill:'red', shape:'dot', text:err});
node.error(err, msg);
return;
} else {
var tone_analyzer = watson.tone_analyzer({

var tone_analyzer = new ToneAnalyzerV3({
'username': settings.username,
'password': settings.password,
'version': 'v3',
'version_date': '2016-05-19'
version_date: '2016-05-19'
});

var options = toneutils.parseOptions(msg, config);

node.status({fill:'blue', shape:'dot', text:'requesting'});
tone_analyzer.tone(options, function (err, response) {
node.status({})
Expand All @@ -120,7 +118,7 @@ module.exports = function (RED) {
};


// This is the Tone Analyzer Node.
// This is the Tone Analyzer Node.
function Node (config) {
RED.nodes.createNode(this, config);
var node = this;
Expand Down

0 comments on commit 6874c0c

Please sign in to comment.