public static List <string> indexes = new List <string>();// lista de noticias static void Main(string[] args) { //bot = new AIML(); engine = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("pt-BR")); //Instanciando Engine de Reconhecimento engine.SetInputToDefaultAudioDevice(); //Configurando dispositivo de audio sp = new SpeechSynthesizer(); //Instancia do sintetizador de fala //Vetores de Comandos //Musica //Configurando AIML //AIML.ConfigAIMLFiles(); //conversas a.i string[] conversaAi = AIML.GetWordsOrSentences(); //PEGANDO PALAVRAS E LANÇANDO NO VETOR string[] mp3Files = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), "*.wav", SearchOption.AllDirectories); //Conversas string[] conversas = { "Jarvis", "olá", "boa noite", "boa tarde", "tudo bem", "hello", "Fala com a Isa", "café", "vou te apagar", "oi bebe", "Dá parabéns pro meu pai" }; //Comandos do Sistemas string[] comandosSistema = { "apresentar", "que horas são", "que dia é hoje", "parar", "google", "aulas de violão", "pesquisar", "desligar máquina", "fechar aplicativo", "facebook", "fechar navegador", "youtube", "conversor mp3", "listar musicas", "listar pastas", "acessar hotmail", "abrir gmail", "noticias", "listar documentos", "listar comandos", "prompt de comando", "ler noticias", "abrir link 1" }; string[] documentos = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "", SearchOption.AllDirectories); String[] escolhaNews = new String[42]; int i = 0; //Choices while (i < 42) { escolhaNews[i] = "" + i; i++; } Choices cNoticias = new Choices(escolhaNews); Choices c_conversaAi = new Choices(conversaAi);//Colocando lista de expressoes e palavras em choices Choices cMusics = new Choices(); Choices c_conversas = new Choices(conversas); Choices c_comandosSistema = new Choices(comandosSistema); Choices c_documentos = new Choices(); dictMyMusic = new Dictionary <string, string>(); foreach (var mp3File in mp3Files) { FileInfo fi = new FileInfo(mp3File); String temp = fi.Name.Replace(fi.Extension, ""); if (temp.Contains("_")) { temp.Replace("_", " "); } cMusics.Add(temp); if (!dictMyMusic.ContainsKey(temp)) { dictMyMusic.Add(temp, fi.FullName); } } //Comandos GrammarBuilder gbNoticias = new GrammarBuilder(); gbNoticias.Append(new Choices("abrir noticia", "acessar noticia")); gbNoticias.Append(cNoticias); Grammar gNoticias = new Grammar(gbNoticias); gNoticias.Name = "news"; GrammarBuilder gbAI = new GrammarBuilder(); //Adicionando gbAI.Append(c_conversaAi); GrammarBuilder gbMusic = new GrammarBuilder(); gbMusic.Append(new Choices("tocar", "reproduza", "toque", "musica aleatória")); gbMusic.Append(cMusics); Grammar gMusics = new Grammar(gbMusic); gMusics.Name = "music"; //Instancia Grammar Builder GrammarBuilder gb_conversas = new GrammarBuilder(); gb_conversas.Append(c_conversas); GrammarBuilder gb_comandosSistema = new GrammarBuilder(); gb_comandosSistema.Append(c_comandosSistema); //Instancia Grammar Grammar g_conversaAi = new Grammar(gbAI); g_conversaAi.Name = "ai"; Grammar g_conversas = new Grammar(gb_conversas); g_conversas.Name = "conversas"; Grammar g_comandosSistema = new Grammar(gb_comandosSistema); g_comandosSistema.Name = "sistema"; //Load dos Grammars Console.Write("<==============================="); engine.LoadGrammar(g_conversaAi); engine.LoadGrammar(g_comandosSistema); engine.LoadGrammar(g_conversas); engine.LoadGrammar(gMusics); engine.LoadGrammar(gNoticias); Console.Write("==============================>"); //Incremento do reconhecimento de voz engine.SpeechRecognized += rec; String n = sp.Voice.Name.ToString(); Console.WriteLine("\nEstou ouvindo..."); engine.RecognizeAsync(RecognizeMode.Multiple); sp.SelectVoiceByHints(VoiceGender.Male); Console.ReadKey(); }
private static void rec(object s, SpeechRecognizedEventArgs e) { //Confiança no resultado if (e.Result.Confidence >= 0.4f) { string speech = e.Result.Text; Console.WriteLine("Você disse " + speech + " || Confiança: " + e.Result.Confidence); switch (e.Result.Grammar.Name) { case "conversas": processConversa(speech); break; case "sistema": processarSistema(speech); break; case "music": //"tocar", "reproduza", "toque" if (speech.StartsWith("tocar")) { speech = speech.Replace("tocar", ""); } else if (speech.StartsWith("reproduza")) { speech = speech.Replace("reproduza", ""); } else if (speech.StartsWith("toque")) { speech = speech.Replace("toque", ""); } else if (speech.StartsWith("musica aleatória")) { musicaAleatoria(); } speech = speech.Trim(); playFile(dictMyMusic[speech]); break; case "news": // "abrir","acessar" if (speech.StartsWith("abrir noticia")) { speech = speech.Replace("abrir noticia", ""); } else if (speech.StartsWith("acessar noticia")) { speech = speech.Replace("acessar noticia", ""); } speech = speech.Trim(); try { speech = indexes[int.Parse(speech)]; Process.Start("chrome", speech); } catch (Exception ex) { Speak("Eu preciso ler as noticias para saber o que procurar"); } break; //inteligencia artificial case "ai": string fala = AIML.GetOutputChat(speech); string url; if (speech.StartsWith("pesquisar")) //se o comando começar com pesquisar { speech = speech.Replace("pesquisar", ""); //apagar o pesquisar da memoria url = "http://www.google.com.br/search?q='" + speech + "'"; Process.Start("chrome", url); } else if (speech.StartsWith("disco")) //se o comando começar com pesquisar { speech = speech.Replace("disco", ""); //apagar o pesquisar da memoria url = speech + ":\\"; //pesquisar em documentos Process.Start("explorer", url); //abrindo explorer } else if (speech.StartsWith("documentos")) //se o comando começar com documentos { speech = speech.Replace("documentos", ""); //apagar o documentos da memoria url = @"C:\Users\Laércio.Home\Documents\" + speech; //pesquisar em documentos Process.Start("explorer", url); //abrindo explorer } else { Speak(fala); //pegando saida para entrada de fala e falando } break; default: Speak("Carregando Arquivos"); break; } }//Caso a confiança no resultado seja menor que 0.4f else { //Fala isso Speak("Não te ouvi direito"); } }