[英]IBM Watson Speech to Text using WebSockets
I am trying to use the Watson Developer Cloud java SDK to transcribe large audio files. 我正在尝试使用Watson Developer Cloud java SDK来转录大型音频文件。 I tried the Sessionless method and it works fine, however when I try the WebSockets method things become unreliable. 我尝试了Sessionless方法并且工作正常,但是当我尝试WebSockets方法时,事情变得不可靠。
Most of the time the method will just return with no SpeechResult
passed to the delegates; 大多数情况下,该方法只返回没有将SpeechResult
传递给委托者; rarely it works, but it only transcribes the first couple of seconds. 它很少有效,但它只能转录前几秒。
This is what my code looks like: 这就是我的代码:
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();
}
I have continuous enabled. 我已经连续启用了。 I tried fiddling with interimResults but that did not work. 我试图摆弄interimResults但是没有用。
What am I doing wrong? 我究竟做错了什么?
The issue you are mentioning was fixed in the 3.0.0-RC1
version. 您提到的问题已在3.0.0-RC1
版本中修复。
I've answered a similar question and added a code snippet that recognizes an audio file using WebSockets. 我已经回答了类似的问题,并添加了一个代码片段,可以使用WebSockets识别音频文件。
Starting from the 3.0.0-RC1
there is a WebSocket example in the README . 从3.0.0-RC1
开始, README中有一个WebSocket示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.