c# - Multi-level Speech Commands? -
i'm trying multi-level command speech, i'm having trouble it...
i want have master commands like: "tv", "light", "water" etc
when "tv", example, want have sub commands desired action, like:
when "tv": sub commands -> "volume up", "volume down", "power off", "power on"
i'll recognized commands tv, until "tv done". master command's list.
how can that?
my actual code this:
class program { static dictionary<string, string> listacanais = new dictionary<string, string>() { { "fox news", "0 6 0" }, { "the weather channel", "0 3 1"}, { "spike", "0 3 8"} }; static void main(string[] args) { using (var sre = new speechrecognitionengine(new system.globalization.cultureinfo("pt-br"))) { sre.setinputtodefaultaudiodevice(); sre.loadgrammarasync(comandos()); sre.requestrecognizerupdate(); sre.speechrecognitionrejected += sre_speechrecognitionrejected; sre.speechrecognized += sre_speechrecognized; sre.recognizeasync(recognizemode.multiple); console.readline(); } } public static grammar comandos() { choices numerostv = new choices("zero", "um", "dois", "trĂªs", "quatro", "cinco", "seis", "sete", "oito", "nove", "10", "11", "12"); grammarbuilder frasenumerotv = new grammarbuilder(numerostv); grammarbuilder frasemudarcanal = new grammarbuilder("tv, canal"); frasemudarcanal.append(numerostv); //frasemudarcanal.append(numerostv); //frasemudarcanal.append(numerostv); choices nomecanal = new choices(); foreach (string key in listacanais.keys) { nomecanal.add(key); } grammarbuilder frasenomecanal = new grammarbuilder("tv, canal"); frasenomecanal.append(nomecanal); grammarbuilder frasemudo = new grammarbuilder("tv, silencioso"); grammarbuilder fraseligar = new grammarbuilder("tv, ligar"); grammarbuilder frasefecharapp = new grammarbuilder("controle, fechar aplicativo"); grammarbuilder frasepausecomandovoz = new grammarbuilder("controle, pausar comando de voz"); grammarbuilder fraseiniciarcomandovoz = new grammarbuilder("controle, ativar comando de voz"); choices opcoesprincipais = new choices(new grammarbuilder[] {frasemudarcanal, frasenomecanal, frasemudo, fraseligar, frasefecharapp, frasepausecomandovoz, fraseiniciarcomandovoz}); grammar resultado = new grammar((grammarbuilder)opcoesprincipais); return resultado; } static void sre_speechrecognitionrejected(object sender, speechrecognitionrejectedeventargs e) { console.writeline("ignorado"); } // create simple handler speechrecognized event. static void sre_speechrecognized(object sender, speechrecognizedeventargs e) { console.writeline("ouvi"); if (e.result == null) return; console.writeline("[ " + e.result.confidence + " ]" + "reconhecido: " + e.result.text); } }
thanks in advance.
such things easy implement within state machine framework. define state of recognizer , act based on it, main work done in onrecognitionresult method:
states = {input, tv, water}; inputgrammar = createinputgrammar(); tvgrammar = createtvgrammar(); watergrammar = createwatergrammar(); state = input; vodi onrecognitionresult() { if (state == input) { if (result == "tv") { state = tv; recognizer.loadgrammar(tvgrammar); } } if (state == tv) { if (result == "volume up") { raisevolume(); } if (result == "tv done") { state = input; recognizer.loadgrammar(inputgrammar); } } // restart recognition recognizer.recognizeasync(); }
you can read simple state machine example in c#? more information.
Comments
Post a Comment