In this sample, you will see how to make an audio recorder app on windows 10 IoT Core.
Components needed:- 1 USB Mouse
- 1 HDMI Monitor and HDMI cable
- 1 Raspberry Pi2 Board
- Connect the USB headset, USB mouse, HDMI montior, Ethernet cable (or WiFi dongle if you are using WiFi ) to Raspberry Pi 2, and then power it on.
- Download the sample, build it and deploy on Raspberry Pi 2.
- You will see how the app runs on Raspberry Pi 2.
App Built Core Steps:
1. Open VS 2015, create a new Windows Universal Blank App:
2. Enable the capabilities in the package.appxmanifest
as below. Make sure Microphone
and VideoLibrary
(where we will save the audio file) and Webcam
capability selected:
3. In MainPage.xaml
, add three buttons (startRecord,endRecord,PlayRecordedAudio) and one MediaElement. The MediaElement will be used to play recorded audio:
<Button Click="startRecord" Content="Start To Record" Margin="50,50,0,10"/>ode> <Button Click="endRecord" Content="End Record" Margin="50,10,0,10"/>ode> <Button Click="playRecordedAudio" Content="Play Recorded Audio" Margin="50,10,0,10"/>ode><MediaElement x:Name="media" Margin="0,10,0,10" Width="100"ode> Height="300"ode> AreTransportControlsEnabled="False"ode> AutoPlay="True">ode> </MediaElement>
4. In MainPage.xaml.cs
, you will need to:
- Enumerate to find audio recording device:
var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.AudioCapture);ode>
- Initialize the CaptureSetting and MediaCapture setting:
captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
captureInitSettings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.AudioAndVideo;
audioCapture = new Windows.Media.Capture.MediaCapture();
await audioCapture.InitializeAsync(captureInitSettings);
- Start recording:
var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync("audioOut.mp3", Windows.Storage.CreationCollisionOption.GenerateUniqueName);
profile = MediaEncodingProfile.CreateM4a(Windows.Media.MediaProperties.AudioEncodingQuality.Auto);
await audioCapture.StartRecordToStorageFileAsync(profile, storageFile);
- End recording:
await audioCapture.StopRecordAsync();
- Play recorded audio:
Windows.Storage.StorageFile storageFile = await Windows.Storage.KnownFolders.VideosLibrary.GetFileAsync(audioFileName);
var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
if (null != stream)
{
media.SetSource(stream, storageFile.ContentType);
media.Play();
}
Once the project is coded and setup, you should be able to record the audio and play it back.
Comments