Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save vaimr/503c6276eeb49b2f90cdea82bc62f84a to your computer and use it in GitHub Desktop.

Select an option

Save vaimr/503c6276eeb49b2f90cdea82bc62f84a to your computer and use it in GitHub Desktop.

Revisions

  1. @varqox varqox revised this gist Oct 17, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion recording_application_and_microphone.md
    Original file line number Diff line number Diff line change
    @@ -27,6 +27,8 @@ pacmd load-module module-combine-sink sink_name=combined sink_properties=device.
    ```

    ## Step 3. Attach microphone to `recording` sink
    _Protip: If you ommit this step you may record multiple apps without microphone._

    First we have to locate our microphone as a source:
    ```sh
    pacmd list-sources | egrep '^\s+name: .*' | grep input
    @@ -40,7 +42,6 @@ Now we attach it to `redording` sink:
    ```sh
    pacmd load-module module-loopback source=alsa_input.pci-0000_00_1f.3.analog-stereo sink=recording latency_msec=1
    ```
    _Protip: If you ommit this step you may record multiple apps without microphone._

    ## Step 4. Channel applications through the `combined` sink to record them (this step can be done after step 5. -- you can change what apps you record without stopping recording)
    Open `pavucontrol`, go to `Playback` tab and change sink to `combined`. _Hint: the application won't appear there unless it is producing sound._
  2. @varqox varqox revised this gist Dec 28, 2019. No changes.
  3. @varqox varqox revised this gist Dec 28, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions recording_application_and_microphone.md
    Original file line number Diff line number Diff line change
    @@ -44,6 +44,7 @@ _Protip: If you ommit this step you may record multiple apps without microphone.

    ## Step 4. Channel applications through the `combined` sink to record them (this step can be done after step 5. -- you can change what apps you record without stopping recording)
    Open `pavucontrol`, go to `Playback` tab and change sink to `combined`. _Hint: the application won't appear there unless it is producing sound._

    ![image](https://user-images.githubusercontent.com/4380808/71537536-6132e980-2915-11ea-85ec-afd37f3ac183.png)

    ## Step 5. Record audio
  4. @varqox varqox revised this gist Dec 28, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion recording_application_and_microphone.md
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ _Protip: If you ommit this step you may record multiple apps without microphone.

    ## Step 4. Channel applications through the `combined` sink to record them (this step can be done after step 5. -- you can change what apps you record without stopping recording)
    Open `pavucontrol`, go to `Playback` tab and change sink to `combined`. _Hint: the application won't appear there unless it is producing sound._
    TODO: add screenshots
    ![image](https://user-images.githubusercontent.com/4380808/71537536-6132e980-2915-11ea-85ec-afd37f3ac183.png)

    ## Step 5. Record audio
    With the above setup, you can start and stop recording at any time. To record `recording` sink, use:
  5. @varqox varqox created this gist Dec 28, 2019.
    55 changes: 55 additions & 0 deletions recording_application_and_microphone.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    # How to record multiple applications and microphone into one audio file on Linux

    ## Step 0. Terminology
    Sinks are for output, sources are for input. To stream source to sink a loopback must be created.
    More shall you find [there](https://gavv.github.io/articles/pulseaudio-under-the-hood/#key-abstractions).

    ## Step 1. Create output sink that will be recorded
    Our output sink will be named `recording`.
    ```sh
    pacmd load-module module-null-sink sink_name=recording sink_properties=device.description=recording
    ```

    ## Step 2. Create output sink that will forward data to `recording` and the default sink -- your headphones (using speakers is not a good idea because they will be recorded by microphone for the second time)
    First we have to locate our output sink:
    ```sh
    pacmd list-sinks | egrep '^\s+name: .*'
    ```
    For me it prints:
    ```
    name: <alsa_output.pci-0000_00_1f.3.analog-stereo>
    name: <bluez_sink.4C_87_5D_07_5B_C4.a2dp_sink>
    ```
    So I choose `bluez_sink.4C_87_5D_07_5B_C4.a2dp_sink` as my output sink because its my headphones (the other represents my speakers).
    Now we can combine it with our new `recording` sink into `combined` sink:
    ```sh
    pacmd load-module module-combine-sink sink_name=combined sink_properties=device.description=combined slaves=recording,bluez_sink.4C_87_5D_07_5B_C4.a2dp_sink
    ```

    ## Step 3. Attach microphone to `recording` sink
    First we have to locate our microphone as a source:
    ```sh
    pacmd list-sources | egrep '^\s+name: .*' | grep input
    ```
    For me it produced:
    ```
    name: <alsa_input.pci-0000_00_1f.3.analog-stereo>
    ```
    So `alsa_input.pci-0000_00_1f.3.analog-stereo` represents my microphone.
    Now we attach it to `redording` sink:
    ```sh
    pacmd load-module module-loopback source=alsa_input.pci-0000_00_1f.3.analog-stereo sink=recording latency_msec=1
    ```
    _Protip: If you ommit this step you may record multiple apps without microphone._

    ## Step 4. Channel applications through the `combined` sink to record them (this step can be done after step 5. -- you can change what apps you record without stopping recording)
    Open `pavucontrol`, go to `Playback` tab and change sink to `combined`. _Hint: the application won't appear there unless it is producing sound._
    TODO: add screenshots

    ## Step 5. Record audio
    With the above setup, you can start and stop recording at any time. To record `recording` sink, use:
    ```sh
    parecord --channels=2 -d recording.monitor output.wav
    ```
    It will save recording to `output.wav` file. To stop recording press `Crtl-C` (kill the parecord with SIGINT).
    _Protip: You can change recorded applications while recording by controlling which ones output to `combined` sink as was shown in step 4._