How To Easily Record Sound On Windows And Linux

fmedia >> Articles >> Audio Formats Comparison
by Simon Zolin, Aug 25 2016 (upd. Dec 26, 2016)

In this tutorial I'm going to show you how to record audio using fmedia. The article covers several aspects: choosing audio capture device, configuring audio settings and saving recorded audio to a file. First I describe how to use fmedia from command line on both Windows and Linux, and then how to use fmedia GUI supported only on Windows.



Before we start using more advanced features, I want to show you the easy way how to record sound from your default audio input device to a file. Just execute the following command:

	fmedia --record -o myrec.wav

The recording process starts and the output file "myrec.wav" is being filled with audio data. The dB values show how loud your current signal is. If it reaches 0dB, your signal is too loud and it will be clipped, resulting in quality loss. Usually, the best recording quality is achieved when the sound level is almost 0dB, but not reaches it.

To stop recording, press Ctrl+C or just S (the default key for "Stop"). All cached data is flushed to a file and fmedia exits. fmedia can automatically stop recording after the given time is passed: use --until=MIN:SEC parameter when executing fmedia.

Note that this method may not work if the default audio format configured in fmedia isn't compatible with your audio device. Also, you might want to use another audio device, not the one configured in your OS as the default. The next sections of this tutorial will show you how to do that.

Note Linux users: fmedia uses ALSA for audio streaming, so if your system doesn't have ALSA installed and configured, sound recording won't work.


Without any additional configuration fmedia will use audio device configured in your OS as the default. But what if you want to use another device? There are 2 simple steps you should follow:

  1. Get the list of sound devices.
  2. Choose the needed device and pass it to fmedia.

Step 1.

This command shows the list of all available sound devices in your system:

	fmedia --list-dev

Step 2.

You should pick a device you want to use from "Capture" section and pass its number to fmedia. For example, if I want to record from my USB soundcard, I run fmedia like this:

	fmedia --dev-capture=4 --record -o myrec.wav

Now the sound will be recorded from "Microphone (E-MU 0202 | USB)".


If you don't want to specify --dev-capture=N parameter each time you run fmedia, you can set this device to be used by fmedia by default. You need to edit fmedia.conf file and configure the module which is used for sound recording.

On Windows, find this section:

	mod_conf "" {
		device_index 0

and set another device number instead of "0".

On Linux, do the same in this section:

	mod_conf "" {
		device_index 0


Default audio format used by fmedia for sound recording is audio-CD quality (16-bit, 44.1kHz, stereo). But it isn't always the best choice. You may wish to set different audio settings: bit depth, sample rate, channels. Consider this example:

	fmedia --record --format=int24 --rate=48000 --channels=mono -o myrec.wav

This command starts recording in 24-bit format, 48kHz sample rate, 1 channel.
The supported formats, that can be used with --format switch, are: int8, int16, int24, int32, float32.

Note Windows users: the audio settings you pass here to fmedia may not be compatible with the format configured in Windows. In this case sound conversion will occur possibly resulting in a quality loss. The next section explains how to configure your audio device recording format.


Here are the steps to set audio format used by Windows for the recording device:

  1. Right click on Speaker icon in system tray.
  2. Choose "Recording devices" in the popup menu.
  3. Double click on the device you want to configure.
  4. Select "Advanced" tab.
  5. In section "Default Format" select the needed format.
    It is best if this format matches with fmedia audio format settings.
  6. Press OK to save settings.


You may configure fmedia to use different audio format by default, rather than audio-CD quality. Open fmedia.conf in your text editor, then find this section:

	# Default audio format for recording
	record_format {
		# Audio format: int8 | int16 | int24 | int32 | float32
		format int16
		# Channels number: 2 (stereo) | 1 (mono) | left | right
		channels 2
		rate 44100

and set the audio format you want fmedia to use by default. After that you don't need to specify --format, --rate and --channels parameters every time.


To record into another file format, just specify its file extension as the output file. For example, to use FLAC:

	fmedia --record -o myrec.flac

You can use any output file format supported by fmedia: wav, flac, ogg, mp3, m4a.

I recommend you to use FLAC for lossless audio recording. CPU usage is really small for FLAC encoding, so don't be afraid to use it. But be aware that fmedia can't encode 32-bit or float audio to FLAC.

If you need the fastest possible recording and you don't need to save disk space, use WAV format. It supports any audio format and requires zero encoding time.

When you want to save disk space and the best audio quality isn't required, use OGG Vorbis for lossy audio recording. The default setting 5.0 for Vorbis encoding quality gives a good starting point.


fmedia can also write recorded audio into stdout. It may be useful if you want to immediately pass fmedia's output to another program. Here's an example:

	fmedia --record --out=@stdout.wav > ./my-rec.wav

Here fmedia writes recorded data into stdout, and then it's being redirected to a file my-rec.wav. When --out=@stdout argument is specified, fmedia writes output to stdout, instead of a file. File extenstion (.wav in this case) for --out parameter must be specified, so fmedia knows what output file format to use.

You can use another application to process recorded audio:

	fmedia --record -o @stdout.wav | your_audio_app OPTIONS

You may also use fmedia to read audio from stdin:

	fmedia --record -o @stdout.wav --until=5 | fmedia @stdin.wav -o rec.wav

Keep in mind that since stdout is an unseekable stream, recorded output files may have incomplete headers. Currently, only .wav, .flac, .ogg/.opus are supported for stdout streaming.


On Windows, WASAPI has an ability to capture audio from playback device, it's called loopback mode. You can easily capture the sound you hear from your speakers with fmedia:

	fmedia --record --dev-loopback=0 -o rec.wav

--dev-loopback=0 argument tells fmedia to use the default playback device and start recording from it. You can use other device to record from, just specify its number instead of 0 (see Choosing Audio Input Device). Note that you need to specify a "Playback/Loopback" device and not a "Capture" device. Also, note that no audio will be recorded unless something is playing at the moment: if you stop playback through the speakers, fmedia will stop writing output audio until you resume playback again.


fmedia can stop recording which was started from another instance of fmedia. This can be useful if you don't have an ability to interact with a terminal where fmedia is running (i.e. you can't press "S" to stop recording). This feature isn't enabled by default, you must pass --globcmd=listen command line argument to enable it:

	fmedia --record -o myrec.wav --globcmd=listen

This command starts recording audio and starts listening for commands that can be sent from another instance of fmedia. You can now forget about this terminal window, where fmedia is currently running, and minimize it. This would be instance #1.

When you want to stop recording, you execute fmedia once again (i.e. you start instance #2):

	fmedia --globcmd=stop

fmedia will find out that instance #1 is currently running and will issue a command to it to stop recording. Both fmedia processes will now exit, with the first one correctly finishing its recording file (flushing all cached data and finalizing file header). In other words, this command will simulate an "S" key-press action for the first instance.

There are other commands that --globcmd parameter supports, but currently they're useful for audio playback only. See the output of fmedia --help to find out more.


fmedia can process multiple tracks running together. If you need to record audio while still being able to play another track, use this command:

	fmedia track.mp3 --record -o myrec.wav

It will start playback of track.mp3 and in the same time start recording audio into myrec.wav.

Note that there may be a small time unsynchronisation between input tracks and your recorded file. If you experience this problem, try reducing buffer size for modules "", "wasapi.out" (Windows) or "", "alsa.out" (Linux). However, at this time there's no 100% working solution for the issue.

Consider the next example:

	fmedia --mix track1.mp3 track2.mp3 --format=int16 --record -o myrec.wav

Here fmedia starts playback of both track1.mp3 and track2.mp3 simultaneously (mixing tracks together) and starts recording into myrec.wav. --format=int16 parameter is required because by default fmedia uses int16 audio format for mixer output, but mp3 output format is float32, thus audio conversion must be done. Be careful when using --mix command: fmedia doesn't apply sound attenuation in this case, so the output signal may be very loud.


On Windows there is a graphical interface for fmedia you can use for recording. Of course command-line interface has its advatages but recording with GUI is even easier!

Run fmedia-gui and from the main window press Ctrl+R. The recording process will start to a new file. To stop recording, press Ctrl+R once again. Also, you can start and stop recording by clicking on Record menu and then Quick Start/Stop. After recording is stopped, a new file will appear in the playlist.

If you wish to configure recording settings, you need to open Record window:

Here you select where to save your recordings, how to name them and which output file format they will be saved into (.flac in this case). fmedia supports dynamic variables (e.g. $date and $time) that can free you from naming the files manually every time. You can read about $-variables in help.txt file.

Empty value (e.g. for "Audio Format") means "use default". You can change some of these settings in fmedia.conf in section mod_conf "gui.gui".


So this is how you can record audio with fmedia. I hope this article was helpful. If you have any questions, send me an email.

Copyright © 2015 Simon Zolin