当前位置: 首页>>代码示例>>Java>>正文


Java JSGFGrammar类代码示例

本文整理汇总了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);
	}
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:22,代码来源:TagsToSentences.java

示例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");

		}
	}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:14,代码来源:RuleParser.java

示例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.");
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:17,代码来源:GrammarTraversal.java

示例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);
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:8,代码来源:DialogManager.java

示例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;
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:51,代码来源:PhonemeCollector.java

示例6: GrammarDump

import edu.cmu.sphinx.jsgf.JSGFGrammar; //导入依赖的package包/类
public GrammarDump(JSGFGrammar grammar) {
	this.grammar = grammar;
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:4,代码来源:GrammarDump.java

示例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;
        }
    }
 
开发者ID:EllaVator,项目名称:EllaVator,代码行数:51,代码来源:JsgfExpander.java

示例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");

	
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:15,代码来源:GrammarVisualizer.java

示例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;
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:10,代码来源:DialogManager.java


注:本文中的edu.cmu.sphinx.jsgf.JSGFGrammar类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。