Using NSpeex for Silverlight

Sep 30, 2010 at 6:17 AM


I am trying to use NSpeex with Silverlight 4.0 to encode the audio file. But I can't succeed and I don't have a clear idea of doing it. Can you please provide me the sample code or tell how to proceed? Your help is greatly appreciated.

Sep 30, 2010 at 6:57 AM
Edited Sep 30, 2010 at 7:32 AM


what exactely are you trying to do? Are you reading a local file and transcode it to a speex encoded file or are you capturing data (from a microphone) and want to save the encoded data into an audio file? Also, how do you want to read the audio file again, through an external player or using your own code?

There are many possible ways and depending on the above questions the solution might be different! But basically, using the example code provided on the documentation page ( you must use the encoded data package and write it to a filestream. Now here we need the answers to the questions from above as the decoding part specifies the format in which we write the data into the file stream. If you write the decoding part yourself your are completey free to specify the format alternatively there are is an 

OggSpeexWriter and a PcmWaveWriter.

The wave writer can be used in conjunction with the Windows ACM codec.


Apr 14, 2011 at 10:01 PM

There's a problem with the WriteHeader() method of PcmWaveWriter.

Constructing a PcmWaveWriter object using the public PcmWaveWriter(int mode, int quality, int sampleRate, int channels, int nframes, bool vbr) constructor and passing 0 (NB) for mode results in an IndexOutOfRangeException when calling the WriteHeader(string) method later.

WriteHeader() calls CalculateEffectiveBitrate(int mode_0, int channels_1, int quality_2) and with mode_0 being 0...

private static int CalculateEffectiveBitrate(int mode_0, int channels_1, int quality_2)
	return ((((WAVE_FRAME_SIZES[mode_0 - 1, channels_1 - 1, quality_2] * WAVE_BITS_PER_FRAME[mode_0 - 1, channels_1 - 1, quality_2]) + 7) >> 3) * 50 * 8)
			/ WAVE_BITS_PER_FRAME[mode_0 - 1, channels_1 - 1, quality_2];



Apr 15, 2011 at 2:32 PM

Hi tranmq,

thank's for pointing that out! I just fixed it in the PcmWaveWriter.