Skip to content

JayXT/RecordAudioOutput

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RecordAudioOutput

A custom bash script to record audio output in GNU/Linux.

The solution is aimed at GNU/Linux distributions using either PulseAudio or PipeWire audio system. In the first case pulseaudio-utils or alternative package for your distribution containing parec utility should be installed. The script is available in two variations: record_audio_output (PulseAudio version) and record_audio_output_pw (PipeWire version).

Before using any of them, please ensure that lame and xclip dependencies are also installed. Both script variations use the default sink (output audio device).

The respective script should be placed in any convenient location and a permission to execute it should be granted. Then user can assign a shortcut to run it via the system settings:

image

The record_audio_output script has been tested in Debian 11 Xfce and Debian 12 Xfce with PulseAudio. The record_audio_output_pw has been tested in Fedora 39 GNOME with PipeWire.

The default execution algorithm:

  1. Check whether parec/pw-record is already running.
  2. If it's running, kill it and thus finish execution/recording, if it's not, proceed with the step 3.
  3. Set a targetSink variable to the default output device.
  4. Generate a random audio name starting with "out_" to be stored in user's Downloads folder.
  5. Record the audio output from the targetSink to the output file using parec/pw-record + lame.
  6. Copy the audio file to the clipboard with xclip (happens when the audio process is killed and then step 5 terminates).

So to sum it up, both script versions allow to start recording output audio, and finish it with one shortcut (e.g. Super + A to start and Super + A to finish). Then the file will stay in the clipboard ready to be pasted into any application like Anki, Telegram, etc.

This is especially useful for immersion-based language learning and Anki cards creation, because with a couple of key presses it's possible to record the original high-quality audio from any movie, TV series, dictionary, or service.

Additional Notes

If for some reason there's a need to manually specify a sink to record the audio from, it could be done as follows:

PulseAudio

  1. Identify your output device using the following command: pacmd list-sinks | grep -e 'name:' -e 'index' -e 'Speakers' Here's a sample of its output: image
  2. Replace the value of targetSink variable in the script with your device name + ".monitor" suffix for PulseAudio. In this particular example it looks as follows: targetSink="alsa_output.usb-Audioengine_Ltd._Audioengine_2__ABCDEFB1180003-00.analog-stereo.monitor"

PipeWire

  1. Find your output device (sink) with the following command: wpctl status
  2. Set targetSink variable in the record_audio_output_pw to the number associated with the desired sink.

About

A custom script to record audio output in GNU/Linux.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages