示例#1
0
文件: C2SR.cs 项目: ariva13/C2Program
        public C2SR(Form1 form, int numZone)
        {
            form1       = form;
            numZones    = numZone;
            appAddress  = "192.168.113.90";
            gpio        = new C2gpio(numZones, appAddress);
            state       = State.IDLE;
            voice       = new C2Voice[numZones];
            rtpClient   = new RTPReceiver[numZones];
            rtpServer   = new RTPServer[numZones];
            recoContext = new SpInProcRecoContext[numZones];
            grammar     = new ISpeechRecoGrammar[numZones];

            //Set up unique variables (1 for all zones)
            myLocationMap = CreateLocationMap();

            //Set up zones
            zoneAddresses  = new String[numZones];
            zoneMotion     = new bool[numZones];
            lightsOccupied = new bool[numZones];

            for (int i = 0; i < numZones; i++)
            {
                zoneAddresses[i]  = "192.168.113." + (100 + i + 1);
                zoneMotion[i]     = false;
                lightsOccupied[i] = false;
            }



            missunderstandCount = 0;

            for (int i = 0; i < numZones; i++)
            {
                InitZone(i + 1);
                voice[i].Speak("Zone " + (i + 1) + " standing by.");
            }

            //Set up timers
            //Initialize c2attentionTimer to be ready for a time out to stop listening (don't start till listening)
            c2attentionTimer           = new Timer(30000); //30 second time out for C2 to stop listening
            c2attentionTimer.Elapsed  += new ElapsedEventHandler(C2attentionTimer_Elapsed);
            c2attentionTimer.AutoReset = true;

            //Initialize c2MotionTimer to check motion sensors every 2 seconds
            c2MotionTimer           = new Timer(2000);
            c2MotionTimer.Elapsed  += new ElapsedEventHandler(c2MotionTimer_Elapsed);
            c2MotionTimer.AutoReset = true;
            c2MotionTimer.Start();


            voice[0].Speak("C2 standing by and awaiting your instructions!");
        }
示例#2
0
        public C2SRold(Form1 form)
        {
            form1                      = form;
            gpio                       = new C2gpio(1, "");
            state                      = State.IDLE;
            voice                      = new C2Voice(1);
            C2attentionTimer           = new Timer(30000); //60 second time out for C2 to stop listening
            C2attentionTimer.Elapsed  += new ElapsedEventHandler(C2attentionTimer_Elapsed);
            C2attentionTimer.AutoReset = false;

            missunderstandCount = 0;
            voice.Speak("C2 standing by and awaiting your instructions!");

            //recoContext = new SpSharedRecoContext();
            recoContext = new SpInProcRecoContext();

            //set up the socket stream first
            //IPEndPoint receiver = new IPEndPoint(new IPAddress(("192.168.2.101"), 1234);
//            UdpClient udpClient = new UdpClient("192.168.2.101", 1234);
            //UdpClient udpClient = new UdpClient(1234);
            //udpClient.Connect(receiver);
//            Socket socket = udpClient.Client;

            //TcpClient tcpClient = new TcpClient("192.168.2.101", 1234);
//            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
//            socket.Connect("192.168.2.101", 1234);
//            if (!socket.Connected)
//            {
//                form1.statusMsg = "socket was never connected!";
//                return;
//            }

            //SpMMAudioIn instream = new SpMMAudioIn();
//            ASRStreamClass myAsrStream = new ASRStreamClass();
//            mySrStream = new C2SRStream("192.168.2.101", 1234);
            rtpClient = new RTPReceiver(1234);
            rtpClient.StartClient();
            SpCustomStream stream = new SpCustomStream();

//            stream.BaseStream = (System.Runtime.InteropServices.ComTypes.IStream)mySrStream;
//            stream.BaseStream = (System.Runtime.InteropServices.ComTypes.IStream)rtpClient.AudioStream;
            stream.BaseStream = rtpClient.AudioStream;
            //SpStream st = new SpStream();
            //st.



            //m_GrammarID = 1;
            Grammar = this.recoContext.CreateGrammar(0);
            Grammar.DictationLoad("", SpeechLoadOption.SLOStatic);
            //our program doesn't do this
            Grammar.DictationSetState(SpeechRuleState.SGDSActive);
            //our program doesn't do this

            //            ISpeechGrammarRule CommandsRule;
            //            CommandsRule = Grammar.Rules.Add("CommandsRule", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
            //            CommandsRule.Clear();
            //            object dummy = 0;
            //            string sCommand = "see";
            //            CommandsRule.InitialState.AddWordTransition(null, sCommand, " ", SpeechGrammarWordType.SGLexical, null, 0, ref dummy, 0);
            //            Grammar.Rules.Commit();
            //            Grammar.CmdSetRuleState("CommandsRule", SpeechRuleState.SGDSActive);
            //stream.get
            this.recoContext.Recognizer.AudioInputStream = stream;
            //this.recoContext.Recognizer.AudioInputStream = (ISpeechBaseStream) stream.BaseStream;
            //this.recoContext.Recognizer.AudioInputStream = (ISpeechBaseStream)rtpClient.Stream;
            //RecoContext.EventInterests = SpeechRecoEvents.SREAllEvents;
            //RecoContext.RetainedAudioFormat.Type = SpeechAudioFormatType.SAFT32kHz16BitMono;
            recoContext.RetainedAudioFormat.Type = SpeechAudioFormatType.SAFT24kHz16BitMono;
            //RecoContext.EventInterests = SPSEMANTICFORMAT. SRERecognition + SRESoundEnd + SREStreamEnd + SREStreamStart + SRESoundEnd;
            recoContext.Recognition += new SpeechLib._ISpeechRecoContextEvents_RecognitionEventHandler(InterpretCommand);
            //RecoContext.Recognition += new _ISpeechRecoContextEvents_

            recoContext.Recognizer.SetPropertyNumber("AdaptationOn", 0);
        }