16

Each time I want to use Skype, I have to go in the sound preferences. And there, turn the audio-in to "webcam" and uncheck the "mute" button. It's quite annoying. Is there a way to always keep the same configuration ?

1
  • 1
    I have this problem as well with a logitech quickacam. After every reboot I have to go through the preferences and reset it as the default input in order for it to work. I think it has something to do with the fact that usb devices are loaded after sound preferences are set so pulse or alsa don't "see" the usb mic. Unfortunately because the "problem" isn't really a problem just an inconvenience it's not so important that I want to roll up the shirt sleeves and start digging and editing through config files.
    – user13694
    Apr 6, 2011 at 5:16

4 Answers 4

18

Changing default settings for PulseAudio

When running pulseaudio all settings can be defined by putting custom configuration files in the hidden .pulse directory in your HOME. If these file do not yet exist there you can use the standard files from /etc/pulse/ as a template. Most entries have verbous explanations in these files.

  • ~/.pulse/default.pa to load modules and define defaults
  • ~/.pulse/client.conf to configure a client for the sound server
  • ~/.pulse/daemon.conf to define sample rates and buffers

To make your webcam the default source we need to know this source's name and number by looking through the list produced by the following command in a terminal:

pacmd list-sources

We then edit the following line in ~/.pulse/default.pa:

set-default-source [name]

and replace [name] by the name or the source number for the desired source. We then need to make sure that the source is unmuted by adding this line:

set-source-mute [name]|[#n]> 0

Give the name or the index of your source. You can add a variety of other settings that are referenced in the PulseAudio Wiki (now on man page: man pulse-cli-syntax).

It is recommended to first test all commands through the command line interface before changing the configuration files. This can be opened with pacmd in a terminal

4
  • There's no default.pa in my .pulse folder. Should I create a new file with one line: set-default-source x ?
    – To Do
    Mar 16, 2012 at 21:17
  • 3
    @ToDo the default settings are in /etc/pulse/default.pa. Use this file or copy it to ~/.pulse before editing.
    – Takkat
    Mar 17, 2012 at 17:49
  • For the sake of completeness: one have to write as an input device name the thing that is written inside of angle braces of output of pacmd list-sources. I.e. with for my device it was set-default-source alsa_input.usb-0d8c_USB_PnP_Sound_Device-00-Device.analog-mon.
    – Hi-Angel
    Nov 13, 2015 at 15:00
  • @Hi-Angel: thank you for that - the answer came from a much older version of pulseaudio. We can now use the proper name of a sink.
    – Takkat
    Nov 13, 2015 at 17:11
7

I agree that the problem is that Pulseaudio does not set a USB device as default because it is not present when pulse starts.

Soo my solution to this is to hook into the system that does notice when a USB device is connected... UDEV!

BTW, these instructions are slightly funky, and I am assuming that you are comfortable doing stuff at the command line, and becoming the root user to update udev files, and making scripts executable.

First, find out stuff

USB Id

First step is to plug in your webcam and find the magic vendor and product numbers by typing

lsusb

I'm using a Microsoft Lifecam, and it show as

Bus 001 Device 013: ID 045e:072d Microsoft Corp.

the important part is 045e:072d

Pulseaudio device

Next, while the webcam is connected, find out the pulseaudio device name. Type

pacmd list-sources

Again, I'm looking for the line that starts name: then has something about a Microsoft Lifecam... here it is

name: <alsa_input.usb-Microsoft_Microsoft___LifeCam_VX-5500-02-VX5500.analog-mono>

so my pulseaudio device name will be alsa_input.usb-Microsoft_Microsoft___LifeCam_VX-5500-02-VX5500.analog-mono

UDEV rules

Then I made a new udev rule which is fired when a USB device with vendor=045e and product=072d is inserted. To make a rule, create a new file called /etc/udev/rules.d/SOMETHING.rules (I called my file /etc/udev/rules.d/95-webcam-mic.rules).

Put this line into the file

SUBSYSTEMS=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="072d", ACTION=="add", GROUP="audio", RUN+="/usr/local/bin/webcam-mic"

Remember to replace the ATTR{idVendor} and ATTR{idProduct} with the values for your webcam.

What this rule does is run a script to set the usb device for input, that is the RUN+="/usr/local/bin/webcam-mic" part.

Finally, set the webcam for input

Quick overview time. Each time I connect my webcam I want to run the command

pacmd set-default-source alsa_input.usb-Microsoft_Microsoft___LifeCam_VX-5500-02-VX5500.analog-mono

But the command needs to run as me (the user running the desktop), but udev runs as the root user - so when udev runs my command I need it to change to my user then run the command.

So we have 2 options.

  1. Quick and dirty. Make the udev rule run su james -c pacmd set-default-source... this is sooo wrong I can't even finish typing the command. What if you change webcams? What if you install this for another user?

  2. Slightly cleaner. Run a script that reads a defaults file which has the pulseaudio device name, and your username in it. If you want the files they are on GitHub. First the script /usr/local/bin/webcam-mic. The defaults file /etc/default/webcam-mic just needs to define the 2 shell variables, as per the comment in the gist. Put the script into /usr/local/bin/ and make it executable. Then put the defaults file into /etc/defaults/ and edit it to use your username and the pulseaudio device from earlier.

Good luck!

2
  • Any chance you could upload those scripts again; they appear to have disappeared from pastebin?
    – ej159
    Oct 11, 2014 at 8:56
  • I have put the script into a gist on GitHub, and updated the answer. Oct 17, 2014 at 3:11
2

The solution by Takkat was not working for me, here is my solution for anyone still having a problem with this.

There were two issues for me with the solution by Takkat. First, I realised that there needs to be a delay after startup before the switch to the microphone can take place (I use the command 'sleep' in my solution below). Also, the command 'set-default-source' was working to switch the USB microphone on, but somehow Skype was not recognising this and continued to use the internal microphone.

For this to work, first it is useful to install pavucontrol. In pavucontrol, open the 'Configuration' tab, and observe what happens with the commands below to check things are working as intended.

Then, from a terminal enter:

pacmd

From there, enter:

list-cards

In the output, find the index number of the USB audio you want (in my case, this was '1'). Then have a look at the lines listed under 'profiles' for both the default card and USB card. These should be the same as the ones listed in pavucontrol, and can be something like 'ouput:input+output', 'off', or 'input:analog-mono' etc. Still in the pacmd command line, the command set-card-profile <index number> <profile name> should change the settings in pavucontrol. What we want to do here is to switch the internal audio from duplex to output only, and the USB to input.

Once found the appropriate profiles, we want to create a startup command to change a few settings just after startup. To create a startup command, open the dash and search for 'startup applications', then click 'add', then enter a name of your choice and the appropriate command below.

After trial and error, my start up command ended up looking like this:

bash -c "sleep 30 && pacmd set-card-profile 0 output:analog-stereo && pacmd set-card-profile 1 off && pacmd set-card-profile 1 input:analog-mono"

Explanation: I found that the command 'sleep' was necessary, this means that the command is executed after a pause, that I set to 30 seconds (I think this can be less, play around with this). The next command (after the '&&') is to get the default (internal) card profile to switch from input+output (duplex, which is the default) to output only. The next command is for the USB sound card (in my case, the number is '1') to switch off. The last command is for this same card to switch back on in the mode 'input:analog-mono'

You might have to play around with these settings, to find the one that works.

Now when I startup, my USB microphone is ready to use after 30 seconds, and Skype uses the correct microphone.

0

try this, click on the speaker icon on your top panel, the click preferences. there you can select a default input option for you microphone and probably change some hardware config to make it work ok.

1
  • 1
    Thank you for your help, but that's what I'm doing right now. However, I don't see any ways to make this a default setting. Every now and then, I'll have to do it again because the setting would have changed. Mar 21, 2011 at 2:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .