11

I have an application for iPAD. This application records the voice of the microphone. The audio formats of the item must be PCM, MP3 and WAV files. The MP3 file I get it starting from the original raw file and then convert using LAME. Unfortunately I have not found any example that allows me to convert a PCM file to a WAV file. I just noticed that if I put the file extension to WAV format, starting from the raw application saves without problems, so I think that there is no type conversion from PCM WAV files. Correct?

PS: Sorry for my english ... I use Google Translate

macuser
  • 567
  • 2
  • 6
  • 16
  • 1
    `wav` files are just a [container](http://en.wikipedia.org/wiki/Digital_container_format). WAV files doesn't specify any specific audio encoding. However, the most common encoding seems to be a variant of PCM: [LPCM](http://en.wikipedia.org/wiki/Linear_pulse-code_modulation). – Some programmer dude Jan 15 '14 at 07:41
  • Thank you .. so there is no difference between a PCM and a WAV file – macuser Jan 15 '14 at 07:45
  • 1
    That's not entirely true, but in practice you'll probably find 99.9% of the WAV files you will come across will just contain PCM data. The exceptions may be if you have custom codecs or perhaps data recorded on mobiles (which might use compression, for instance). – the_mandrill Jan 16 '14 at 11:33

3 Answers3

26

WAV is some kind of a box. PCM is in the box. There are many container formats like MP4. MP4 can contain audio, video or both. It can also contain multiple video or audio streams. Or zip files. Zip files can contain text files. But zip files can also contain images, pdfs,... But you can't say "how can I convert a zip file to the text file inside the zip".

If you want to convert PCM data to a WAVE file you should not many problems because WAV files are quite simple files. Take a look at this: enter image description here

(See also WAVE PCM soundfile format.)

You first need that header and after you can just append all your pcm data (see the data field).

cp.engr
  • 2,291
  • 4
  • 28
  • 42
Florian
  • 5,918
  • 3
  • 47
  • 86
6

Converting PCM to WAV isn't too hard. PCM and WAV both format contains raw PCM data, the only difference is their header(wav contains a header where pcm doesn't). So if you just add wav header then it will do the tricks. Just get the PCM data and add the wav header on top of the PCM data. To add wav header with PCM data, check this link.

Community
  • 1
  • 1
Partho Biswas
  • 2,290
  • 1
  • 24
  • 39
2

I was working on a system where it accepts only wav files, but the one I was receiving from amazon Polly was pcm, so finally did this and got my issue resolved. Hope it helps someone. This is an example of nodejs.


    // https://github.com/TooTallNate/node-wav
    const FileWriter = require('wav').FileWriter
    
    let audioStream = bufferToStream(res.AudioStream);
    var outputFileStream = new FileWriter(`${outputFileFolder}/wav/${outputFileName}.wav`, {
                                sampleRate: 8000,
                                channels: 1
                            });
    audioStream.pipe(outputFileStream);
    
    function bufferToStream(binary) {
        const readableInstanceStream = new Stream.Readable({
            read() {
                this.push(binary);
                this.push(null);
            }
        });
        return readableInstanceStream;
    }
Giorgio Robino
  • 2,148
  • 6
  • 38
  • 59