Java IBM Watson TextToSpeech示例不接受音频作为contentType
正在尝试运行IBM Watson SpeechToText Java SDK提供的RecognitizeUsingWebSocketsExample,但无法为分发版提供的示例.wav文件创建有效的RecognitizeOptions对象:Java IBM Watson TextToSpeech示例不接受音频作为contentType,java,speech-to-text,ibm-watson,Java,Speech To Text,Ibm Watson,正在尝试运行IBM Watson SpeechToText Java SDK提供的RecognitizeUsingWebSocketsExample,但无法为分发版提供的示例.wav文件创建有效的RecognitizeOptions对象: Exception in thread "main" java.lang.IllegalArgumentException: When using PCM the audio rate should be specified. at com.ibm.watso
Exception in thread "main" java.lang.IllegalArgumentException: When using PCM the audio rate should be specified.
at com.ibm.watson.developer_cloud.util.Validator.isTrue(Validator.java:38)
at com.ibm.watson.developer_cloud.speech_to_text.v1.RecognizeOptions$Builder.contentType(RecognizeOptions.java:95)
at com.ibm.watson.developer_cloud.speech_to_text.v1.RecognizeUsingWebSocketsExample.main(RecognizeUsingWebSocketsExample.java:30)
似乎contentType(HttpMediaType.AUDIO_WAV)被误解为RAW。以下是实际的(未修改自发行版)代码:
package com.ibm.watson.developer_cloud.speech_to_text.v1;
导入java.io.FileInputStream;
导入java.io.FileNotFoundException;
导入java.util.concurrent.CountDownLatch;
导入java.util.concurrent.TimeUnit;
导入com.ibm.watson.developer_cloud.http.HttpMediaType;
将com.ibm.watson.developer_cloud.speech_导入到_text.v1.model.SpeechResults;
将com.ibm.watson.developer_cloud.speech_导入_text.v1.websocket.BaseRecognizeCallback;
/**
*使用WebSockets识别示例wav文件并将成绩单打印到控制台输出中。
*/
使用WebSocketsExample识别公共类{
专用静态倒计时锁=新倒计时锁(1);
公共静态void main(字符串[]args)抛出FileNotFoundException、InterruptedException{
SpeechToText服务=新建SpeechToText();
service.setUserName和密码(“,”);
FileInputStream音频=新的FileInputStream(“src/test/resources/speech_to_text/sample1.wav”);
RecognizeOptions=newrecognizeoptions.Builder()
.连续(真)
.interimResults(真)
.contentType(HttpMediaType.AUDIO_WAV)
.build();
service.recognizeUsingWebSocket(音频、选项、新BaseRecognitizeCallback(){
@凌驾
公开无效的onTranscription(SpeechResults SpeechResults){
System.out.println(speechResults);
if(speechResults.isFinal())
锁。倒计时();
}
});
锁定。等待(1,时间单位。分钟);
}
}
我使用的是3.0.0-RC2快照。运行不使用识别选项的示例(如SpeechToTextExample)时没有问题。Thx
-rg对不起,虚惊一场。我从头开始重新创建了这个示例项目,它编译和运行都很顺利。我的Eclipse设置一定有些奇怪
package com.ibm.watson.developer_cloud.speech_to_text.v1;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import com.ibm.watson.developer_cloud.http.HttpMediaType;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechResults;
import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.BaseRecognizeCallback;
/**
* Recognize using WebSockets a sample wav file and print the transcript into the console output.
*/
public class RecognizeUsingWebSocketsExample {
private static CountDownLatch lock = new CountDownLatch(1);
public static void main(String[] args) throws FileNotFoundException, InterruptedException {
SpeechToText service = new SpeechToText();
service.setUsernameAndPassword("<username>", "<password>");
FileInputStream audio = new FileInputStream("src/test/resources/speech_to_text/sample1.wav");
RecognizeOptions options = new RecognizeOptions.Builder()
.continuous(true)
.interimResults(true)
.contentType(HttpMediaType.AUDIO_WAV)
.build();
service.recognizeUsingWebSocket(audio, options, new BaseRecognizeCallback() {
@Override
public void onTranscription(SpeechResults speechResults) {
System.out.println(speechResults);
if (speechResults.isFinal())
lock.countDown();
}
});
lock.await(1, TimeUnit.MINUTES);