Convert from PCM to WAV. Is it Possible?

30,370

Solution 1

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).

Solution 2

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.

Solution 3

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;
    }
Share:
30,370
macuser
Author by

macuser

Updated on October 28, 2020

Comments

  • macuser
    macuser over 3 years

    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

  • jotadepicas
    jotadepicas about 8 years
    Just so you know, Stanford link is broken.
  • jotadepicas
    jotadepicas about 8 years
    Perhaps this is the current equivalent link? soundfile.sapp.org/doc/WaveFormat