WAV file saved is not playable.. no usefulness here

Jun 12, 2010 at 6:40 PM
Thanks for the effort - but I find little value in the example/demo that's included.. Here the audio from the mic is supposedly live-ended to speex in-memory, and an option to save it to a file is presented.. However this option decodes the in-memory stream to a WAV file and saves that.... The wav file that gets saved isn't even playable.. it's corrupt or invalid in some way. Also, there's no way to save the Speex-encoded audio to a file.. or even an indication of what's missing. There is a huge need for audio-encoding capabilities in Silverlight, I've been workin on this issue for some time and am willing to contribute and help. Thanks, Bobby
Nov 24, 2010 at 3:04 PM

Yes, I'm experiencing the same issue.  I had a look at the .wav file and its data segment is 0 length...  Not quite sure why, but that's why its not playing anything.  I'm going to take a closer look.

Dec 26, 2011 at 2:12 PM

yes, i am also facing such type of problem in using it. in this i have found Zero length of wav file when my speak is too short or few seconds, and when i use this for huge speak it works but in wav file i dint found last few words which i spoke at last in recording time. if you have any solution for getting all the recording words please give me your suggestion.

Apr 6, 2012 at 12:36 AM

probably it isn't adding the WAV file header - see the helper class you can use for adding that header at

http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-camera-and-microphone-support.aspx

Apr 6, 2012 at 12:38 AM
Edited Aug 4, 2012 at 4:17 PM

maybe it doesn't decode to flat PCM (for saving to WAV file with the header-adding helper I mention above)?

Aug 4, 2012 at 4:16 PM
Edited Aug 4, 2012 at 4:17 PM

To decode an encoded stream and play it you obviously need a Speex decoder class that CSpeex should provide

Aug 4, 2012 at 4:55 PM
Edited Aug 4, 2012 at 5:18 PM

The SLAudioDemo saves a WAV fine for me (see ISSUE TRACKER for my fix to compile for Silverlight 5)

The WAV is uncompressed, since SLAudioDemo seems to compress in memory (via StreamAudioSink) and decompress to normal PCM WAV when you save (else it would be unplayable). Obviously the code is useful for uploading compressed audio to a server (or the other end at some voice chat app) and decompress there before storage/playback (similarly the other way arround). At the server side btw you could also keep an extra decoded copy of the compressed CSpeex audio data, recoded into WMA using automation of Microsoft Expression Encoder for example (see Microsoft Transform Manager, can do this in the background if you uncompress into WAV at some temp/incoming folder)

For the encoding see StreamAudioSink.cs. Only 2 lines are needed (as you can see at MainPage.xaml.cs):

           streamAudioSink = new StreamAudioSink();
 
           streamAudioSink.CaptureSource = _captureSource;

after you 1st declare at the top level (must have this as a top-level field, else the garbage collector can get it)

private StreamAudioSink streamAudioSink;
 
Here's the decoding code that saves the WAV (from MainPage.xaml.cs):
                if (sfd.ShowDialog() == true)
                {
                    // User selected item. Only property we can get to is.
                    using (Stream stream = sfd.OpenFile())
                    {
                        JSpeexDec decoder = new JSpeexDec();
                        decoder.setDestFormat(JSpeexDec.FILE_FORMAT_WAVE);
                        decoder.setStereo(true);
 
                        Stream memStream = streamAudioSink.MemFile.InnerStream;
                        memStream.Position = 0;
 
                        decoder.decode(new RandomInputStream(memStream), new RandomOutputStream(stream));
 
                        stream.Close();
                    }
                }