【问题标题】:Decode JSON output in Watson Speech to Text在 Watson Speech to Text 中解码 JSON 输出
【发布时间】:2017-01-31 12:16:57
【问题描述】:

我目前正在使用 Watsons 强大的语音转文本 API,它在麦克风输入上返回 JSON(?)。

这是返回 JSON 文件的代码的一部分:

service.recognizeUsingWebSocket(audio, options, new BaseRecognizeCallback() {
      @Override
      public void onTranscription(SpeechResults speechResults) { 
          System.out.println(speechResults);
      }
    }); 

我目前正在尝试做的是获取 SpeechResults json 的“成绩单”部分(参见输出),但它似乎不适用于使用 json 解析器的典型 json 描述,因为 SpeechResults不是字符串。

你们有任何想法如何实现这一点吗?

这是输出:

{
  "result_index": 0,
  "results": [
    {
      "final": true,
      "alternatives": [
        {
          "confidence": 0.908,
          "timestamps": [
            [
              "are",
              0.03,
              0.2
            ],
            [
              "you",
              0.2,
              0.36
            ]
          ],
          "transcript": "are you ",
          "word_confidence": [
            [
              "are",
              0.838
            ],
            [
              "you",
              0.982
            ]
          ]
        }
      ]
    }
  ]
}

【问题讨论】:

    标签: java json ibm-watson watson


    【解决方案1】:

    您必须分解整个对象才能到达条目数组。

    假设 SpeechResults 已经是一个解析的 JSONObject。

    SpeechResults.getJSONObject("results").getJSONArray("transcript");
    

    示例一:

    //By using javasript json parser
    var json = SpeechResults.results; 
    System.out.println(json.transcript)
    

    示例二:

            String jsonStr = SpeechResults;
            JSONObject jsonObj = new JSONObject(jsonStr);
            String transcript = jsonObj.getString("transcript");
            System.out.println(transcript);
    

    【讨论】:

      猜你喜欢
      • 2016-05-08
      • 2017-07-28
      • 1970-01-01
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多