1

I am trying to record audio on my Rasp Pi 3 running Windows 10 IoT. I am recording audio to store in USB drive. Can anyone help to advise what did I do wrong. Thanks in advance.

 private async void RecordBtn_Checked(object sender, RoutedEventArgs e)
    {
        //init mediacapture
        audioCapture = new MediaCapture();
        await audioCapture.InitializeAsync();

        StorageFolder externalDevices = KnownFolders.RemovableDevices;
        IReadOnlyList<StorageFolder> externalDrives = await externalDevices.GetFoldersAsync();
        StorageFolder usbStorage = externalDrives[0];

        var recordFolder = await usbStorage.CreateFolderAsync("Recording");

        StorageFile recordFile = await recordFolder.CreateFileAsync("record.mp3", Windows.Storage.CreationCollisionOption.GenerateUniqueName);

        audioRecording = await audioCapture.PrepareLowLagRecordToStorageFileAsync(MediaEncodingProfile.CreateMp3(AudioEncodingQuality.High), recordFile);

        await audioRecording.StartAsync();

        isRecording = true;
        RecordStatus.Text = "Recording ... ";

        //PlayRec.IsEnabled = StopRec.IsEnabled = false;


    }

 private async void RecordBtn_Unchecked(object sender, RoutedEventArgs e)
    {
        if (isRecording)
        {
            await audioRecording.StopAsync();
            isRecording = false;

            await audioRecording.FinishAsync();
            RecordStatus.Text = "Recording stopped.";

            //PlayRec.IsEnabled = StopRec.IsEnabled = true;
        }

    }
mylim
  • 313
  • 4
  • 16

1 Answers1

2

If you want to capture audio only, try the following:

audioCapture = new 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;  
await audioCapture.InitializeAsync(settings);  

Also make sure you have set the right capabilities in your Package.appxmanifest file:

<Capabilities>      
   <DeviceCapability Name="microphone" />  
</Capabilities>  

Check this tutorial out, it has some good examples:

https://learn.microsoft.com/en-us/samples/microsoft/windows-iotcore-samples/webcam-app/

user2986756
  • 89
  • 1
  • 9
Isma
  • 14,604
  • 5
  • 37
  • 51
  • Thanks man! it works! can i know what is the reason behind it? – mylim Sep 19 '17 at 09:47
  • Did you have to add the capabilities or the settings? – Isma Sep 19 '17 at 09:48
  • I have already added the capabilities .. just wondering why my init process down't work .. do i have to setup all the parameters like in your example? – mylim Sep 19 '17 at 09:49
  • May be you don't have a Webcam, if you don't set the settings like in the answer it will try to initialize video too... – Isma Sep 19 '17 at 09:53
  • understood.. is that why it went in a loop waiting for camera ? – mylim Sep 19 '17 at 09:55
  • Can i ask additional question is I need a progress time lapse for the recording.. how can i achieve that? typically what do people use? progress bar or textblock? Sorry I have to put it this way.. because I am kind of lost and not really sure how to phrase it .. – mylim Sep 20 '17 at 10:04