Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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
Multithreading javafx中对多线程的需求_Multithreading_Javafx_Cmusphinx - Fatal编程技术网

Multithreading javafx中对多线程的需求

Multithreading javafx中对多线程的需求,multithreading,javafx,cmusphinx,Multithreading,Javafx,Cmusphinx,我是javafx新手,我有一个问题。我的项目是一个语音浏览器与一些简单的命令,但我有一个问题,在开关。第一个case语句第1行和第3行的命令起作用,但第2行不起作用。但是如果我删除while循环,它工作得很好!我不知道怎么解决这个问题,请帮帮我 这是我的密码 btSpeak.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) {

我是javafx新手,我有一个问题。我的项目是一个语音浏览器与一些简单的命令,但我有一个问题,在开关。第一个case语句第1行和第3行的命令起作用,但第2行不起作用。但是如果我删除while循环,它工作得很好!我不知道怎么解决这个问题,请帮帮我

这是我的密码

btSpeak.setOnAction(new EventHandler<ActionEvent>() {

    @Override
    public void handle(ActionEvent event) {
    new Task<Void>(){
         public Void call(){
        int click=JOptionPane.showConfirmDialog(null, "Bạn đã sẵn sàng trải nghiệm với VoiceCommand chưa", "Speak", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if(click==JOptionPane.YES_OPTION) {
            JOptionPane.showMessageDialog(null, "Start", "Speak", JOptionPane.INFORMATION_MESSAGE);
            // code for voice recognize
            try {
                URL url;
                url = HelloWorld.class.getResource("helloworld.config.xml");
                System.out.println("Loading..."+url.toString());
                ConfigurationManager cm = new ConfigurationManager(url);
                final Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
                Microphone microphone = (Microphone) cm.lookup("microphone");


                /* allocate the resource necessary for the recognizer */
                recognizer.allocate();

                /* the microphone will keep recording until the program exits */



                if (microphone.startRecording())
                {
                    System.out.println("Say: (Leen | Xuoongs| Trais | Phair | DDi |Veef| Dongs-Tab|Mowr-Tab| Noi - Dung| Trang-Chur|Trang-Truoc)") ;


                    System.out.println("Start speaking. Press Ctrl-C to quit.\n");

                    /*
                     * This method will return when the end of speech
                     * is reached. Note that the endpointer will determine
                     * the end of speech.
                     */
                    //   Platform.runLater(new Runnable(){
                    //    public void run(){
                    int i = 0;
                    while(i< 5) {
                        //Thread.this.notifyAll();
                        Result result = recognizer.recognize();
                        if (result != null)
                        {
                            int t = 0;
                            System.out.println("Enter your choise"+ "\n");
                            resultText = result.getBestFinalResultNoFiller();
                            System.out.println("You said: " + resultText + "\n");
                            if(resultText.equals("xuoongs")) {
                                t = 1;
                            } else if(resultText.equals("leen")) {
                                t = 2;
                            }

                            switch(t) {
                            case 1: {
                                JOptionPane.showMessageDialog(null, "xuống");//line 1
                                webEngine.executeScript("window.scrollBy(0,100)");line 2
                                break;// line 3
                            }
                            case 2: {
                                JOptionPane.showMessageDialog(null, "lên");
                                webEngine.executeScript("window.scrollBy(0,-100)");
                                break;
                            }
                            }// end switch
                        }// end if
                    }//end while()
                }// end if
            } catch (PropertyException e) {
                System.err.println("Problem configuring HelloWorld: " + e);
                e.printStackTrace();
            }
        }
     }
     }.run());
    }// end button
});

是的,您需要在单独的线程中运行资源消耗识别过程。目前你还没有这么做。@NikolayShmyrev你能告诉我怎么做吗?因为我试着这么做,但根本不起作用!!!谢谢你!!当然,显示您尝试过的代码,描述什么不起作用,我们将能够帮助您。我在线程任务中设置它,并在Gui代码中运行它。但在案例1中它仍然跳过第2行。第2行永远不会执行,但当我删除while循环时,它工作得很好,我的意思是,第1、2、3行是顺序执行的!!!不,这是错误的,您只需要在线程中运行识别,其余的必须在UI线程中运行。否则,您将在下一次调用时阻止UI更新。