This project has moved. For the latest updates, please go here.

compress audio input

Apr 17, 2013 at 3:32 PM
Edited Apr 17, 2013 at 3:32 PM
i'm doing a project which concerns an audio chat, but not understand how to do some things:
I capture the audio through microphone with "wavein" into the buffer type "BufferedWaveProvider", but I need that the file is lightweight, because I should send it.
how i do it ??, how compress it ??
sorry for my english.
Dim inp As WaveIn
Dim sampleRate As integer = 8000
Dim channels As Integer = 1
Dim bitrate As Integer = 16
Dim wav As New WaveFormat(sampleRate,bitrate,channels)
Dim buffer As New BufferedWaveProvider(wav)

//here start recording
inp=New WaveIn()
inp.WaveFormat = New WaveFormat(sampleRate,bitrate,channels)
AddHandler inp.DataAvailable, AddressOf upd
Apr 18, 2013 at 4:14 PM
I've written an article explaining how you can compress audio in .NET. There are lots of options depending on how compressed you want the audio to be.
Apr 19, 2013 at 10:16 AM
thanks for the reply.
I want a format suitable for speech coding, I thought a gsm or advise me.

I had already seen that article, but I do not understand how to compress the same, can you do me a simple example please?

it is possible to capture the audio already compressed, or do I have to catch it in pcm and then compress it?
Apr 20, 2013 at 9:06 AM
You will have to capture the audio in uncompressed form. Afterwards you can use the WaveFormatConversionStream to apply compression on the captured steam.

I can recommend the use of Speex for compressing audio. On the website ( you will find a download for the acm driver that is needed for the WaveFormatConversionStream.
Apr 20, 2013 at 2:36 PM
ok, but I do not understand how to convert from "BufferedWaveProvider" to "WaveStream," how I do it?
Apr 21, 2013 at 6:10 PM
A WaveProvider is a WaveStream that cannot be repositioned and whose length is unknown. So you would not normally convert, although if you wanted you could make an adapter class in which repositioning does nothing. I usually convert to PCM before putting audio into the BufferedWaveProvider. If you look at the source code in the NAudio network chat demo you'll see the Acm classes being called at a lower level to decompress the audio, eliminating the need to use WaveFormatConversionStream.
Apr 24, 2013 at 10:29 PM
Edited Apr 24, 2013 at 10:31 PM
I saw the example of "network chat", but I have a problem ..
I capture the audio to pcm, and during the event "data_available" convert the bytes in GSM610 (for now), but:
Dim input As WaveFormat = WaveFormat.CreateCustomFormat (WaveFormatEncoding.Pcm, 8000,1,8000,1,8)
Dim output As WaveFormat = WaveFormat.CreateCustomFormat (WaveFormatEncoding.Gsm610, 8000,1,1625,65,0)
Dim encodeStream As AcmStream

//next in data_available
encodestream = New AcmStream (input, output)
I get the error "NAudio.MmException: AcmNotPossible calling acmStreamOpen"
But through the demo NAudio I saw that I installed the GSM610

Where I'm wrong?
Apr 25, 2013 at 3:42 PM
Your custom formats are probably not what the ACM codec is expecting. Use new Gms610WaveFormat for the outputFormat. For the inputFormat, it should be 16 bit PCM. so new WaveFormat(8000,16,1)
Apr 27, 2013 at 2:54 PM
really thanks, now it works.
I preferred the GSM6.10 because it is lighter in terms of cpu.
I have another problem, how can I increase the volume of input devices?
for those in the output:
waveout.volume = 100
Apr 27, 2013 at 5:53 PM
there is no uniform way to do this with the waveIn APIs, which is unfortunate. The mixer APIs in theory can let you get at the microphone gain, but in practice this can be really hard to do. This is because soundcards have lots of inputs of various kinds each with different capabilities.