ashishbajaj99 / mic

A simple stream wrapper for arecord (Linux (including Raspbian)) and sox (Mac, Windows). Returns a Passthrough stream object so that stream control like pause(), resume(), pipe(), etc. are all available.
MIT License
103 stars 61 forks source link

[Question] How can I record WAV or MP3? #5

Closed arronhunt closed 8 years ago

arronhunt commented 8 years ago

Changing 'fileType': 'wav' or just the output file name to output.wav creates an unplayable WAV file.

ashishbajaj99 commented 8 years ago

Changing 'fileType': 'wav' should do it on Mac or Windows with SoX.

So we use the 'rec' command which uses SoX. On Linux we are using alsa tools 'arecord'. For SoX, you need to check how to record a wave file by reading up here: http://sox.sourceforge.net/soxformat.html

Excerpt here:

.wav (also with −t sndfile)
Microsoft .WAV RIFF files. This is the native audio file format of Windows, and widely used for uncompressed audio.
Normally .wav files have all formatting information in their headers, and so do not need any format options specified for an input file. If any are, they will override the file header, and you will be warned to this effect. You had better know what you are doing! Output format options will cause a format conversion, and the .wav will written appropriately.
SoX can read and write linear PCM, floating point, μ-law, A-law, MS ADPCM, and IMA (or DVI) ADPCM encoded samples. WAV files can also contain audio encoded in many other ways (not currently supported with SoX) e.g. MP3; in some cases such a file can still be read by SoX by overriding the file type, e.g.
   play −t mp3 mp3−encoded.wav
Big endian versions of RIFF files, called RIFX, are also supported. To write a RIFX file, use the −B option with the output file options.

You can see how we are calling the underlying 'rec' by looking at the mic.js file available at: mic/lib/mic.js

Clearly we call it with -t fileType so if you change it to 'wav' it should work.