Click here to Skip to main content
12,633,373 members (32,317 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Windows audio
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);

LayoutRoot.Children.Add(playback);
playback.RealTimePlayback = true;
playback.AudioCategory = AudioCategory.Communications;


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



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.
Posted 28-Nov-12 2:59am
paul_b520
Comments
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100