简体   繁体   中英

Windows IoT Raspberry Pi 3 c# Recording Audio

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;
        }

    }

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://docs.microsoft.com/en-us/samples/microsoft/windows-iotcore-samples/webcam-app/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM