Talk:Recording audio playing on the computer

Update Plan - Peter 3Apr12
The tutorial in the Manual was entirely derived from this one and was was much extended and verified there following the the transfer. Therefore I recommend.
 * 1) Remove the entire current content of this tutorial.
 * 2) Add a landing point for recommending use of /upgrade to current version and a link to current manual.
 * 3) Possibly add a link to SF legacy FAQ for 1.2 users?
 * 4) The SF legacy FAQ will require updating as it has a link back to here for "more details".


 * Bill 03Apr12: +1 for removing this tutorial from the wiki
 * Gale 04Apr12: +1 for landing page linking to old FAQ/ current manual, with proviso that http://manual.audacityteam.org/man/Tutorial_-_Recording_Computer_Playback_on_Linux may be TLDR; or inaccurate (see below) and the command-line methods may be too esoteric for the Manual. Possible solution, move into Linux Issues or to a separate page linked to on Linux Issues. We still need longer term to decide about Mixer Toolbar Issues and if the Windows section from Mixer Toolbar Issues needs as I suspect to be a separate Wiki page with more handholding and pictures.
 * Peter 4Apr12: Re, the http://manual.audacityteam.org/man/Tutorial_-_Recording_Computer_Playback_on_Linux page - that is really Steve's baby, I have no skills or knowledge to contribute to that page. Steve did some work on it pre 2.0 but there still remains a Px ToDo on that page.  I suspect that it may not be TLDR (at the risk of sounding facetious and not meaning to ;-)>  ) don't the *nix heads revel in that level of detail?

PCM device
Gale 13Apr11:

Hi Avalon

Sorry for reverting your edit but at the moment it seems advisable to leave the warning about pulse in. To begin with is

FLASH_ALSA_DEVICE=teeraw firefox

meant to go in ,asoundrc or to to be used standalone in a terminal to launch Firefox? Either way it produces no playback sound in Firefox for me on Ubuntu 10.10 (using "empty" or "copy"). If put in .asoundrc, Audacity can't find any audio devices even if Firefox is closed. At no time is /tmp/out.raw written.

If I use FLASH_ALSA_DEVICE=teeraw firefox from a terminal then I see in the terminal FLASH_ALSA_DEVICE=teeraw firefox Failed to open VDPAU backend libvdpau_nvidia.so: cannot open shared object file: No such file or directory

Avalon 13Apr11:

I don't know about

FLASH_ALSA_DEVICE=teeraw firefox

I think somebody else put that information. In any case this is the command line to start firefox with FLASH_ALSA_DEVICE environment variable set in a UNIX shell. Also I've no idea why should you get such an error. As far as I see vdpau is something for graphics. See http://en.wikipedia.org/wiki/VDPAU

In any case the instructions should work on any linux distribution using ALSA to handle audio. To make instructions more verbose they will become a guide to ALSA rather than quick notes. I don't have time to write such now though.

The only way for pulseaudio to interfere is by opening the hardware sound device and preventing any other processes to open it. If the teeraw device is written to use the hardware pcm device the whole thing will fail. But the teeraw device should be able to use the pulseaudio device instead...

So I agree that on a system using pusleaudio it might be far easier to use pusleaudio so one doesn't have to mess with the complex ALSA setup. But stating pusleaudio may break alsa is not correct in my experience.

If you care enough for the pure ALSA way of doing things and can provide me with ssh access to a machine you see this error on, I can look at that.

=Archiving the original page content here - just in case we need it=

Windows
'''Quick answer:

Choose the inbuilt sound device at (or  in Audacity Beta). Then choose the appropriate "stereo mix" or similar input source in the Audacity Mixer Toolbar dropdown selector.
 * Audacity 1.2.6 to 1.3.12 inclusive on Windows 98/ME/2000/XP:

Choose the appropriate "stereo mix" or similar Recording Device at (or at  or Device Toolbar in the current Beta version).
 * '''Audacity 1.2.6 onwards on Windows Vista/7, and 1.3.13 onwards on Windows 98/ME/2000/XP:

If you have problems, use the Windows Control Panel to enable and select the correct source or device - see especially the green panel "HELP ON RECORDING COMPUTER PLAYBACK OR STREAMING AUDIO" in that section.

Mac
Macs have no ability to record streaming audio as it plays on the built-in sound device. It is possible to record streaming audio from the built-in microphone, but this a very lossy method that also picks up all ambient noise.

Recommended solutions:


 * If your machine has a line-in, you may be able to record audio from the computer into Audacity by joining the line-out and line-in ports on the computer with an audio cable, and setting the default input in Apple Audio MIDI Setup to line-in. To hear the sound while recording, use a single to double stereo connector to give you a jack for the speakers or headphones. This has two disadvantages: system sounds and unwanted sounds from other programs are captured in the recording, and minor degradation is likely because the digital original is converted to analogue by being played on the sound device. There is no conversion to analogue with the remaining three alternatives below.


 * On OS X 10.4 or later, use Audio Hijack or Wiretap to capture the audio to AIFF files directly from the player application. Turn off compression in Wiretap Preferences if you want to import the recorded AIFF files into Audacity.
 * On OS X 10.2 or later, use the free open source Soundflower system extension. Soundflower behaves like an additional system audio device, so for example to record streaming audio into Audacity you would select Soundflower as the output device in the application in which you are playing sound, and Soundflower as the input device on the (Devices tab in current Audacity Beta). If the application playing the sound does not allow you to specify its output  device, you can make Soundflower the default output device in.


 * If you are playing an unprotected audio stream and know its actual web address, VLC player can save it to the hard drive in a number of formats including WAV, MOV and OGG. QuickTime may also be able to save at least unprotected MP3 streams as MP3 or MOV.
 * There is another software you can used called Sound Tap from NHC.

Linux
On Linux there are in general two different sound systems that provide drivers to your sound device, OSS and the more recent ALSA. Additionally, advanced sound servers such as PulseAudio and JACK can use ALSA to provide professional audio features such as routing of inputs and outputs, high quality mixing and resampling, aggregation of devices or sound cards and (in the case of JACK) very low latencies.

Alsamixer
To record computer playback into Audacity, you can use the alsamixer mixer device to select the "capture" device of your sound card and adjust its input volume. This will record all audio playing through the sound card, including system sounds and possibly sounds from applications other than the one you want to record. To capture sound directly from the application producing it, try using the ALSA PCM file or (on many Linux distributions) try PulseAudio.

Alsamixer should be already installed. Alsamixer is a command line tool, but with "view" options to represent the sound device graphically.

To start alsamixer, open a shell/terminal and start the program by typing alsamixer. There are three different views: Playback (default), Capture and All. This is the Playback view, which you can get to at any time by pressing or  :
 * [[Image:Alsamixer_main.png|Alsamixer Playback view]]

Top left you should see some information about your sound card. Below are volume bars for adjusting the output volume for each named device: examples are Master, PCM, Line, CD and so on. The currently selected item appears in red and the volume percentages are displayed for left and right channels above the device name. For a mono device, only one value is shown.

You can scroll between devices using the left/right arrow keys. Use up/down arrow keys to adjust the volume. Press the key to mute/unmute the device. When a device is turned off, M (mute) appears below the volume bar. When it's turned on, O in green appears instead.

Now press the key or  to switch to Capture view. This is preferable to switching to All view with, because All may not show all of the capture devices for your card.
 * [[Image:Alsamixer_capture.png|Alsamixer Capture view]]

Select the device called Capture with the spacebar. The red CAPTUR flag should appear underneath the Capture bar to indicate that capture is turned on for that device, and L and R letters will indicate that left and right channels are turned on. Devices whose capture is turned off are shown by --. Now, also select the "Mix" device (this might sometimes be called "Master").

Launch Audacity and open the preferences using or navigate to it by clicking. Select Alsa: default as playback device and Alsa:: (hw:0,0) as recording device ("0" represents the default sound card). Click OK to exit Preferences, then press the red Record button or the shortcut to start recording the audio playing on the computer. If the audio is too soft or too loud so it distorts, you will need to check both the output levels in the Playback view of alsamixer, and adjust the recording level in Audacity (or do so in the Capture view of alsamixer).

If no capture device is available, try plugging your line-out or headphones-out to the line-in and then record from line-in. To hear the sound while recording, use a single to double stereo connector to give you a jack for the speakers or headphones.

If you have only mic-in and no line-in is selectable through alsamixer, you can build an attenuator to reduce the line level output to a level suitable for mic-in. But probably this will only provide mono recording, because mic-in is mono in most cases. As well, the quality may be questionable.



Using the ALSA PCM file
It is not necessary to use Audacity to record sounds playing on the computer. You can capture the sound from the application producing it before it reaches the sound device, which avoids capturing unwanted system sounds. This solution can be used even if there is no sound device. Note: this solution may not work on a system using PulseAudio but you can use PulseAudio Volume Control instead.

First you need to create (or edit if it exists) ~/.asoundrc file. Do it with your favorite plain text editor. Note: ~ is your home directory so change that to /home/john or whatever if you are not working in a Linux shell.

pcm.teeraw { type empty slave.pcm "tee:default,'/tmp/out.raw',raw" # 48000 S16_LE 2ch (aplay -t raw -f dat) }

Now tell the application you are trying to record from to use the "teeraw" ALSA device for playback - read the application's manual for help. Although there is no interface to do this for Adobe Flash, it can be achieved by setting the FLASH_ALSA_DEVICE environment variable to the name of the sound device to use, e.g.

FLASH_ALSA_DEVICE=teeraw firefox

Thanks to wensley.org for this tip.

Run the application. Stop the application. Now /tmp/out.raw should contain your sound with perfect quality. If you change "default" to "null" in the above text, you will not hear anything but sound will still go to the file. If for some reason "empty" is not liked by your ALSA library, then try with "copy".

If you want to record all sounds played through the computer, you'll need to set the teeraw device as your default device with something like:

pcm.!default{ type empty slave.pcm "teeraw" }

In this case though, you will need to change "tee:default,'/tmp/out.raw',raw" to "tee:null,'/tmp/out.raw',raw" or something else because otherwise you create a loop. In many cases changing "null" to "dmix" should do the trick - you record any application audio still you hear it through your speakers. Note that you'll pick up random sounds from other applications such as system "dings", and the raw file could get corrupted or overwritten. So unless your alsa lib allows you a setup like below, you must absolutely make sure, only the desired application is producing sound while you are recording this way.

With newer ALSA versions you can try these parameters for convenience (also you can adapt to use a different encoder than lame):

pcm.teewav { type copy slave.pcm "tee:default,'/tmp/out.raw',wav" } pcm.teemp3 { type file format "raw" slave.pcm "default" file '|/usr/local/bin/lame -S -r -s %r --bitwidth %b -m j - /tmp/asound-$$.mp3' }

PulseAudio
PulseAudio is a sound server providing professional audio features such as mixing and input/output routing. It is the default audio device on many Linux distributions like Ubuntu or Debian. PulseAudio operates as a plug-in to ALSA-lib or provides the padsp utility to reroute audio from OSS applications through PulseAudio.

Sometimes PulseAudio can expose a sound card's "Stereo Mix" or "What U Hear" device for recording computer playback which would not otherwise be available when running on Linux.

Installing the optional PulseAudio Device Chooser and PulseAudio Volume Control lets you connect applications like Audacity to record directly from playback applications like Firefox or Rhythmbox. This avoids recording possibly unwanted system sounds. For details of how to configure Audacity to use PulseAudio Volume Control, see Stereo mix with Ubuntu 10 (the principles stated there apply to most Linux distributions where PulseAudio can be used).