// Check if the app has mic permissions. If not, query user for access
        private async Task CheckAndEnableMic()
        {
            bool isMicAvailable = true;

            try
            {
                var mediaCapture = new Windows.Media.Capture.MediaCapture();
                var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                isMicAvailable = false;
            }
            if (!isMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }
            else
            {
                UpdateUI(() =>
                {
                    this.Messages.Add(new MessageDisplay("Microphone enabled", Sender.Other));
                });
            }
        }
        public async Task <bool> GetPermissionsAsync()
        {
            var isMicAvailable = true;

            try
            {
                using (var mediaCapture = new Windows.Media.Capture.MediaCapture())
                {
                    var settings = new Windows.Media.Capture.MediaCaptureInitializationSettings
                    {
                        StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio
                    };
                    await mediaCapture.InitializeAsync(settings);
                }
            }
            catch (Exception)
            {
                isMicAvailable = false;
            }

            if (!isMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }

            return(isMicAvailable);
        }
        private static async Task EnsureMicIsEnabled()
        {
            bool isMicAvailable = true;

            try
            {
                var mediaCapture = new Windows.Media.Capture.MediaCapture();
                var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                isMicAvailable = false;
            }

            if (!isMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }
            else
            {
                Trace.WriteLine("Microphone already enabled");
            }
        }
Esempio n. 4
0
        public static async Task EnableMicrophone()
        {
            if (IsMicAvailable)
            {
                return;
            }

            IsMicAvailable = true;
            try
            {
                var mediaCapture = new Windows.Media.Capture.MediaCapture();
                var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                IsMicAvailable = false;
            }

            if (!IsMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }
            else
            {
                Debug.WriteLine("Microphone was enabled");
            }
        }
Esempio n. 5
0
        private async void EnableMicrophoneButton_Click(object sender, RoutedEventArgs e)
        {
            bool isMicAvailable = true;

            try
            {
                var mediaCapture = new Windows.Media.Capture.MediaCapture();
                var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                isMicAvailable = false;
            }
            if (!isMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }
            else
            {
                NotifyUser("Microphone was enabled", NotifyType.StatusMessage);
                this.EnableMicrophoneButton.IsEnabled = false;
                this.RecognizeKeywordButton.IsEnabled = true;
            }
        }
Esempio n. 6
0
        private static async Task SetupCapturMedia()
        {
            var mediaCapture = new Windows.Media.Capture.MediaCapture();
            var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();

            settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
            await mediaCapture.InitializeAsync(settings);
        }
 private async void EnableMicrophone()
 {
     try
     {
         var mediaCapture = new Windows.Media.Capture.MediaCapture();
         var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
         settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
         await mediaCapture.InitializeAsync(settings);
     }
     catch (Exception)
     {
         MyMessageBox("No se pudo inicializar el micrófono");
     }
 }
 private async Task CheckMicSettings()
 {
     try
     {
         var mediaCapture = new Windows.Media.Capture.MediaCapture();
         var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
         settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
         await mediaCapture.InitializeAsync(settings);
     }
     catch (Exception exp)
     {
         LogOutput($"Error initialing mic: {exp}");
     }
 }
Esempio n. 9
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();
                }
            }
        }
        /// <summary>
        /// Open Microphone
        /// </summary>
        private async void EnableMicrophone()
        {
            bool isMicAvailable = true;

            try
            {
                var mediaCapture = new Windows.Media.Capture.MediaCapture();
                var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                isMicAvailable = false;
            }
            if (!isMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }
            else
            {
                NotifyUser("Microphone was enabled", NotifyType.StatusMessage);
            }
        }