<!-- In your flow, you need to change between the contexts --><stateid="start"extends="Dialog"><varname="lang"type="String"value="en"/><onentry><agent:say>German or English?</agent:say></onentry><oneventname="sense.user.speak"cond="event?:sem:german"><exec>lang = "de"</exec><sendevent="action.context.default"p:context="'german'"/><sendevent="action.voice"p:name="'SOME_GERMAN_VOICE'"/><gotostate="next"/></onevent><oneventname="sense.user.speak"cond="event?:sem:english"><exec>lang = "en"</exec><sendevent="action.context.default"p:context="'english'"/><sendevent="action.voice"p:name="'SOME_ENGLISH_VOICE'"/><gotostate="next"/></onevent></state><stateid="next"><onentry><ifcond="eq(lang, 'de')"><agent:say>Schönen Tag</agent:say><else/><agent:say>Hello there</agent:say></if></onentry></state>
// In YourSkill.java you have to create the contexts@Overridepublicvoidinit()throwsException{// ...// Create english context and set an open vocabulary contexthandler.loadContext("english",newOpenVocabularyContext(language));handler.loadContext("english",newSemanticGrammarContext(newSRGSGrammar(getPackageFile("YourGrammar_en.xml"))));// Create german context, this time with a list of german phrases that the regozniser should give prominance tohandler.loadContext("german",newOpenVocabularyContext(language,german_phrases));handler.loadContext("german",newSemanticGrammarContext(newSRGSGrammar(getPackageFile("YourGrammar_de.xml"))));// Set english as defaulthandler.setDefaultContext("default");// ...}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.