You are not logged in.

#1 2022-03-03 00:49:05

bohokash
Member
Registered: 2019-11-30
Posts: 76

How can I record sound output only of a given window or application?

One can easily record the sound output, which are played by the soundcard. But I would like to record sound output coming only from a given browser window or application, and not recording, discarding those sound effects, which are played for example in another browser instance, like facebook sound effects, pidgin messenger notification sounds, skype calls, etc.

I made searches, and I found "pacat", wich is part of pa* app group of pulseaudio, like paplay, pamon, parec, etc.
I tried the following command line:

pacat --volume=32768 --format=s16ne --channels=2 --rate=44100 --file-format=oga -r -n "Chromium Input" > 1.ogg

and even

pacat --volume=32768 --fix-format --fix-channels --fix-rate --file-format=oga -r -n "Chromium Input" > 1.ogg

Which is mentioned in the corresponding man page of "pacat".

I also tried --file-format option with "flac" file format.

But in both cases, and both file formats, ogg and flac, the recorded sound is truly low quality, sounds like a very old radio set, or an old telephone, with sample rate of something like 8000 Hz, and mono. However the resulting audio file is 44 kHz and stereo, 128 kbps, still the sound quality is poor, suboptimal.

What should I do to record sound from a given window, app, process in the same quality, what can be heard while it is playing?

Which application do you recommend for this special task?

Offline

#2 2022-03-03 02:19:32

vorvac
Member
Registered: 2021-05-14
Posts: 44

Re: How can I record sound output only of a given window or application?

Offline

#3 2022-03-03 08:25:00

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,944

Re: How can I record sound output only of a given window or application?

parec/pacat has the --monitor-stream= where you can pass an index of the sink-input you are interested in that directly grabs the relevant streams audio. If you use that without explicitly specifying sample or channel arguments you should get the exact same thing as is being output from the sink.

You seem to try to do this with the -n parameter, which is not what it is for.

Offline

#4 2022-03-04 18:28:41

bohokash
Member
Registered: 2019-11-30
Posts: 76

Re: How can I record sound output only of a given window or application?

What to substitute after --monitor-stream= ?

When I list the available sinks: "pacmd list-sinks"

1 sink(s) available.
  * index: 0
	name: <alsa_output.pci-0000_00_0e.0.analog-stereo>
	driver: <module-alsa-card.c>
	flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
	state: RUNNING
	suspend cause: (none)
	priority: 9039
	volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
	        balance 0.00
	base volume: 65536 / 100% / 0.00 dB
	volume steps: 65537
	muted: no
	current latency: 75.53 ms
	max request: 14 KiB
	max rewind: 14 KiB
	monitor source: 0
	sample spec: s16le 2ch 48000Hz
	channel map: front-left,front-right
	             Stereo
	used by: 1
	linked by: 3
	configured latency: 75.00 ms; range is 0.50 .. 1837.50 ms
	card: 0 <alsa_card.pci-0000_00_0e.0>
	module: 6
	properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = "Generic Analog"
		alsa.id = "Generic Analog"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "0"
		alsa.card = "0"
		alsa.card_name = "HDA Intel PCH"
		alsa.long_card_name = "HDA Intel PCH at 0xa1114000 irq 134"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:00:0e.0"
		sysfs.path = "/devices/pci0000:00/0000:00:0e.0/sound/card0"
		device.bus = "pci"
		device.vendor.id = "8086"
		device.vendor.name = "Intel Corporation"
		device.product.id = "3198"
		device.product.name = "Celeron/Pentium Silver Processor High Definition Audio"
		device.form_factor = "internal"
		device.string = "front:0"
		device.buffering.buffer_size = "352800"
		device.buffering.fragment_size = "176400"
		device.access_mode = "mmap+timer"
		device.profile.name = "analog-stereo"
		device.profile.description = "Analog Stereo"
		device.description = "Built-in Audio Analog Stereo"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	ports:
		analog-output-speaker: Speakers (priority 10000, latency offset 0 usec, available: unknown)
			properties:
				device.icon_name = "audio-speakers"
		analog-output-headphones: Headphones (priority 9900, latency offset 0 usec, available: no)
			properties:
				device.icon_name = "audio-headphones"
	active port: <analog-output-speaker>

1 sink is available. But when I try to substitute 0 or 1 after "--monitor-stream=" I got an error message: "Stream error: No such entity"

Offline

#5 2022-03-04 19:32:22

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,944

Re: How can I record sound output only of a given window or application?

The index of the sink-input i.e. the chromium stream you want to record from, check pacmd list-sink-inputs during playback of the thing you want to record.

Last edited by V1del (2022-03-04 19:33:55)

Offline

#6 2022-03-05 04:04:14

bohokash
Member
Registered: 2019-11-30
Posts: 76

Re: How can I record sound output only of a given window or application?

I tried recording with ffmpeg, and it works:

ffmpeg -f pulse -i 0 -c:a libmp3lame -b:a 128k pulse.mp3

Offline

#7 2022-03-05 07:41:44

Maniaxx
Member
Registered: 2014-05-14
Posts: 757

Re: How can I record sound output only of a given window or application?

For a different approach, you could create dummy sinks, virtual soundcards, loopback devices, etc and use them individually in your apps (e.g. Alsa/snd-aloop, Pipewire/nullsink..).


sys2064

Offline

#8 2022-03-05 11:01:38

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,944

Re: How can I record sound output only of a given window or application?

but that will contain everything rather than the single application?

Offline

#9 2022-03-05 14:50:01

Maniaxx
Member
Registered: 2014-05-14
Posts: 757

Re: How can I record sound output only of a given window or application?

Not if you (can) tell the app to use that (non-default) sink/loopback explicitly/exclusively (wheras all other apps use the "default" one). Audacity (for example) allows to output to a specific audio device. Many apps probably do not though and just use the 'default' sink.

Last edited by Maniaxx (2022-03-05 14:55:00)


sys2064

Offline

#10 2022-03-05 15:13:55

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,944

Re: How can I record sound output only of a given window or application?

Of course, I was more referring to the solution bohokosh ended up using and it shouldn't have been a comment on your suggestion, sorry should've made that more clear. Without wanting to install/use anything else invoking parec with the correct arguments should suffice.

Offline

Board footer

Powered by FluxBB