views:

891

answers:

4

I've written a basic SL4 application to capture audio data from the microphone using CaptureSource. The trouble is, it's raw PCM output - which means huge and uncompressed.

Given that I need this application to run purely within a SL4 environment, how can I compress the PCM audio data into something that can be delivered to a remote server more easily?

Essentially I need a solution that I can also deploy/include in a Windows Phone Series 7 application as well as one that will work in the browser environment - so managed code solutions only, I think?

In conversation, people have suggested Speex and WMA for instance, but I haven't found any libraries or examples that work without requiring reference to DLL's that won't work in a SL4 project.

A: 

This article http://alvas.net/alvas.audio,articles.aspx#how-to-save-audio-to-mp3-on-silverlight about save audio on client. To send audio data to a server you can use WebClient, for example.

alex
Thanks; what I'm after though is a purely .NET managed solution with no third party components that aren't specifically targeted at the SL4 platform. I need a solution that will work on Windows Phone Series 7, too.
Richard
+2  A: 

Please see the WavFileHelper class in Silverlight 4 Rough Notes: Camera and Microphone Support on Mike Taulty's blog (a bit lower than the middle of the page, but the full article is worthwhile) in which he compresses the PCM file to WAV.

Here's another example of when writing to WAV you can change values such as Mono/Stereo, which will directly change the size of the WAV file: Audio recorder Silverlight 4 sample. And one more that gives more details about writing to WAV: Creating Sound using MediaStreamSource in Silverlight 3 Beta

Otaku
Thanks, these are all articles that I've seen though. One thing to bear in mind here, is my requirement that I need to "compress the PCM audio data into something that can be delivered to a remote server more easily". Converting PCM to WAV is easy, but compressing the output isn't. WAV is undesirable because it is so bloaty, even if you encode it as mono. Mike Taulty's blog is great at showing how to use the sinks to capture PCM and convert to WAV, but I guess what we really need here is a MediaStreamSource or something similar that outputs as Speex or WMA.
Richard
@Otaku - I have accepted your answer; it was the most comprehensively sourced. A lot more still needs to be done though, and I will try to update this article at some point in the future with my actual answer. Thanks for your input.
Richard
@Richard - thank you! I hear ya on the need for something much more compact than WAV. I'll keep this front of mind as well as I run into things and if something better comes along, I'll update the answer.
Otaku
@Richard - haven't had a chance to look at this in too much detail, but this looks of interest: http://silverlightencoder.codeplex.com
Otaku
@Otaku - thanks for the pointer, I'll try and have a look at that soon!
Richard
+1  A: 

Take a look at this. It looks like he has ported the Speex encoder to C# for the exact problem you are trying to solve. It is available here. Speex is designed for speech and should perform better than wma, mp3, or other audio codecs that are designed to handle music if you are just encoding speech, which I assume since you are grabbing from the mic.

Jason
Thanks Jason. I've seen this before - I will have to revisit it and see if it works; I forget the exact reason I discounted it first time around!
Richard
A: 

You can do encoding thru the server, by send all stream to WCF service and do your encoding thru Microsoft Expression Encoding SDK API.

Please, see this url that i have asked before: http://forums.silverlight.net/forums/t/181141.aspx

Regards

Thanks, but the point is to compress it *before* it gets sent to the server.
Richard