Example #1
0
        /// <summary>
        /// Begins recording audio.
        /// </summary>
        /// <returns>true if recorder has started.</returns>
        public bool StartAudio()
        {
            if (prepared && !isRecording)
            {				
                if (audioRecorder.RecordingState == RecordState.Recording)
                {
                // Not all devices have a noise suppressor
                    if (NoiseSuppressor.IsAvailable && isNoiseSupression)
                    {
                        noiseSuppressor = NoiseSuppressor.Create(audioRecorder.AudioSessionId);

                        // Differences on some platforms according to API?
                        if (noiseSuppressor.Enabled == false)
                        {
                            noiseSuppressor.SetEnabled(true);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Start was called, but the auio recorder was not ready to be started.");
                    }
               }
               else
               {
                   Console.WriteLine("Noise suppression is not enabled on this device.");
               }

                isRecording = true;
                audioRecorder.StartRecording();

               // Allows us to write audio data to a file alongside recording.
               // We have to do this as noise suppression isn't supported with MediaRecorder.
               ThreadPool.QueueUserWorkItem(o => WriteAudioDataToFile());

              

               return true;
            }
            else
            {
                return false;
            }
        }
Example #2
0
        /// <summary>
        /// Stops recording audio and saves data to file.
        /// </summary>
        /// <returns>true if audio was recording and has been stopped.</returns>
        public bool StopAudio()
        {
            if (prepared && isRecording)
            {
                if (audioRecorder.RecordingState == RecordState.Recording)
                {
                    isRecording = false;
                    audioRecorder.Stop();

                    if (noiseSuppressor != null)
                    {
                        noiseSuppressor.Release();
                        noiseSuppressor.Dispose();
                        noiseSuppressor = null;
                    }

                    return true;
                }
                else
                {
                    Console.WriteLine("Stop was called, but the audio recorder was not ready to be stopped.");
                    return false;                    
                }
            }
            else
            {
                return false;
            }
        }