當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。