Search This Blog

Friday, April 14, 2017

How to use Watson Speech to text API ?

 

Speech to text is offered by Watson on blue mix, today we will see how to quickly setup the environment to use this service.

 

Prerequisites:

  • Eclipse
  • Blue mix account

 

Create a new Java  eclipse project and attach this jar in the build path.

Now create a class file as shown below

 

code

========================

package com.ibm.watson.developer_cloud.discovery.v1;

import java.io.File;

import com.ibm.watson.developer_cloud.speech_to_text.v1.SpeechToText;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechResults;


/**
* Recognize a sample wav file and print the transcript into the console output. Make sure you are using UTF-8 to print
* messages; otherwise, you will see question marks.
*/
public class SpeechToTextExample {

  public static void main(String[] args) {
    SpeechToText service = new SpeechToText();
    service.setUsernameAndPassword("username", "password");

    File audio = new File("src/sample1.wav");
    SpeechResults transcript = service.recognize(audio).execute();

    System.out.println(transcript);
  }
}

 

 

=======================================================================

 

Username and password you can get from blue mix account , by creating a new instance of the service –> add credential

 

 

Now put a sample wav file in the source folder of your eclipse project and run it.

 

image

 

 

Copy paste the wav and source for this speech to text demo from this github url.

 

 

image

 

The JAR attached has the java-sdk for watson and can be used to call any of the services hosted on blue mix.

 

Keep Reading !

 

Action Item : Subscribe & Share !

No comments:

Post a Comment