java - Watson STT Java - Websockets Java 和 HTTP POST 之间的不同结果

标签 java api ibm-cloud speech-to-text ibm-watson

我正在尝试构建一个采用流式音频输入(例如:麦克风中的线路)并使用 IBM Bluemix (Watson) 进行语音转文本的应用。

我简要修改了找到的示例 Java 代码 here .此示例发送的是 WAV,但我发送的是 FLAC……这 [应该] 无关紧要。

结果很糟糕,很糟糕。这是我在使用 Java Websockets 代码时得到的:

{
  "result_index": 0,
  "results": [
    {
      "final": true,
      "alternatives": [
        {
          "transcript": "it was six weeks ago today the terror ",
          "confidence": 0.92
        }
      ]
    }
  ]
}

现在,将上面的结果与下面的结果进行比较。这些是发送相同内容但使用 cURL (HTTP POST) 时的结果:

{
   "results": [
  {
     "alternatives": [
        {
           "confidence": 0.945,
           "transcript": "it was six weeks ago today the terrorists attacked the U. S. consulate in Benghazi Libya now we've obtained email alerts that were put out by the state department as the attack unfolded as you know four Americans were killed including ambassador Christopher Stevens "
        }
     ],
     "final": true
  },
  {
     "alternatives": [
        {
           "confidence": 0.942,
           "transcript": "sharyl Attkisson has our story "
        }
     ],
     "final": true
  }
   ],
   "result_index": 0
}

这几乎是完美的结果。

为什么使用 Websockets 时会有所不同?

最佳答案

此问题已在 3.0.0-RC1 版本中修复。

您可以从以下位置获取新 jar :

  1. 专家

    <dependency>
        <groupId>com.ibm.watson.developer_cloud</groupId>
        <artifactId>java-sdk</artifactId>
        <version>3.0.0-RC1</version>
    </dependency>
    
  2. Gradle

    'com.ibm.watson.developer_cloud:java-sdk:3.0.0-RC1'
    
  3. 压缩包

    下载 jar-with-dependencies (~1.4MB)


这是一个如何使用 WebSockets 识别 flac 音频文件的例子

SpeechToText service = new SpeechToText();
service.setUsernameAndPassword("<username>", "<password>");

FileInputStream audio = new FileInputStream("path-to-audio-file.flac");

RecognizeOptions options = new RecognizeOptions.Builder()
  .continuous(true)
  .interimResults(true)
  .contentType(HttpMediaType.AUDIO_FLAC)
  .build();

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

要测试的 FLAC 文件:https://s3.amazonaws.com/mozart-company/tmp/4.flac


注意:3.0.0-RC1 是一个候选版本。我们将在下周发布产品版本 (3.0.1)。

关于java - Watson STT Java - Websockets Java 和 HTTP POST 之间的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36504879/

相关文章:

ibm-cloud - 如何从 IBM Bluemix 中删除组织?

java - 我该如何修复此错误 java.util.ConcurrentModificationException

java - 如何将 jFreeChart 添加到 jFrame 中的 jPanel?

java - java中的itext,不能使用PdfContentByte cb = writer.getDirectContent();

javascript - 如何在 YII2 中将具有单独 API URL 响应的 ajax 返回到 Controller ?

javascript - Node js 错误 : Protocol "https:" not supported. 预期为 "http:"

java - 将单个数组列表项添加到单个图 block

r - httr POST 身份验证错误

django - "non_field_errors": [ "Invalid data. Expected a dictionary, but got list." ] in django rest framework while calling api in postman

docker - 使用容器docker作为CF应用程序的代理来获取公共(public)IP