我正在尝试使用Watson Developer Cloud java SDK来转录大型音频文件。我尝试了Sessionless方法并且工作正常,但是当我尝试使用WebSockets方法时,事情变得不可靠。
大多数情况下,该方法只返回没有SpeechResult
传递给代理人;很少有效,但它只能转录前几秒。
这就是我的代码:
static SpeechResults transcript = null;
private static String SpeechToText(String audioFile) throws FileNotFoundException {
SpeechToText service = new SpeechToText();
service.setUsernameAndPassword("<!!USERNAME!!>", "<!!PASSWORD!!>");
service.setEndPoint("https://stream.watsonplatform.net/speech-to-text/api");
RecognizeOptions options = new RecognizeOptions();
options.contentType("audio/ogg;codecs=opus");
options.continuous(Boolean.TRUE);
options.inactivityTimeout(-1);
options.model(Models.GetModelName(Models.SpeechModelEnums.ArabicBroadband));
options.timestamps(Boolean.TRUE);
options.wordAlternativesThreshold(0.5);
options.wordConfidence(Boolean.TRUE);
options.interimResults(Boolean.FALSE);
File audio = new File(audioFile);
//This is my sessionless call
//SpeechResults transcript = service.recognize(audio, options);
service.recognizeUsingWebSockets(new FileInputStream(audio), options, new BaseRecognizeDelegate()
{
@Override
public void onMessage(SpeechResults speechResults){
System.out.println(speechResults);
}
}
);
return "";//transcript.toString();
}
我已连续启用。我试图摆弄interimResults但是没有用。
我做错了什么?