Im a beginner at using express and node.js. I am confused on how to use Watson api and I can barely understand the documentations/apis. I just want to be able to try using the watson api to my application. So I will just enumerate what I did and where I got stuck.
So first I executed this at the command line, to get the framework.
express test
Then I did installed the dependencies using this command.
cd test && npm install
Then I installed watson via the command
npm install watson-developer-cloud
Then I placed this code at my app.js file.
var TextToSpeechV1 = require('watson-developer-cloud/text-to-speech/v1');
var fs = require('fs');
var text_to_speech = new TextToSpeechV1({
username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE', (placed my username and password)
password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE'
});
var params = {
text: 'Hello from IBM Watson',
voice: 'en-US_AllisonVoice', // Optional voice
accept: 'audio/wav'
};
// Pipe the synthesized text to a file
text_to_speech.synthesize(params).pipe(fs.createWriteStream('output.wav'));
So I know that means I am creating a Watson object. But I do not know where to go from here. I just want to be able to create a simple text to speech, wherein there is a textbox and a speak button.
a textbox and a speak button.
Do you mean in a web browser? In that case, you probably want to checkout the watson-speech SDK instead of the Node.js one. There's a example at https://github.com/watson-developer-cloud/speech-javascript-sdk/blob/v0.20.0/examples/static/text-to-speech.html that does more or less exactly what you're describing.
(Note that the watson-speech browser SDK still requires some server-side code in Node.js or whatever to generate auth tokens. See https://github.com/watson-developer-cloud/speech-javascript-sdk/tree/v0.20.0/examples)
If you would prefer to do it in Node.js for whatever reason, check out the demo https://text-to-speech-demo.mybluemix.net/ & https://github.com/watson-developer-cloud/text-to-speech-nodejs - the current version uses the Node.js SDK and then sends the audio through Node.js to the browser for playback.
Disclosure: I used to work for IBM Watson and I authored the speech-javascript-sdk and parts of the node-sdk. I no longer work there or have any control over these libraries.