예제 #1
0
 public static WSRKeyboard GetInstance()
 {
     if (manager == null)
     {
         manager = new WSRKeyboard();
     }
     return(manager);
 }
예제 #2
0
        // ==========================================
        //  HANDLE HTTPSERVER
        // ==========================================

        public virtual bool HandleCustomRequest(NHttp.HttpRequestEventArgs e, StreamWriter writer)
        {
            // Status
            String status = e.Request.Params.Get("status");

            if (status != null)
            {
                if (WSRSpeakerManager.GetInstance().Speaking)
                {
                    writer.Write("speaking");
                }
            }

            // Askme
            var values = System.Web.HttpUtility.ParseQueryString(e.Request.Url.Query);
            var mgr    = WSRSpeechManager.GetInstance();

            String[] grammar = values.GetValues("grammar");
            String[] tags    = values.GetValues("tags");
            WSRSpeechManager.GetInstance().DynamicGrammar(grammar, tags);

            // Stop Music
            String pause = e.Request.Params.Get("pause");

            if (pause != null)
            {
                WSRSpeakerManager.GetInstance().Stop(pause);
            }

            // Play Music
            String mp3 = e.Request.Params.Get("play");

            if (mp3 != null)
            {
                WSRSpeakerManager.GetInstance().Play(mp3, e.Request.Params.Get("sync") == null);
            }

            // Recognize
            String audio = e.Request.Params.Get("recognize");

            if (audio != null)
            {
                WSRSpeechManager.GetInstance().RecognizeFile(audio);
            }

            // Listening
            String listen = e.Request.Params.Get("listen");

            if (listen != null)
            {
                WSRSpeechManager.GetInstance().Listening = bool.Parse(listen);
            }

            // Recognize File
            NHttp.HttpPostedFile file = e.Request.Files.Get("recognize");
            if (file != null)
            {
                byte[] data = null;
                using (var reader = new BinaryReader(file.InputStream)) {
                    data = reader.ReadBytes(file.ContentLength);
                }
                var path = WSRConfig.GetInstance().audio + "/" + file.FileName;
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                File.WriteAllBytes(path, data);
            }

            // Text To Speech
            String tts = e.Request.Params.Get("tts");

            if (tts != null)
            {
                tts = e.Server.HtmlDecode(tts);
                WSRSpeakerManager.GetInstance().Speak(tts, e.Request.Params.Get("sync") == null);
            }

            // Text To Speech - Stop
            String notts = e.Request.Params.Get("notts");

            if (notts != null)
            {
                WSRSpeakerManager.GetInstance().ShutUp();
            }

            // Text To Speech - Stop
            String restart = e.Request.Params.Get("restart");

            if (restart != null)
            {
                Restart();
            }

            // Set Context
            String ctxt = e.Request.Params.Get("context");

            if (ctxt != null)
            {
                WSRSpeechManager.GetInstance().SetContext(new List <string>(ctxt.Split(',')));
                WSRSpeechManager.GetInstance().SetContextTimeout();
                WSRSpeechManager.GetInstance().ForwardContext();
            }

            // Process
            String activate = e.Request.Params.Get("activate");

            if (activate != null)
            {
                WSRKeyboard.GetInstance().ActivateApp(activate);
            }

            String run   = e.Request.Params.Get("run");
            String param = e.Request.Params.Get("runp");

            if (run != null)
            {
                WSRKeyboard.GetInstance().RunApp(run, param);
            }

            // Keyboard
            String keyMod = e.Request.Params.Get("keyMod");
            String key    = e.Request.Params.Get("keyPress");

            if (key != null)
            {
                WSRKeyboard.GetInstance().SimulateKey(key, 0, keyMod);
            }

            key = e.Request.Params.Get("keyDown");
            if (key != null)
            {
                WSRKeyboard.GetInstance().SimulateKey(key, 1, keyMod);
            }

            key = e.Request.Params.Get("keyUp");
            if (key != null)
            {
                WSRKeyboard.GetInstance().SimulateKey(key, 2, keyMod);
            }

            String keyText = e.Request.Params.Get("keyText");

            if (keyText != null)
            {
                WSRKeyboard.GetInstance().SimulateTextEntry(keyText);
            }

            // Recognize String
            String emulate = e.Request.Params.Get("emulate");

            if (emulate != null)
            {
                WSRSpeechManager.GetInstance().RecognizeString(emulate);
                writer.Write(WSRSpeakerManager.GetInstance().SpeechBuffer);
            }
            return(false);
        }
예제 #3
0
 public static WSRKeyboard GetInstance() {
   if (manager == null) {
     manager = new WSRKeyboard();
   }
   return manager;
 }