Monday, May 26, 2014

Processing audio from the microphone in realtime

I want to process audio in realtime from the microphone, but the documentation is so incomplete that it is impossible to figure out how to do it. I believe I need to use MediaCapture.PrepareLogLagRecordToStreamAsync. Note this needs to work on both Windows 8.1 and WP 8.1.


Unfortunately the only samples I found simply saves the recording to a file, however I need to be able to stream the data into memory so that I can process it in realtime. I tried using InMemoryRandomAccessStream and can retrieve the first second or so of data after which it stops.


This is what I'm doing right now:



var capture = new MediaCapture();
var stream = new InMemoryRandomAccessStream();
var settings = new MediaCaptureInitializationSettings();
var profile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Auto);

settings.StreamingCaptureMode = StreamingCaptureMode.Audio;
await capture.InitializeAsync(settings);

var recording = await capture.PrepareLowLagRecordToStreamAsync(profile, stream).AsTask();

await recording.StartAsync().AsTask();

Can someone show me how to then continuously retrieve the data from the stream? It only works for a second or so after which new data stops being recorded into the stream. Do I need to call PrepareLowLagRecordToStreamAsync after each time I read the data out of the stream?






No comments:

Post a Comment