如何解决最大限度地减少天蓝色语音到文本判断是否没有检测到语音所需的时间
我有这个代码,我想问一下是否有办法让我在大约 2 或 3 秒内不说任何话时,打印一条语句,例如“未检测到任何内容”。
代码需要大约 16 秒来识别我是否没有说 smth,我想问一下是否有办法改变它。
public static long fromMicContinouse(SpeechConfig speechConfig) throws InterruptedException,ExecutionException {
long timeStart = System.nanoTime();
AudioConfig audioConfig = AudioConfig.fromDefaultMicrophoneinput();
SpeechRecognizer recognizer = new SpeechRecognizer(speechConfig,audioConfig);
// First initialize the semaphore.
Semaphore stopTranslationWithFileSemaphore = new Semaphore(0);
recognizer.recognizing.addEventListener((s,e) -> {
System.out.println(e.getResult().getText());
});
recognizer.recognized.addEventListener((s,e) -> {
if (e.getResult().getReason() == ResultReason.RecognizedSpeech) {
System.out.println(e.getResult().getText());
} else if (e.getResult().getReason() == ResultReason.NoMatch) {
System.out.println("NOMATCH: Speech Could not be recognized.");
long timeEnd = System.nanoTime();
System.out.println("Took: " + (timeEnd - timeStart));
}
});
recognizer.canceled.addEventListener((s,e) ->
{
System.out.println("CANCELED: Reason=" + e.getReason());
if (e.getReason() == CancellationReason.Error) {
System.out.println("CANCELED: ErrorCode=" + e.getErrorCode());
System.out.println("CANCELED: ErrorDetails=" + e.getErrorDetails());
System.out.println("CANCELED: Did you update the subscription info?");
}
stopTranslationWithFileSemaphore.release();
});
recognizer.sessionStopped.addEventListener((s,e) -> {
System.out.println("\n Session stopped event.");
stopTranslationWithFileSemaphore.release();
});
recognizer.startContinuousRecognitionAsync().get();
stopTranslationWithFileSemaphore.acquire();
return timeEnd - timeStart;
}
我可以看到,只要我说出来,单词就会直接打印出来,但是如果我在 16 秒内什么也没说,那么它会打印“NOMATCH:无法识别语音”。这对于识别器来说是很长的时间,以了解是否或是否没有说什么。
我在问是否有办法,所以如果我说 smth 它会直接打印它,如果它没有检测到有 2 秒的语音来打印“未检测到”或打印 ("--- --") 没有任何延迟。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。