How can I record sound from the windows command line?

14

7

Is there an application capable of recording sound that I can run from the command line on XP?

Ideally I'd start it with one command and stop it with another. Or I could specify a duration with the starting command.

Tom Wright

Posted 2010-09-24T14:18:41.220

Reputation: 453

Answers

10

You can use SoX package.

rec recorded_track.wav 00:05

Records for 5 minutes.

More documentation on SoX manpage.

Sathyajith Bhat

Posted 2010-09-24T14:18:41.220

Reputation: 58 436

3SOX doesn't appear to ship with "rec" command anymore. – PeterX – 2015-10-15T13:23:53.310

1@peterx See answer from @this-lau sox -t waveaudio −d new-file.wav – Holger Bille – 2018-04-12T06:39:35.733

12

rec is no longer provided in the SoX Windows package. Instead you can use this command line:

sox -t waveaudio -d new-file.wav

laurent

Posted 2010-09-24T14:18:41.220

Reputation: 5 258

Thanks for the update. Wish I could "sticky" this for any future explorers. – Tom Wright – 2016-08-03T09:27:15.557

@TomWright You can select this answer as the new best answer. – Hashim – 2019-03-28T06:33:03.993

4

To record sound using command line on Windows you can use fmedia:

fmedia --record --out=Recording.wav

You can stop recording at any time by pressing Ctrl+C.

While recording, fmedia shows how loud the signal is, for example:

g:\fmedia>fmedia --record --out=myrec.flac
fmedia v0.10
0:19  [========..] -7.89dB / -1.31dB

Supported formats are WAV, FLAC, OGG and MP3. Output to WAV is the fastest. However, FLAC compression is quite fast too, so you probably won't notice any difference in CPU usage.


If you want to capture sound from a specific device (not just the default one):

Step 1. Use --list-dev switch to show all available devices.

Step 2. Pick a device you want to use and call fmedia with --dev-capture argument.

For example, start recording from a specific device - Microphone:

C:\>fmedia --list-dev
fmedia v0.10
Playback:
device #1: Realtek Digital Output (Realtek High Definition Audio)
device #2: Speakers (Realtek High Definition Audio)

Capture:
device #1: Stereo Mix (Realtek High Definition Audio)
device #2: Microphone (Realtek High Definition Audio)
device #3: Line In (Realtek High Definition Audio)

C:\>fmedia --record --out=Recording.wav --dev-capture=2

def

Posted 2010-09-24T14:18:41.220

Reputation: 41

3

FFmpeg

Besides conversion, ffmpeg could do a lot more than that (i.e filters, i/o device controlling). For this particular subject I'll focus on input-devices.


List all the input devices of DirectShow. FFmpeg requires a input filename, that's not much realistic in this case so null is passed as a filename.

ffmpeg -list_devices true -f dshow -i null

For example, the command below saves 30 seconds of PCM data from dshow input. DEVICE_NAME is placeholder for the actual device substitute it with an actual device name from the list of devices.

ffmpeg -f dshow -t 30 -i "audio=DEVICE_NAME" out.flac

FFmpeg Documentation on dshow.

Quadcubic

Posted 2010-09-24T14:18:41.220

Reputation: 175

1

This is old but might be an alternative

LiveInCode

This program encodes live audio from line-in or microphone directly into Ogg Vorbis, MP3, FLAC, Speex and other formats.

The current version only has built-in support for Ogg Vorbis and Speex. It means you can use any other encoders too, but for encoders other than Ogg Vorbis and Speex you'll need to manually specify the command-line.

Nifle

Posted 2010-09-24T14:18:41.220

Reputation: 31 337