Example #1
0
        private void StartTalk()
        {
            if (_bTalking)
            {
                StopTalk();
            }
            if (_muLawCodec != null)
            {
                lock (_obj)
                {
                    _muLawCodec.Dispose();
                }
                _muLawCodec = null;
            }
            _muLawCodec = new AcmMuLawChatCodec();

            string sPost = "POST /axis-cgi/audio/transmit.cgi HTTP/1.0\r\n";
            //sPost += "Content-Type: multipart/x-mixed-replace; boundary=--myboundary\r\n";
            sPost += "Content-Type: audio/basic\r\n";
            sPost += "Content-Length: 9999999\r\n";
            sPost += "Connection: Keep-Alive\r\n";
            sPost += "Cache-Control: no-cache\r\n";

            string usernamePassword = _username + ":" + _password;
            sPost += "Authorization: Basic "+Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword))+"\r\n\r\n";

            _client = new TcpClient(_server, _port);
            _avstream = _client.GetStream();
            
            byte[] hdr = Encoding.ASCII.GetBytes(sPost);
            _avstream.Write(hdr, 0, hdr.Length);

            _audioSource.DataAvailable += AudioSourceDataAvailable;
            _talkBuffer = new byte[2500];
            _talkDatalen = 0;
            _bTalking = true;
        }
Example #2
0
        private void StopTalk()
        {
            if (_bTalking)
            {
                lock (_obj)
                {
                    if (_bTalking)
                    {
                        _bTalking = false;
                    }
                    if (_client!=null)
                    {
                        _client.Close();
                        _client = null;
                    }

                    if (_avstream != null)
                    {
                        _avstream.Close();
                        _avstream.Dispose();
                        _avstream = null;
                    }

                    if (_muLawCodec != null)
                    {
                        _muLawCodec.Dispose();
                        _muLawCodec = null;
                    }

                    _audioSource.DataAvailable -= AudioSourceDataAvailable;
                    TalkStopped?.Invoke(this, EventArgs.Empty);
                }
            }
        }