Search This Blog

Friday, April 14, 2017

How to use IBM Watson Text to Speech API via JAVA SDK


I was trying to see how text can be converted to speech using WATSON API, but due to some or the other reasons I was getting a few errors while trying to test locally as well as on blue mix.


I followed this link to set up the app.
https://github.com/watson-developer-cloud/text-to-speech-java

I could deploy but I was getting some error while testing the text to speech feature.
For local it gave me error on
./target/wlp/bin/bluemixUtility import text-to-speech-service
Some null pointer exception.

For Blue mix
Error while processing in red color on the results section of my page.


Finally I had to understand the complete code and I got to know that credentials are not submitted properly to the service from the local system and cloud was not able to bind to the service and was giving “Unknown service exception)


The following setup worked for me, try this.
Step 1
> mvn install

and it created the target folder and it  has a liberty run time with it.
image




Step 2
Configure the liberty server as a new server from the window and give path of the wlp folder shown above.
It will create a liberty profile.

Step 3

Create a text to speech service manually in the blue mix and note down the Username and Password.

Enter the below line just below the service constructor in the DemoServlet.java

Code
=================================================
  TextToSpeech textService = new TextToSpeech();
                  textService.setUsernameAndPassword("username", "password");
=============================================

Execute the maven install again, it will rebuild the war.
> mvn install

Step 4
Import the war in Eclipse and run it on the liberty as shown below.
text to speech api watson how to

Step 4 Open http://localhost:9080/text-to-speech-1.0-SNAPSHOT/

watson text to speech ibm working

Well there can be other ways also for this, but this one will get you working in no time and I thought it might help some one.

Keep Reading !

No comments:

Post a Comment