Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSGF Engine #97

Open
roddar92 opened this issue Jan 14, 2020 · 1 comment
Open

JSGF Engine #97

roddar92 opened this issue Jan 14, 2020 · 1 comment

Comments

@roddar92
Copy link

Dear colleagues,
I tried to start JSGF from Sphinx4 library. But I can't find a good demo with grammars and queries to check how it works.

Could you suggest me any instructions for launching JSGF engine?

Regards,
Daria

@SwimmingTiger
Copy link

SwimmingTiger commented Apr 17, 2021

Here is a demo about JSGF:

public static void main(String[] args) throws Exception {
Configuration configuration = new Configuration();
configuration.setAcousticModelPath(ACOUSTIC_MODEL);
configuration.setDictionaryPath(DICTIONARY_PATH);
configuration.setGrammarPath(GRAMMAR_PATH);
configuration.setUseGrammar(true);
configuration.setGrammarName("dialog");
LiveSpeechRecognizer jsgfRecognizer =
new LiveSpeechRecognizer(configuration);
configuration.setGrammarName("digits.grxml");
LiveSpeechRecognizer grxmlRecognizer =
new LiveSpeechRecognizer(configuration);
configuration.setUseGrammar(false);
configuration.setLanguageModelPath(LANGUAGE_MODEL);
LiveSpeechRecognizer lmRecognizer =
new LiveSpeechRecognizer(configuration);
jsgfRecognizer.startRecognition(true);
while (true) {
System.out.println("Choose menu item:");
System.out.println("Example: go to the bank account");
System.out.println("Example: exit the program");
System.out.println("Example: weather forecast");
System.out.println("Example: digits\n");
String utterance = jsgfRecognizer.getResult().getHypothesis();
if (utterance.startsWith("exit"))
break;
if (utterance.equals("digits")) {
jsgfRecognizer.stopRecognition();
recognizeDigits(grxmlRecognizer);
jsgfRecognizer.startRecognition(true);
}
if (utterance.equals("bank account")) {
jsgfRecognizer.stopRecognition();
recognizerBankAccount(jsgfRecognizer);
jsgfRecognizer.startRecognition(true);
}
if (utterance.endsWith("weather forecast")) {
jsgfRecognizer.stopRecognition();
recognizeWeather(lmRecognizer);
jsgfRecognizer.startRecognition(true);
}
}
jsgfRecognizer.stopRecognition();
}

The JSGF grammar file it uses:

#JSGF V1.0;
grammar dialog;
<digit> = oh |
zero |
one |
two |
three |
four |
five |
six |
seven |
eight |
nine ;
<number> = <digit>+ [point <digit>+];
<menu_command> = digits |
[go to [the]] bank account |
weather forecast |
exit [[the] program] ;
<bank_command> = [show | check] balance |
deposit <number> |
withdraw <number> |
back ;
public <command> = <menu_command> | <bank_command>;

If you are on Windows, you need to edit this file to start the demo:

public class SpeechSourceProvider {
Microphone getMicrophone() {
return new Microphone(16000, 16, true, false);
}
}

// Change the class to this
public class SpeechSourceProvider {
    private static final Microphone mic = new Microphone(16000, 16, true, false);

    Microphone getMicrophone() {
        return mic;
    }
}

See details for the bug:
https://stackoverflow.com/questions/29121188/cant-access-microphone-while-running-dialog-demo-in-sphinx4-5prealpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants