Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 可以使用麦克风录制一次声音,但不能再次启动麦克风_Java_Audio_Cmusphinx_Sphinx4 - Fatal编程技术网

Java 可以使用麦克风录制一次声音,但不能再次启动麦克风

Java 可以使用麦克风录制一次声音,但不能再次启动麦克风,java,audio,cmusphinx,sphinx4,Java,Audio,Cmusphinx,Sphinx4,我正在使用CMU sphinx库录制声音。开始java应用程序时,我只分配识别器和配置管理器一次,如下所示: cm = new ConfigurationManager(soundPart.class.getResource("hellongram.config.xml")); recognizer = (Recognizer) cm.lookup("recognizer"); recognizer.allocate(); 此外,我的应用程序中有

我正在使用CMU sphinx库录制声音。开始java应用程序时,我只分配识别器和配置管理器一次,如下所示:

        cm = new ConfigurationManager(soundPart.class.getResource("hellongram.config.xml"));
        recognizer = (Recognizer) cm.lookup("recognizer");
        recognizer.allocate();
此外,我的应用程序中有一个录制声音按钮。当用户单击它时,我使用以下代码录制声音:

    Microphone microphone = (Microphone)MR.sp.cm.lookup("microphone");
    if (!microphone.startRecording()) {
        System.out.println("Cannot start microphone.");
        MR.sp.recognizer.deallocate();

        System.exit(1);
    }
    //MR.sp.pleaseStartSpeaking.setVisible(true);
    while(true){
    Result result = MR.sp.recognizer.recognize();
    if(result!=null){
        String resultText = result.getBestFinalResultNoFiller();
        MR.sp.lblYouSearched.setVisible(true);
        MR.sp.lblNewLabel.setVisible(true);
        MR.sp.lblNewLabel.setText(resultText);
        MR.textQuery = resultText.toLowerCase();
        break;
    }
    }

我第一次这么做就行了。但是,如果用户第二次单击录制按钮,则会抛出无法启动麦克风的错误。我在这里做错了什么。为什么我不能第二次获取麦克风

您可能希望查看麦克风的录制线程,并重新阅读获取该代码的页面,因为您使用的代码与您想要执行的代码之间的区别在于,您使用的代码不会启动和停止麦克风,而是持续录制。一个RecordingThread看起来就是你想要的,因为你可以很容易地调用start和stop来获得你想要的。

你能给我一些示例代码吗。仅仅看文档对我没有多大帮助。在我上面的代码中,每当我想录音时,我都会拿到麦克风。这有什么问题?