Exemple #1
0
        /// <summary>
        /// Indicates the introduction has finished. It's starts the voice record.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Narrator_IntroductionFinished(object sender, EventArgs e)
        {
            Narrator.Finished -= Narrator_IntroductionFinished;

            waveStreamRecorder =
                new WaveStreamRecorder(Path.Combine(Environment.CurrentDirectory,
                                                    string.Format("IVRVoiceMesage{0}.wav", DateTime.Now.ToFileTime())));

            OnIntroductionStarting(waveStreamRecorder);
            waveStreamRecorder.StartStreaming();

            Narrator.Finished += narrator_PostIntroductionFinished;
        }
        /// <summary>
        /// Loads a wav file for playback.
        /// </summary>
        public void LoadPlaybackWavFile(string filePath)
        {
            if (!_initialized)
            {
                return;
            }

            if (_wavPlayer != null)
            {
                _audioConnector.Disconnect(_wavPlayer, _phoneCallAudioSender);
                _wavPlayer.Dispose();
                _wavRecorder = null;
            }

            _wavPlayer = new WaveStreamPlayback(filePath, false, true);

            _audioConnector.Connect(_wavPlayer, _phoneCallAudioSender);
        }
Exemple #3
0
        /// <summary>
        /// Loads a wav file for playback.
        /// </summary>
        public void LoadRecordWavFile(string filePath)
        {
            if (!initialized)
            {
                return;
            }

            if (wavRecorder != null)
            {
                audioConnector.Disconnect(recordDataMixer, wavRecorder);
                wavRecorder.Dispose();
                wavRecorder = null;
            }

            wavRecorder = new WaveStreamRecorder(filePath);

            audioConnector.Connect(recordDataMixer, wavRecorder);
        }
Exemple #4
0
        /// <summary>
        /// Loads a wav file for playback.
        /// </summary>
        public void LoadPlaybackWavFile(string filePath)
        {
            if (!initialized)
            {
                return;
            }

            if (wavPlayer != null)
            {
                audioConnector.Disconnect(wavPlayer, outgoingDataMixer);
                wavPlayer.Dispose();
                wavRecorder = null;
            }

            wavPlayer = new WaveStreamPlayback(filePath, false, true);

            audioConnector.Connect(wavPlayer, outgoingDataMixer);
        }
        public RecordingContext(ISession my_session, RecordingFileFormat my_format, string my_extension_subpath)
        {
            session           = my_session;
            format            = my_format;
            extension_subpath = my_extension_subpath;

            recorder_filename = Path.GetTempFileName();

            switch (format)
            {
            case RecordingFileFormat.MP3:
                mp3_recorder = new MP3StreamRecorder(recorder_filename);
                break;

            case RecordingFileFormat.WAV:
                wav_recorder = new WaveStreamRecorder(recorder_filename);
                break;
            }
        }
        public CallHandler()
        {
            _guid = Guid.NewGuid().ToString();

            // Setup logging
            _logFileName = String.Format("{0}{1}.log", _dataDirectory, _guid);
            GlobalContext.Properties["LogFileName"] = _logFileName;
            GlobalContext.Properties["CallGUID"]    = _guid;
            log4net.Config.XmlConfigurator.Configure();
            _log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            _wavFileName = String.Format("{0}{1}.wav", _dataDirectory, _guid);

            _mixer         = new AudioMixerMediaHandler();
            _audioReceiver = new PhoneCallAudioReceiver();
            _wavRecorder   = new WaveStreamRecorder(_wavFileName, new WaveFormat());
            _connector     = new MediaConnector();
            _connector.Connect(_audioReceiver, _mixer);
            _connector.Connect(_mixer, _wavRecorder);
        }
        private void CallEnded()
        {
            _log.Info("Audio position at " + _wavRecorder.Stream.Position);
            _log.Info("Call Completed");
            _wavRecorder.StopStreaming();
            _connector.Disconnect(_audioReceiver, _mixer);
            _connector.Disconnect(_mixer, _wavRecorder);
            _wavRecorder.Stream.Flush();
            _wavRecorder.Dispose();
            _wavRecorder = null;
            _audioReceiver.Detach();
            _log.Info("Call tear down done");

            // Wake up the main thread
            _complete = true;
            lock (_sync)
            {
                Monitor.Pulse(_sync);
            }
        }
        /// <summary>
        /// Loads a wav file for playback.
        /// </summary>
        public void LoadRecordWavFile(string filePath)
        {
            if (!_initialized)
            {
                return;
            }

            if (_wavRecorder != null)
            {
                _audioConnector.Disconnect(_phoneCallAudioReceiver, _wavRecorder);
                _audioConnector.Disconnect(AudioEnhancer, _wavRecorder);
                _wavRecorder.Dispose();
                _wavRecorder = null;
            }

            _wavRecorder = new WaveStreamRecorder(filePath);

            _audioConnector.Connect(_phoneCallAudioReceiver, _wavRecorder);
            _audioConnector.Connect(AudioEnhancer, _wavRecorder);
        }
Exemple #9
0
        protected override void ElapsedVoice(object sender, EventArgs eventArgs)
        {
            if (SoundTimer != null)
            {
                SoundTimer.Stop();
                SoundTimer.Elapsed -= ElapsedVoice;
                SoundTimer.Dispose();
            }
            Connector.Disconnect(_camera.AudioChannel, WaveStreamRecorder);

            WaveStreamRecorder.Stop();

            WaveStreamRecorder.Dispose();

            VadFilter.Enabled = true;
            IsSoundDetected   = false;
            Log.Motion("Sound recording has stopped");

            OnGetFilePath(new VoIPEventArgs <string>(SoundFilePath));
        }
Exemple #10
0
        protected override void VadFilterVoiceDetected(object sender, EventArgs e)
        {
            if (IsSoundDetected)
            {
                return;
            }

            VadFilter.Enabled = false;

            var date = DateTime.Now.Year + "y-" + DateTime.Now.Month + "m-" + DateTime.Now.Day + "d-" +
                       DateTime.Now.Hour + "h-" + DateTime.Now.Minute + "m-" + DateTime.Now.Second + "s";


            string currentpath;

            if (String.IsNullOrEmpty(MotionDirectoryPath))
            {
                currentpath = AppDomain.CurrentDomain.BaseDirectory + date + ".wav";
            }
            else
            {
                currentpath = MotionDirectoryPath + "\\" + date + ".wav";
            }
            SoundFilePath = currentpath;

            WaveStreamRecorder = new WaveStreamRecorder(currentpath);

            Connector.Connect(_microphone, WaveStreamRecorder); // connects the voices to the recorder

            SoundTimer           = new Timer();
            SoundTimer.Elapsed  += ElapsedVoice;
            SoundTimer.Interval  = Duration * 1000;
            SoundTimer.AutoReset = false;

            _microphone.Start();
            SoundTimer.Start();
            WaveStreamRecorder.Start();
            IsSoundDetected = true;
            Log.Motion("Sound detected");
        }
        /// <summary>
        /// Loads a wav file for playback.
        /// </summary>
        public void LoadPlaybackWavFile(string filePath)
        {
            if (!initialized)
                return;

            if (wavPlayer != null)
            {
                audioConnector.Disconnect(wavPlayer, outgoingDataMixer);
                wavPlayer.Dispose();
                wavRecorder = null;
            }

            wavPlayer = new WaveStreamPlayback(filePath, false, true);

            audioConnector.Connect(wavPlayer, outgoingDataMixer);
        }
Exemple #12
0
        void workDelayRecording_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            #region combine mic and receiver in record

            if (callstate == CallState.InCall)
            {
                this.Invoke(new Action(delegate()
                {
                    memStreamRecorder = new MemoryStream();
                    recorder = new WaveStreamRecorder(memStreamRecorder);
                    memStreamRecorder = new MemoryStream();
                    recorder = new WaveStreamRecorder(memStreamRecorder);
                    recorder.Stopped += new EventHandler<EventArgs>(recorder_Stopped);
                    connector.Connect(m_UserMicrophone, mixer);
                    connector.Connect(mediaReceiver, mixer);
                    connector.Connect(mixer, recorder);
                    recorder.StartStreaming();
                    //recorder.IsStreaming = true;
                }));
            }

            #endregion
        }
Exemple #13
0
        /// <summary>
        /// Occurs when the phone call state has changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void call_CallStateChanged1(object sender, VoIPEventArgs<CallState> e)
        {
            this.InvokeGUIThread(() => {
                if (e.Item == CallState.Ringing) {
                    m_TimeStart = DateTime.Now.TimeOfDay;
                    m_StartTimeOutCounter = true;
                    m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.Ring);
                }

                else if (e.Item == CallState.InCall) {
                    try
                    {
                        m_StartTimeOutCounter = false;
                        mixer = new AudioMixerMediaHandler();
                        mixerMic = new AudioMixerMediaHandler();
                        mixerReceiver = new AudioMixerMediaHandler();
                        AudioId = Guid.NewGuid();
                        CommonApplicationData commonData = new CommonApplicationData("BrightVision", "BrightSales", true);
                        if (m_UserMicrophone != null)
                            m_UserMicrophone.Start();

                        if (m_UserSpeaker != null)
                            m_UserSpeaker.Start();

                        connector.Connect(m_UserMicrophone, mediaSender);
                        connector.Connect(mediaReceiver, m_UserSpeaker);
                        m_MediaUtility.Stop();
                        //m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.HangUp);

                        mediaSender.AttachToCall(call);
                        mediaReceiver.AttachToCall(call);

                        #region combine mic and receiver in record
                        string fileName = String.Format(@"{0}\\tmpwav\\{1}_.wav", commonData.ApplicationFolderPath, AudioId);
                        recorder = new WaveStreamRecorder(fileName);
                        recorder.Stopped += new EventHandler<EventArgs>(recorder_Stopped);
                        connector.Connect(m_UserMicrophone, mixer);
                        connector.Connect(mediaReceiver, mixer);
                        connector.Connect(mixer, recorder);
                        #endregion

                        #region record mic
                        fileName = String.Format(@"{0}\\tmpwav\\{1}_mic.wav", commonData.ApplicationFolderPath, AudioId);
                        recorderMic = new WaveStreamRecorder(fileName);
                        recorderMic.Stopped += new EventHandler<EventArgs>(recorder_Stopped1);
                        connector.Connect(m_UserMicrophone, mixerMic);
                        connector.Connect(mixerMic, recorderMic);
                        #endregion

                        #region record receiver
                        fileName = String.Format(@"{0}\\tmpwav\\{1}_receiver.wav", commonData.ApplicationFolderPath, AudioId);
                        recorderReceiver = new WaveStreamRecorder(fileName);
                        recorderReceiver.Stopped += new EventHandler<EventArgs>(recorder_Stopped2);
                        connector.Connect(mediaReceiver, mixerReceiver);
                        connector.Connect(mixerReceiver, recorderReceiver);
                        #endregion

                        recorder.StartStreaming();
                        //recorder.IsStreaming = true;
                        recorderReceiver.StartStreaming();
                        //recorderReceiver.IsStreaming = true;
                        recorderMic.StartStreaming();
                        //recorderMic.IsStreaming = true;
                    }
                    catch(Ozeki.Common.Exceptions.MediaException me) {
                        if (CallState_Changed != null)
                        {
                            CallState_Changed(this, new CallStateChangedArgs()
                            {
                                PhoneCallState = CallState.Rejected
                            });
                        }
                        if (call != null)
                            call.HangUp();

                        //softPhone.UnregisterPhoneLine(phoneLine);
                        softPhone.Close();
                        this.WireDownCallEvents();
                        call = null;

                        m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.HangUp);
                        MessageBox.Show("Your mic or speaker is not working. Please change your mic or speaker in the Phone Settings.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }

                else if (e.Item == CallState.Completed) {
                    try
                    {

                        if (m_UserMicrophone != null)
                            m_UserMicrophone.Stop();
                        if (m_UserSpeaker != null)
                            m_UserSpeaker.Stop();

                        connector.Disconnect(m_UserMicrophone, mediaSender);
                        connector.Disconnect(mediaReceiver, m_UserSpeaker);

                        if (recorder != null)
                        {
                            recorder.StopStreaming();
                            //recorder.IsStreaming = false;
                        }
                        if (recorderMic != null)
                        {
                            recorderMic.StopStreaming();
                            //recorderMic.IsStreaming = false;
                        }
                        if (recorderReceiver != null)
                        {
                            recorderReceiver.StopStreaming();
                            //recorderReceiver.IsStreaming = false;
                        }

                        connector.Disconnect(m_UserMicrophone, mixer);
                        connector.Disconnect(mediaReceiver, mixer);
                        connector.Disconnect(mixer, recorder);

                        connector.Disconnect(m_UserSpeaker, mixerMic);
                        connector.Disconnect(mixerMic, recorderMic);

                        connector.Disconnect(mixerMic, recorderMic);
                        connector.Disconnect(mixerReceiver, recorderReceiver);

                        mediaSender.Detach();
                        mediaReceiver.Detach();
                        if (m_RingTimeOut)
                            return;

                        //softPhone.UnregisterPhoneLine(phoneLine);
                        softPhone.Close();

                        this.WireDownCallEvents();
                        //call.HangUp();
                        call = null;
                        m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.HangUp);
                        recorder.Dispose();
                        mixer.Dispose();
                        recorder = null;
                        mixer = null;
                        recorderMic.Dispose();
                        mixerMic.Dispose();
                        recorderMic = null;
                        mixerMic = null;
                        mixerReceiver.Dispose();
                        recorderReceiver.Dispose();
                        mixerReceiver = null;
                        recorderReceiver = null;
                        WaitUntilTheRecordEndProcess();

                    }
                    catch {
                        //softPhone.UnregisterPhoneLine(phoneLine);
                        softPhone.Close();
                        this.WireDownCallEvents();
                        call = null;
                    }
                }

                else if (e.Item == CallState.Cancelled) {
                    if (m_RingTimeOut)
                        return;

                    m_StartTimeOutCounter = false;
                    //softPhone.UnregisterPhoneLine(phoneLine);
                    softPhone.Close();
                    this.WireDownCallEvents();
                    call = null;
                    m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.HangUp);
                }

                else if (e.Item == CallState.Rejected) {
                    m_StartTimeOutCounter = false;
                    //softPhone.UnregisterPhoneLine(phoneLine);
                    softPhone.Close();
                    this.WireDownCallEvents();
                    call = null;
                    m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.HangUp);
                }

                else if (e.Item == CallState.Busy || e.Item == CallState.Error) {
                    m_RingTimeOut = true;
                    m_StartTimeOutCounter = false;
                    m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.Busy);
                    //softPhone.UnregisterPhoneLine(phoneLine);
                    softPhone.Close();
                    call.HangUp();
                    call = null;
                    //MessageBox.Show("Error encountered. Please check the format of the number you are calling.", "Bright Sales", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //this.WireDownCallEvents();
                    //call = null;
                }

                if (CallState_Changed != null)
                    CallState_Changed(this, new CallStateChangedArgs() {
                        PhoneCallState = e.Item,
                        AudioId = AudioId
                    });
            });
        }
Exemple #14
0
        private void call_CallStateChanged(object sender, VoIPEventArgs<CallState> e)
        {
            callstate = e.Item;

                if (e.Item == CallState.Ringing)
                {
                    m_TimeStart = DateTime.Now.TimeOfDay;
                    m_StartTimeOutCounter = true;
                    m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.Ring);
                }

                else if (e.Item == CallState.InCall)
                {
                    try
                    {
                        m_StartTimeOutCounter = false;
                        m_MediaUtility.Stop();
                        recorder.StartStreaming();
                        //recorder.IsStreaming = true;
                    }
                    catch (Ozeki.Common.Exceptions.MediaException me)
                    {

                        if (CallState_Changed != null)
                        {
                            AudioId = Guid.Empty;
                            CallState_Changed(this, new CallStateChangedArgs()
                            {
                                PhoneCallState = CallState.Rejected
                            });
                        }
                        if (call != null)
                            call.HangUp();

                        //softPhone.UnregisterPhoneLine(phoneLine);
                        softPhone.Close();
                        this.WireDownCallEvents();
                        call = null;

                        m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.HangUp);
                        MessageBox.Show("Your mic or speaker is not working. Please change your mic or speaker in the Phone Settings.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }

                else if (e.Item == CallState.Completed)
                {
                    try
                    {
                        recorder.StopStreaming();
                        //recorder.IsStreaming = false;

                        EndCall();

                        if (m_RingTimeOut)
                            return;

                        this.WireDownCallEvents();
                        call = null;
                        recorder.Dispose();
                        recorder = null;
                        CommonApplicationData commonData = new CommonApplicationData("BrightVision", "BrightSales", true);
                        string fileNameTmp = String.Format(@"{0}\tmpwav\{1}_.wav", commonData.ApplicationFolderPath, AudioId);
                        string fileNameCache = String.Format(@"{0}\cachewav\{1}_.wav", commonData.ApplicationFolderPath, AudioId);
                        File.Copy(fileNameTmp, fileNameCache);

                        m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.HangUp);

                    }
                    catch
                    {
                        //softPhone.UnregisterPhoneLine(phoneLine);
                        softPhone.Close();
                        this.WireDownCallEvents();
                        call = null;
                    }
                }

                else if (e.Item == CallState.Cancelled)
                {
                    AudioId = Guid.Empty;
                    EndCall();
                    if (m_RingTimeOut)
                        return;

                    m_StartTimeOutCounter = false;
                    //softPhone.UnregisterPhoneLine(phoneLine);

                    this.WireDownCallEvents();
                    call = null;
                    m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.HangUp);
                }

                else if (e.Item == CallState.Rejected)
                {
                    AudioId = Guid.Empty;
                    EndCall();
                    m_StartTimeOutCounter = false;
                    //softPhone.UnregisterPhoneLine(phoneLine);

                    this.WireDownCallEvents();
                    call = null;
                    m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.HangUp);
                }

                else if (e.Item == CallState.Busy || e.Item == CallState.Error)
                {
                    AudioId = Guid.Empty;
                    EndCall();
                    m_RingTimeOut = true;
                    m_StartTimeOutCounter = false;
                    m_MediaUtility.Start(MediaUtility.ePhoneCallSoundType.Busy);
                    //softPhone.UnregisterPhoneLine(phoneLine);
                    softPhone.Close();
                    call.HangUp();
                    call = null;
                    //MessageBox.Show("Error encountered. Please check the format of the number you are calling.", "Bright Sales", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //this.WireDownCallEvents();
                    //call = null;
                }

                if (CallState_Changed != null)
                {
                    CallState_Changed(this, new CallStateChangedArgs()
                    {
                        PhoneCallState = e.Item,
                        AudioId = AudioId
                    });
                }
        }
Exemple #15
0
        public void CreateCall(string pPhoneNo, int pPhoneRingTimeOut = 30)
        {
            if (pPhoneRingTimeOut > 0)
                m_RingingTimeOut = pPhoneRingTimeOut;

            m_RingTimeOut = false;
            m_PhoneNo = pPhoneNo;

            m_UserMicrophone.Start();
            connector.Connect(m_UserMicrophone, mediaSender);

            AudioId = Guid.NewGuid();
            CommonApplicationData commonData = new CommonApplicationData("BrightVision", "BrightSales", true);
            m_UserMicrophone.Start();
            string fileNameTmp = String.Format(@"{0}\tmpwav\{1}_.wav", commonData.ApplicationFolderPath, AudioId);
            recorder = new WaveStreamRecorder(fileNameTmp);
            recorder.Stopped += new EventHandler<EventArgs>(recorder_Stopped);

            connector.Connect(m_UserMicrophone, mixer);
            connector.Connect(mediaReceiver, mixer);
            connector.Connect(mixer, recorder);
            m_UserSpeaker.Start();
            connector.Connect(mediaReceiver, m_UserSpeaker);

            call = softPhone.CreateCallObject(phoneLine, m_PhoneNo);
            mediaSender.AttachToCall(call);
            mediaReceiver.AttachToCall(call);

            this.WireUpCallEvents();
            //System.Threading.Thread.Sleep(1500);
            call.Start();
            //softPhone.RegisterPhoneLine(phoneLine);
            //this.InitializeSoftPhone();
        }
Exemple #16
0
        void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            InvokeGUIThread(() => { lbl_CallState.Text = e.State.ToString(); lblEstatusLlamada.Text = e.State.ToString(); });

            if (e.State == CallState.Answered)
            {
                InvokeGUIThread(() => {
                    wplayer.controls.stop();
                    crearFolio();
                    ALlamadaData.bCurso = true;

                    string sRuta = string.Format(@"{0}\mpy\records\nws", Path.GetTempPath());
                    if (!Directory.Exists(sRuta))
                    {
                        Directory.CreateDirectory(sRuta);
                    }
                });

                StartDevices();
                SendDTMFSingnal();

                sFechaInicio = DateTime.Now;
                sRecordName  = AProspeccionData.bCurso ? string.Format("pcll-{1}.wav", Path.GetTempPath(), AProspeccionData.iIdLlamada) : string.Format("Folio-{0}-{1}{2}{3}{4}{5}{6}.wav", iIdFolio, sFechaInicio.Day, sFechaInicio.Month, sFechaInicio.Year, sFechaInicio.Hour, sFechaInicio.Minute, sFechaInicio.Second);
                filename     = string.Format(@"{0}\mpy\records\nws\{1}", Path.GetTempPath(), sRecordName);

                recorder = new WaveStreamRecorder(filename);  // new recorder object
                _connector.Connect(_microphone, recorder);    // connects the outgoing voice to the recorder
                _connector.Connect(_mediaReceiver, recorder); // connects the incoming voice to the recorder

                _mediaSender.AttachToCall(_call);
                _mediaReceiver.AttachToCall(_call);
                recorder.Start();  // starts the recording

                InvokeGUIThread(() => {
                    timer1.Start();
                    txtDisplay.Text     = "" + ((IPhoneCall)sender).DialInfo.SIPCallerID.DisplayName;
                    lblExtEntrante.Text = "" + ((IPhoneCall)sender).DialInfo.SIPCallerID.DisplayName;

                    if (!AProspeccionData.bCurso)
                    {
                        // Valida despues de mostrar la modal para registrar la llamada
                        if (RegistrarLlamadaModal.Show(iIdFolio, filename) == DialogResult.Yes)
                        {
                            Cliente ACliente = new Cliente();
                            Caso NoCliente;
                            if (bSeguimiento)
                            {
                                NoCliente = new Caso().ClienteCaso(iIdFolioSeguimiento);
                            }
                            else
                            {
                                NoCliente = new Caso().ClienteCaso(iIdFolio);
                            }
                        }
                    }
                });
            }
            else if (e.State == CallState.InCall)
            {
                StartDevices();
            }

            if (e.State == CallState.LocalHeld || e.State == CallState.InactiveHeld)
            {
                StopDevices();
                InvokeGUIThread(() => {
                    lnkHold.Text         = "Unhold";
                    lnkHold.Image        = Properties.Resources.resume_button_48px;
                    lnkHold.NoFocusImage = Properties.Resources.resume_button_48px;
                });
            }
            else
            {
                InvokeGUIThread(() => {
                    lnkHold.Text         = "Hold";
                    lnkHold.Image        = Properties.Resources.pause_48px;
                    lnkHold.NoFocusImage = Properties.Resources.pause_48px;
                });
            }

            if (e.State.IsCallEnded())
            {
                StopDevices();

                _mediaSender.Detach();
                _mediaReceiver.Detach();

                WireDownCallEvents();

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

                _call = null;

                timer1.Stop();

                InvokeGUIThread(() => {
                    wplayer.controls.stop();
                    txtDisplay.Text     = String.Empty;
                    lblExtEntrante.Text = string.Empty;
                    lblTiempo.Text      = string.Empty;

                    if (pnlLlamada.Visible == true)
                    {
                        frmTelefono.Animate2(pnlLlamada, frmTelefono.Effect.Slide, 150, 360);
                        frmTelefono.Animate(pnlKeyPad, frmTelefono.Effect.Slide, 150, 360);
                    }

                    lnkPickUpInCall.Visible      = true;
                    lnkVolverLLamada.Visible     = false;
                    pnlTransferirLlamada.Visible = false;
                    txtNoTransferir.Text         = string.Empty;
                    lnkConfigurar.Enabled        = true;
                    lnkHangUp.Location           = new Point(150, 94);
                    AProspeccionData.bCurso      = false;

                    string sFilePath = "";
                    if (bSeguimiento && iIdFolioSeguimiento != 0)
                    {
                        sFilePath = string.Format(@"{0}\mpy\records\nws\Folio-{1}-{2}{3}{4}{5}{6}{7}.wav", Path.GetTempPath(), iIdFolioSeguimiento, sFechaInicio.Day, sFechaInicio.Month, sFechaInicio.Year, sFechaInicio.Hour, sFechaInicio.Minute, sFechaInicio.Second);
                        File.Move(filename, sFilePath);
                        CasoHistorial _UpdRecord = new CasoHistorial();
                        _UpdRecord.UpdateHistorialRecord(iIdHistorialFolio, sFilePath);
                    }

                    if (ALlamadaData.bCurso)
                    {
                        if (sFilePath == "")
                        {
                            string FullPath = string.Format("{0}/{1}/Records/", FTPCredentials.Path, ConnectionString.FolderConnection);
                            FTPServer.Upload(FullPath, FTPCredentials.User, FTPCredentials.Password, Path.GetFileName(filename), filename);
                            File.Delete(filename);
                        }
                        else
                        {
                            string FullPath = string.Format("{0}/{1}/Records/", FTPCredentials.Path, ConnectionString.FolderConnection);
                            FTPServer.Upload(FullPath, FTPCredentials.User, FTPCredentials.Password, Path.GetFileName(sFilePath), sFilePath);
                            File.Delete(sFilePath);
                        }
                        ALlamadaData.bCurso = false;
                    }
                });
            }
        }
        /// <summary>
        /// Indicates the introduction has finished. It's starts the voice record.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Narrator_IntroductionFinished(object sender, EventArgs e)
        {
            Narrator.Finished -= Narrator_IntroductionFinished;

            waveStreamRecorder =
                new WaveStreamRecorder(Path.Combine(Environment.CurrentDirectory,
                                                    string.Format("IVRVoiceMesage{0}.wav", DateTime.Now.ToFileTime())));

            OnIntroductionStarting(waveStreamRecorder);
            waveStreamRecorder.StartStreaming();

            Narrator.Finished += narrator_PostIntroductionFinished;
        }
        protected override void VadFilterVoiceDetected(object sender, EventArgs e)
        {
            if (IsSoundDetected)
                return;

            VadFilter.Enabled = false;
            var date = DateTime.Now.Year + "y-" + DateTime.Now.Month + "m-" + DateTime.Now.Day + "d-" +
                      DateTime.Now.Hour + "h-" + DateTime.Now.Minute + "m-" + DateTime.Now.Second + "s";

            string currentpath;
            if (String.IsNullOrEmpty(MotionDirectoryPath))
                currentpath = AppDomain.CurrentDomain.BaseDirectory + date + ".wav";
            else
                currentpath = MotionDirectoryPath + "\\" + date + ".wav";
            SoundFilePath = currentpath;
            WaveStreamRecorder = new WaveStreamRecorder(currentpath);

            Connector.Connect(_camera.AudioChannel, WaveStreamRecorder); // connects the voices to the recorder

            SoundTimer = new Timer();
            SoundTimer.Elapsed += ElapsedVoice;
            SoundTimer.Interval = Duration * 1000;
            SoundTimer.AutoReset = false;

            SoundTimer.Start();
            WaveStreamRecorder.Start();
            IsSoundDetected = true;
            Log.Motion("Sound detected");
            Log.Write("The detected sound will be saved at the location: " + currentpath);
        }
        /// <summary>
        /// Loads a wav file for playback.
        /// </summary>
        public void LoadRecordWavFile(string filePath)
        {
            if (!initialized)
                return;

            if (wavRecorder != null)
            {
                audioConnector.Disconnect(recordDataMixer, wavRecorder);
                wavRecorder.Dispose();
                wavRecorder = null;
            }

            wavRecorder = new WaveStreamRecorder(filePath);

            audioConnector.Connect(recordDataMixer, wavRecorder);
        }
 /// <summary>
 /// Stops the audio capturing
 /// </summary>
 public AudioRecordState StopRecord()
 {
     if (WaveStreamRecorder != null)
     {
         WaveStreamRecorder.StopStreaming();
         mediaConnector.Disconnect(RecordDataMixer, WaveStreamRecorder);
         WaveStreamRecorder.Dispose();
         WaveStreamRecorder = null;
     }
     return AudioRecordState.Stopped;
 }
        private void CreateWaveStreamRecorder(string path)
        {
            WaveStreamRecorder = new WaveStreamRecorder(path);

            mediaConnector.Connect(RecordDataMixer, WaveStreamRecorder);
        }