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

How to WAV using G.711 RTP record?

Jan 12, 2014 at 3:16 AM
How to WAV using G.711 RTP record?

I am receiving the RTP attempts to record to WAV.
It has been well documented.

Wav files but containing quite a lot of noise.
(It almost can not hear)
However, Wireshark is a very clean, renewable

How I can I get a clean recording file?

"RTP 214 PT=ITU-T G.711 PCMA, SSRC=0x5EA83D50, Seq=30570, Time=1599766842 "

my source , in c#

if (wavOutput == null)
                {

                    wavOutput = new WaveFileWriter("Calls\\" + CallID + ".wav", new WaveFormat(8000, 16, 1));
                }
udpPacket.PayloadData.Length.ToString());
                for (int index = 0; index < udpPacket.PayloadData.Length; index++)
                {

                     short pcm = MuLawDecoder.MuLawToLinearSample(udpPacket.PayloadData[index]);

                    wavOutput.WriteByte((byte)(pcm & 0xFF));
                    wavOutput.WriteByte((byte)(pcm >> 8));


                }
What should I do now?
How do I extract the clean speech


I saved WAV file processing?

How do I apply codec?

I am using C #, I am beginner

Ask me a sample of the work.
Coordinator
Jan 13, 2014 at 10:18 AM
you'll need to extract the compressed audio from the RTP packet - don't also try to decode the headers.
Also check your bit manipulation is correct. Use BitConverter.GetBytes(pcm) and then write that using wavOutput.Write(bytes, 0, 2)
Jan 13, 2014 at 2:50 PM
I am a beginner

I need a few samples.

SIPDUMP I got from a place called in the source

It works well, but just can not hear the voice.

I tried all night 3 days

Can you help me?

Thank you. ^^;
Coordinator
Jan 15, 2014 at 10:56 AM
well the first step is extracting the audio out of the RTP packet. NAudio does not do this. What are you using to do that?
Sep 11, 2014 at 2:53 PM
I am able to record wave file using above mentioned code.
but containing quite a lot of noise.
I am looking for help to reduce noise from recording.
Sep 12, 2014 at 4:15 PM
according to your description the data is aLaw PCM but you use the uLaw decoder...maybe thats already it...
Sep 17, 2014 at 12:26 PM
Edited Sep 17, 2014 at 1:53 PM
If i use ALawDecoder I don't get any audio.... hence I use MuLawDecoder and getting audio but with a lot of noise....

for (i = 0; i < receiveBytes.Length; i++)
                    {


                            if (i >= 12)
                            {

                                /*
                                short pcm = ALawDecoder.ALawToLinearSample(receiveBytes[i]);
                                wfWriter.WriteByte((byte)(pcm & 0xFF));
                                wfWriter.WriteByte((byte)(pcm >> 8));*/

                                short pcm = MuLawDecoder.MuLawToLinearSample(receiveBytes[i]);

                                wfWriter.WriteByte((byte)(pcm & 0xFF));
                                wfWriter.WriteByte((byte)(pcm >> 8));


                            }

                    }
Sep 18, 2014 at 10:29 AM
hm.... Did you verify the RTP audio data to be correct, e.g. playing a captured stream via wireshark?

In general I think you should be able to hear something if you use the alaw decoder on mulaw PCM data (and vice versa), except for some really weird special cases of the input signal
Sep 18, 2014 at 11:59 AM
I am able to hear audio but I also hear background noise a lot.
Sep 18, 2014 at 12:26 PM
well, if the RTP stream data already contains a lot of noise, the recording of the decoded PCM data will also contain the noise
Sep 26, 2014 at 9:28 AM
just letting you know, I had the same problem: RTP stream after ALaw decoding had a strange noise, which otherwise shouldn't be there. This happened because I wasn't removing the RTP header (first 12 bytes) from the received byte array, and was playing those 12 bytes also on the speakers which gave me the noise.
Sep 26, 2014 at 10:17 AM
But I am already removing the first 12 bytes from the received array... but still getting noise....

wfWriter = new WaveFileWriter(recordedFileName.Text, new WaveFormat(8000, 16, 1));
.
.
.
for (i = 0; i < receiveBytes.Length; i++)
                {
                        if (i >= 12)
                        {
                            /*
                            short pcm = ALawDecoder.ALawToLinearSample(receiveBytes[i]);
                            wfWriter.WriteByte((byte)(pcm & 0xFF));
                            wfWriter.WriteByte((byte)(pcm >> 8));*/

                            short pcm = MuLawDecoder.MuLawToLinearSample(receiveBytes[i]);

                            wfWriter.WriteByte((byte)(pcm & 0xFF));
                            wfWriter.WriteByte((byte)(pcm >> 8));


                        }

                }
Sep 26, 2014 at 10:18 AM
But I am already removing the first 12 bytes from the received array... but still getting noise....

wfWriter = new WaveFileWriter(recordedFileName.Text, new WaveFormat(8000, 16, 1));
.
.
.
for (i = 0; i < receiveBytes.Length; i++)
            {
                    if (i >= 12)
                    {
                        /*
                        short pcm = ALawDecoder.ALawToLinearSample(receiveBytes[i]);
                        wfWriter.WriteByte((byte)(pcm & 0xFF));
                        wfWriter.WriteByte((byte)(pcm >> 8));*/

                        short pcm = MuLawDecoder.MuLawToLinearSample(receiveBytes[i]);

                        wfWriter.WriteByte((byte)(pcm & 0xFF));
                        wfWriter.WriteByte((byte)(pcm >> 8));


                    }

            }
Sep 26, 2014 at 11:53 AM
Yes, you are right. You are doing the same as I do. So, if you have noise, than it means there is noise in the original audio. For example my client was complaining about hearing noise beside the correct audio data and it turned out it was the usb sound card. So you might need to check the audio device you are using. Also try to use some noise filtering algorithm, that might help.
Sep 26, 2014 at 11:59 AM
Edited Sep 26, 2014 at 12:00 PM
Then let me check my sound card.... Thanks!!!!