USB Microphone over USB switch doesn't work with TeamSpeak

1

I run an USB Microphone over a USB switch (together with Mouse and Keyboard) on multiple Computers.

When i switch back from my other Computer, my Microphone is re-activated by Linux, but TeamSpeak cannot reactivate it or still thinks it is broken/not available. I have to change the "Capture Device" configuration in Teamspeak from "Default" to my USB Microphone or the other way around to make it work again.

In an older Ubuntu installation i somehow solved this with the help of Google so that the USB Microphone always appeared active (even though it was unplugged), but i cannot for the live of me find this fix again.

TimeWaster

Posted 2018-11-27T15:20:26.973

Reputation: 11

Do you remember any details how you solved it? With a null Pulseaudio sink, and loopback? With some ALSA plugins, editing .asoundrc? Anything? – dirkt – 2018-11-28T07:02:56.347

@dirkt no, unfortunately not. i just tried the null sink with a loopback module idea, and it only works one time, if i disconnect the microphone more than one time it does not reconnect the mic to the null sink. – TimeWaster – 2018-11-28T19:33:28.960

Answers

0

so, after sweating blood and tears, reading tons over tons of documentation and trying stuff out for days on end i have a solution. not a good one, but i have one.

first add to the end of your pulseaudio config (in my case sudo nano /etc/pulse/default.pa) the following config:

# create virtual sink named Mic and loopback USB Microphone to virtual sink
load-module module-null-sink sink_name=Mic
load-module module-loopback source=alsa_input.usb-Thomann_SC450USB-00.iec958-stereo sink=Mic source_dont_move=true sink_dont_move=true
set-default-source Mic.monitor

this creates a "null-sink" which does not go away when some device is detached because it does not belong to any device, which also has a corresponding monitor source which TS3 can use as a permanent source. then a loopback is created from the microphone to the null sink. now restart pulseaudio:

pulseaudio -k

now you need to make sure that TS3 uses the Mic monitor as a source permanently by opening pavucontrol and making sure that under the "Recording" tab "TeamSpeak3" is bound to "Monitor of Null Output" in the dropdown.

normally this would be enough, but pulseaudio does not re-attach the loopback once the microphone is re-connected. for that to happen we need udev.

first create a script that can be called by udev:

sudo nano /usr/local/bin/udev_sound

and add the following script:

#!/bin/bash

# check if microphone is mounted already
while ! $(pactl list sources|grep -q 'alsa_input.usb-Thomann_SC450USB-00.iec958-stereo')
do
  let "n += 1"
  sleep 1
  if [ "$n" -eq 10 ]
    then break
  fi
  echo "running"
done

# loopback microphone to null sink
export PULSE_RUNTIME_PATH="/run/user/$(id -u)/pulse/"
pactl load-module module-loopback source=alsa_input.usb-Thomann_SC450USB-00.iec958-stereo sink=Mic source_dont_move=true sink_dont_move=true

now make the script executable:

sudo chmod +x /usr/local/bin/udev_sound

this will check for a time period of 10 seconds if the microphone is attached, and if yes, create the pulseaudio loopback again that was removed when the microphone was detached.

now lets create a udev rule starting the script when when the device is re-attached:

sudo nano /lib/udev/rules.d/91-someNameYouWillRecogniseAsYours.rules

with the following content:

ACTION=="add", SUBSYSTEM=="sound", ATTR{id}=="SC450USB", RUN+="/bin/su YOURuSERnAME -c 'screen -d -m /usr/local/bin/udev_sound'"

now restart udev:

sudo /etc/init.d/udev restart

this checks if a device with a certain id is added (attached) and runs the script we just created under your username (don't forget to change it). this is important since on most system pulseaudio is run in userland. screen -d -m is important so the script is run non-blocking, otherwise the microphone would not be attached until the script did end running.

your device-specific command will most likely look different, what "ATTR" and other identifiers to use depends on your device, how to find that out is described a million times online.

this should be it. now everytime the microphone is re-attached the script creates the loopback, and TS3 should all that time be listening to the null sinks monitor thinking it is a real microphone.

in all these steps replace "alsa_input.usb-Thomann_SC450USB-00.iec958-stereo" with whatever your device is named like!

overall i can say i hate udev. it has a million special things it handles different than a normal linux system and it is nearly impossible to debug. i never want to see it again.

TimeWaster

Posted 2018-11-27T15:20:26.973

Reputation: 11