示例#1
0
        private int intDelay = 200;  // Record Time in millesecond...
        // Short time - increase repetet noise ...
        // Long time - create echo ...
        // I think 200ms is optimum ...

        // If you use headphones - best time will be 500..1000ms ...


        private async void btnStart_Click(object sender, RoutedEventArgs e)
        {
            blnStart            = true;
            btnStart.Visibility = Visibility.Collapsed;
            btnStop.Visibility  = Visibility.Visible;

            textBlock.Visibility = Visibility.Visible;

            mediaCaptureAudioPrimery = new Windows.Media.Capture.MediaCapture();

            var settings = new Windows.Media.Capture.MediaCaptureInitializationSettings();

            settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
            settings.MediaCategory        = Windows.Media.Capture.MediaCategory.Other;
            settings.AudioProcessing      = Windows.Media.AudioProcessing.Default; // Use only Default

            await mediaCaptureAudioPrimery.InitializeAsync(settings);

            recordProfile = MediaEncodingProfile.CreateWav(Windows.Media.MediaProperties.AudioEncodingQuality.Low);


            while (blnStart)  // Repeate untile stop ...
            {
                try
                {
                    msIRAS0     = new MemoryStream();
                    streamIRAS0 = msIRAS0.AsRandomAccessStream();                                        // New Stream ...
                    await mediaCaptureAudioPrimery.StartRecordToStreamAsync(recordProfile, streamIRAS0); // write audio in first stream ...

                    await Task.Delay(intDelay);

                    await mediaCaptureAudioPrimery.StopRecordAsync();   // Stop first stream
                    await PlayThreadMethod(streamIRAS0);                // Play from first stream

                    msIRAS1     = new MemoryStream();
                    streamIRAS1 = msIRAS0.AsRandomAccessStream();                                        // Second Stream ...
                    await mediaCaptureAudioPrimery.StartRecordToStreamAsync(recordProfile, streamIRAS1); // sweetch stream ... to second stream ...

                    await Task.Delay(intDelay);

                    await mediaCaptureAudioPrimery.StopRecordAsync();
                    await PlayThreadMethod(streamIRAS1);                // Play Second Streem
                }
                catch (Exception ex)
                {
                    Stop();
                }
            }
        }
示例#2
0
        /// <summary>
        /// StopRecording method
        /// </summary>
        /// <param>
        /// Stop to record audio .
        /// The audio stream is still in stored in memory
        /// </param>
        /// <return>return true if successful.
        /// </return>
        public async System.Threading.Tasks.Task <bool> StopRecording()
        {
            // Stop recording and dispose resources
            if (mediaCapture != null)
            {
                if (isRecording == true)
                {
                    await mediaCapture.StopRecordAsync();

                    isRecording = false;
                }
            }
            return(true);
        }