1

I was wondering how to add custom keywords to voice recognition using sphinx 4 in Java using the GRAM file?

Like: public = (set song);

How would I make this so after 'set song' the user could say anything he wants and it would still get parsed?

        URL url = LulzSpeech.class.getResource("lulzspeech.config.xml");;

        System.out.println("Loading input...");

        ConfigurationManager cm = new ConfigurationManager(url);

        Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
        Microphone microphone = (Microphone) cm.lookup("microphone");

        recognizer.allocate();

        if (microphone.startRecording()) {

            System.out.println("Loading input completed, mic working, ready!");

            try{
            while (true) {
                Thread.sleep(50);

                Result result = recognizer.recognize();

                if (result != null)
                    if(result.getBestFinalResultNoFiller().toLowerCase().contains(MainLulz.programName.toLowerCase()))
                        MainLulz.mainVoiceHandler.handleInput(result.getBestFinalResultNoFiller());
            }
            }catch(Exception e){
                e.printStackTrace();
            }
        } else {
            System.out.println("Cannot start microphone.");
            recognizer.deallocate();
            System.exit(1);
        }
    } catch (IOException e) {
        System.err.println("Problem when loading LulzSpeech input: " + e);
        e.printStackTrace();
    } catch (PropertyException e) {
        System.err.println("Problem configuring LulzSpeech input: " + e);
        e.printStackTrace();
    } catch (InstantiationException e) {
        System.err.println("Problem creating LulzSpeech input: " + e);
        e.printStackTrace();
    }
TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
  • what do you mean by "the user could say anything he wants and it would still get parsed?" can you please provide example? – Abubakkar Oct 03 '12 at 03:57
  • Such as: "find file " and then the user can say whatever he wants, and it will find that file. So like "find file data dot text" but I shouldn't need to put every file in my system into the GRAM file. – user1715880 Oct 03 '12 at 18:42

1 Answers1

0

Keyword detection is not implemented feature in a current version of Sphinx-4. You can not detect keywords easily.

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87