Watson基本使用及环境搭建

1.需要注册一个Bluemix的账号 

https://console.ng.bluemix.net

2.在bluemix中创建一个watson服务,这里以Speech To Text为例,点击查看凭证,账号和密码,供调用api的时候使用


3.https://github.com/watson-developer-cloud/java-sdk 进入这个网址  


点击此处链接,下载jar包。 (此外,也可以选择maven或者gradle进行项目构建,在该网页上均有说明)


4.将jar包导入java项目或者安卓项目  (这里就不作过多解释了)


5.然后就可以开心的写代码了

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

import java.io.File;

public class Main {

    public static void main(String[] args) {
        SpeechToText service = new SpeechToText();
        service.setUsernameAndPassword("这里写你刚刚记录下来的账号", "刚刚记录下的账号的密码");

        File audio = new File("listening.wav");//找的音频文件 一定是wav格式的 小一点  英文的  汉语貌似不行
        SpeechResults transcript = service.recognize(audio).execute();

        System.out.println(transcript);
    }
}

6.执行结果如下

五月 17, 2017 3:53:08 下午 okhttp3.internal.platform.Platform log
信息: --> POST https://stream.watsonplatform.net/speech-to-text/api/v1/recognize http/1.1 (16091214-byte body)
五月 17, 2017 3:53:13 下午 okhttp3.internal.platform.Platform log
信息: <-- 200 OK https://stream.watsonplatform.net/speech-to-text/api/v1/recognize (4750ms, unknown-length body)
{
  "result_index": 0,
  "results": [
    {
      "final": true,
      "alternatives": [
        {
          "confidence": 0.996,
          "transcript": "this test measures your ability to understand conversations and lectures in English "
        }
      ]
    }
  ]
}


Process finished with exit code 0



你可能感兴趣的:(大数据)