本文整理汇总了Java中edu.cmu.sphinx.jsgf.JSGFGrammar类的典型用法代码示例。如果您正苦于以下问题:Java JSGFGrammar类的具体用法?Java JSGFGrammar怎么用?Java JSGFGrammar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSGFGrammar类属于edu.cmu.sphinx.jsgf包,在下文中一共展示了JSGFGrammar类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initSphinx
import edu.cmu.sphinx.jsgf.JSGFGrammar; //导入依赖的package包/类
/**
* Configures Sphinx so that the mapping procedure can be started.
*/
private void initSphinx()
{
ConfigurationManager configurationManager = VoiceRecognitionInput.createConfigurationManager("speechSynthesis/responses.config.xml");
try {
this.recognizer = (Recognizer) configurationManager.lookup("recognizer");
this.recognizer.allocate();
this.grammar = (JSGFGrammar) configurationManager.lookup("jsgfGrammar");
this.parser = new RuleParser(grammar);
regenerate();
this.recognizer.deallocate();
} catch (PropertyException e) {
System.out.println("Problem configuring: " + e);
}
}
示例2: RuleParser
import edu.cmu.sphinx.jsgf.JSGFGrammar; //导入依赖的package包/类
public RuleParser(JSGFGrammar grammar) {
this.grammar = grammar;
this.num = new NumberParser();
this.jsapiRecognizer = new BaseRecognizer(grammar.getGrammarManager());
try {
jsapiRecognizer.allocate();
} catch (Exception e) {
Logging.logWarning("Recognizer", "allocating jsapi recognizer failed in RuleParser");
}
}
示例3: GrammarTraversal
import edu.cmu.sphinx.jsgf.JSGFGrammar; //导入依赖的package包/类
/**
* Configures Sphinx so that the mapping procedure can be started. This
* should only be done once and not every single time when a particular
* response is being queried in the tags to utterance mapping
*/
public GrammarTraversal(JSGFGrammar g) {
grammar = g;
sentences = new ArrayList<Sentence>();
// start traversing with an empty sentence
timer.schedule(new PrintStatistics(), 0, 500);
traverse(grammar.getInitialNode(), "", "");
timer.cancel();
timer.purge();
System.out.println(count_utterances + " sentences parsed.");
}
示例4: newProperties
import edu.cmu.sphinx.jsgf.JSGFGrammar; //导入依赖的package包/类
@Override
public void newProperties(PropertySheet ps) throws PropertyException {
// logger = ps.getLogger();
grammar = (JSGFGrammar) ps.getComponent(PROP_JSGF_GRAMMAR);
microphone = (Microphone) ps.getComponent(PROP_MICROPHONE);
recognizer = (Recognizer) ps.getComponent(PROP_RECOGNIZER);
}
示例5: getVoiceCommandsAndPhonemes
import edu.cmu.sphinx.jsgf.JSGFGrammar; //导入依赖的package包/类
/**
* Allocates recognizer, grammar and dictionary, gets (random) voice
* commands, looks up phoneme representation in the dictionary
*
* @return
*/
private static ArrayList<String[]> getVoiceCommandsAndPhonemes() {
ConfigurationManager configurationManager = VoiceRecognitionInput.createConfigurationManager("voiceControl/input/input.config.xml");
Recognizer recognizer = (Recognizer) configurationManager
.lookup("recognizer");
recognizer.allocate();
JSGFGrammar grammar = (JSGFGrammar) configurationManager
.lookup("jsgfGrammar");
Dictionary dictionary = (Dictionary) configurationManager
.lookup("dictionary");
// Get possible voice commands
ArrayList<String> cmds = new ArrayList<String>();
for (int i = 0; i < 80; i++) {
String s = grammar.getRandomSentence();
if (!cmds.contains(s)) {
cmds.add(s);
}
}
// Get phoneme representation for every command
ArrayList<String[]> commandWithPhonemeRepresentation = new ArrayList<String[]>();
for (String cmd : cmds) {
StringBuilder sb = new StringBuilder();
String[] words = cmd.split(" ");
for (String word : words) {
String[] wordPhon = dictionary.getWord(word)
.getMostLikelyPronunciation().toString()
.split("\\(|\\)");
sb.append(arpabetToIPA(wordPhon[1]) + " ");
}
commandWithPhonemeRepresentation.add(new String[] { cmd,
sb.toString() });
}
recognizer.deallocate();
return commandWithPhonemeRepresentation;
}
示例6: GrammarDump
import edu.cmu.sphinx.jsgf.JSGFGrammar; //导入依赖的package包/类
public GrammarDump(JSGFGrammar grammar) {
this.grammar = grammar;
}
示例7: expandGrammar
import edu.cmu.sphinx.jsgf.JSGFGrammar; //导入依赖的package包/类
public String[] expandGrammar(String grammarPath, String grammarName, boolean random) throws Exception {
URL dictionaryUrl = getClass().getResource("/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
URL noisedictUrl = getClass().getResource("/edu/cmu/sphinx/models/en-us/en-us/noisedict");
Dictionary dictionary = new TextDictionary(
dictionaryUrl,
noisedictUrl,
null,
null,
new UnitManager()
);
dictionary.allocate();
try {
JSGFGrammar grammar = new JSGFGrammar(
grammarPath, grammarName,
true,
true,
true,
true,
dictionary
);
grammar.commitChanges();
String[] utterances;
if (random) {
int number = 100;
utterances = new String[number];
for (int i = 0; i < number; i++) {
utterances[i] = grammar.getRandomSentence();
}
}
else {
utterances = expandGrammarRecursive(grammar.getInitialNode(), "", 0);
}
return utterances;
}
catch (JSGFGrammarParseException e) {
System.out.println(e.details);
throw e;
}
}
示例8: main
import edu.cmu.sphinx.jsgf.JSGFGrammar; //导入依赖的package包/类
public static void main(String[] args) {
ConfigurationManager configurationManager = VoiceRecognitionInput.createConfigurationManager("voiceControl/input/input.config.xml");
Recognizer recognizer = (Recognizer) configurationManager
.lookup("recognizer");
recognizer.allocate();
JSGFGrammar grammar = (JSGFGrammar) configurationManager
.lookup("jsgfGrammar");
grammar.getInitialNode().dumpGDL("grammars.gdl");
}
示例9: getGrammar
import edu.cmu.sphinx.jsgf.JSGFGrammar; //导入依赖的package包/类
/**
* Returns the JSGF Grammar for the dialog manager that contains this
* node
*
* @return the grammar
*/
public JSGFGrammar getGrammar() {
return grammar;
}