最大限度地减少天蓝色语音到文本判断是否没有检测到语音所需的时间

问题描述

我有这个代码,我想问一下是否有办法让我在大约 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 (将#修改为@)