11

In computer I have 2 sound devices.

When I run some program (let's say Skype) I can (using "pavucontrol" -> "PulseAudio Volume Control") setup so that this application will use given device for playback or recording.

But - in the Playback/Recording tabs application is visible only if it is currently doing something (playback or recording).

How can I set device per application, but before the application starts recording or playing sounds?

3 Answers 3

14

I don't know if there is a setting or configuration file for this anywhere but it can be done with environment variables. I've based my answer on this entry in the PulseAudio FAQ about setting the recording source. I've tried this with output (a sink in PulseAudio) but it should work for both input and ouput.

The first step is to get the internal name of the source and sink that you want to use. To do that you need to use the pactl list command. That command will return a pile of data, but the following will list just the source names:

LANG=C pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2

That list will probably include the names for both regular sources and PulseAudio's monitor sources (which on my system have "monitor" in the name). You'll want to use the regular source name of the device you want to target.

You can do the same thing to get the sink names:

LANG=C pactl list | grep -A2 'Sink #' | grep 'Name: ' | cut -d" " -f2

Once you've got the names you can run something like the following from your terminal:

PULSE_SINK=<sink_name> PULSE_SOURCE=<source_name> <command_to_run_skype>

Of course, if you want to run this from a menu you'll probably need to create a shell script and use that instead of the default command. Something like this should work:

#!/bin/sh
set PULSE_SINK <sink_name>
set PULSE_SOURCE <source_name>
<command_to_run_skype>
1
  • Lovely little set of commands to find internal names, ta!!
    – Vix
    Jan 11, 2020 at 16:31
2

You need to EXPORT and assign the variables, like this:

#!/bin/sh 
export PULSE_SINK="sink_name" 
export PULSE_SOURCE="source_name" 
command_to_run_skype
0

I wrote a perl module that does this PulseAudio.pm.

It permits you to use a syntax like this,

use PulseAudio;
use constant TRACKIN  => 'pci-0000:00:1d.7-usb-0:2.3:1.0'

my $pa = PulseAudio->new;

my $sink   = $pa->get_sink_by([qw/properties device.bus_path/] => TRACKIN );
my $source = $pa->get_source_by(
  [qw/properties device.bus_path/] => TRACKIN
  , [qw/properties device.profile.name/] => 'analog-stereo'
);
$pa->exec({
  sink      => $sink
  , source  => $source
  , prog    => '/usr/bin/audacity'
});

Of course, you can use any criteria in get_sink_by and get_source_by. It reads from pacmd info. This works on the same idea of @moberley's answer except it uses a perl library rather than forcing you do your own parsing. It also provides some other nifty features.

For my podcast show, I actually use this to launch Skype too..

$pa->exec({
  sink      => $sink
  , source  => $source
  , prog    => '/usr/bin/skype'
  , args    => ['--callto','btrlistener021']
});

(the btrlistener* Skype names are for blogtalkradio).

You must log in to answer this question.