Click here to Skip to main content
15,937,602 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hey, I'm really stumped on this and it just seems like I'm missing something obvious.

I'm trying to implement a feature in a C# windows store app that allows you to speak through the microphone and that sound to come out of the speakers in real-time.
Recording sound to a file for later playback was a piece of cake, but no matter what I try I can't get it to play back immediately. This is really easy on non-store apps using NAudio, but unfortunately there is no support for that yet.

I'm using a mediacapture object to record to a stream, and then using that stream as the source of a mediaelement object, but this doesn't work.

MediaCapture input = new MediaCapture()
MediaCaptureInitializationSettings inputSettings = new MediaCaptureInitializationSettings();
MediaEncodingProfile encodingProfile = new MediaEncoding Profile();
InMemoryRandomAccessStream recStream = new InMemoryRandomAccessStream();
MediaElement playback = new MediaElement();

inputSettings.AudioDeviceId = "";
inputSettings.StreamingCaptureMode = StreamingCaptureMode.Audio;
await input.InitializeAsync(inputSettings);
encodingProfile = MediaEncodingProfile.CreateWma(AudioEncodingQuality.Auto);

playback.RealTimePlayback = true;
playback.AudioCategory = AudioCategory.Communications;

await input.StartRecordToStreamAsync(encodingProfile, recStream);
playback.SetSource(recStream, "audio/x-ms-wma");

This code works if i change it to record to a storage file, so I know the device is set up ok.

Has anyone done anything like this on Windows 8 before? Any help would be greatly appreciated.
Yvan Rodrigues 20-Aug-13 11:51am    
Did you find a solution? I'm trying to solvethe same problem.
paul_b 20-Aug-13 11:54am    
No I didn't, Sorry. Might take another look at this as it's something I wouldn't mind picking up again.
Yvan Rodrigues 20-Aug-13 12:18pm    
I just noticed that there is a sample in the Windows 8 App samples called Real-time Communication Sample that uses a low-latency mode. I'll take a look.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900