You are not logged in.

#1 2012-05-14 22:10:38

lgeek
Member
From: Europe, Portugal
Registered: 2012-03-09
Posts: 70

Choose Sound Card in Terminal [SOLVED]

I have a USB headset (Microsoft LX 3000) and after I boot i plug it in, and Set it in Gnome-control-center, Sound.
I was wondering if there is a way to set what sound card I want to use by terminal.
Some command, maybe some curses interface?
Thanks.

Last edited by lgeek (2012-05-14 23:57:51)

Offline

#2 2012-05-14 22:21:55

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,564
Website

Re: Choose Sound Card in Terminal [SOLVED]

Check out the alsa page on the wiki, your default asoundrc, then make a ~/.asoundrc.  You can easily do what you want by putting one or two lines in that file.  It would be pretty easy to make a script or set of aliases to switch between two sound cards.

Edit: in fact, you'd probably be best served by setting them both up properly and use alsamixer (curses interface) to control them.

Edit again: perhaps you don't need to do any configuring.  Start alsamixer then hit F6

Last edited by Trilby (2012-05-14 22:24:08)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2012-05-14 22:49:33

lgeek
Member
From: Europe, Portugal
Registered: 2012-03-09
Posts: 70

Re: Choose Sound Card in Terminal [SOLVED]

Thanks for the reply. In alsamixer even if I do what you said (alsamixer F6) lets me select my sound card and when I select my headset, just allows me to set volume to speaker and microphone, but it seems to not activate the headset.
Most of time I have to go in gnome-control-center , Sound and I have to select my headset to actually take effect in most applications.
It's possible to do a script that does this?
aplay -l | grep Microsoft\ LifeChat\ LX-3000
and if that is true set Microsoft LifeChat LX-3000 as "primary" sound card

Offline

#4 2012-05-14 23:14:20

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,564
Website

Re: Choose Sound Card in Terminal [SOLVED]

So the easiest way doesn't work.  Look into asoundrc.  That's also quite easy if you read the wiki.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2012-05-14 23:23:25

lgeek
Member
From: Europe, Portugal
Registered: 2012-03-09
Posts: 70

Re: Choose Sound Card in Terminal [SOLVED]

Wiki on ArchLinux or Wiki on Alsa?
https://wiki.archlinux.org/index.php/ALSA OR http://www.alsa-project.org/main/index. … umentation ?
Is this one right? http://www.alsa-project.org/main/index.php/Asoundrc

Last edited by lgeek (2012-05-14 23:26:28)

Offline

#6 2012-05-14 23:31:55

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Choose Sound Card in Terminal [SOLVED]

lgeek wrote:

Is this one right?

If it works, it's the right one...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#7 2012-05-14 23:34:41

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,564
Website

Re: Choose Sound Card in Terminal [SOLVED]

The alsa wiki has lots of information and is worth perusing.  But for the present issue I think the arch wiki alsa page should be plenty and will keep it simpler.

Figure out how your cards are numbered and look at this same .asoundrc from the wiki

defaults.pcm.card 2
defaults.pcm.device 0
defaults.ctl.card 2

Then you could even write a script something like

#!/bin/bash
if [[ "$1" == "usb" ]]; then
cat <<EOF1 > ~/.asoundrc
defaults.pcm.card 2
defaults.pcm.device 0
defaults.ctl.card 2
EOF1
else
cat <<EOF2 > ~/.asoundrc
defaults.pcm.card 1
defaults.pcm.device 0
defaults.ctl.card 1
EOF2
fi

Just adjust those numbers to match your cards.

Edit: I suppose I should say what the script does.  If you called that script "mysound" and put it somewhere in your path, then you could use commands like "mysound usb" or "mysound default" to choose which device to use.

Last edited by Trilby (2012-05-14 23:37:03)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2012-05-14 23:57:27

lgeek
Member
From: Europe, Portugal
Registered: 2012-03-09
Posts: 70

Re: Choose Sound Card in Terminal [SOLVED]

Thanks for all the support. It is a problem that bothers me alot. Sometimes I plug my headset and it is detected, but Sound is gnome-control-center doesn't allow me to set headset as primary device. If I get that problem any time again, I will run the script and holefully don't need to reboot the computer any more to just get the headset working. One more time, Thanks.

Offline

#9 2012-05-15 00:07:54

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,564
Website

Re: Choose Sound Card in Terminal [SOLVED]

FYI, I'm pretty sure you could have conditionals in an asoundrc.  It may be worth checking on that.  If so you could have something in your ~/.asoundrc that tests whether the headset is available, if so set that as the default, otherwise set the internal sound as default.  If you want to give this a shot, that's where the actual alsa wiki would be more handy.

I've been amazed at how configurable and powerful alsa is when one takes the time to learn about it.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2013-02-20 20:37:17

df3n5
Member
Registered: 2009-04-08
Posts: 25

Re: Choose Sound Card in Terminal [SOLVED]

Solution here worked for me for the Microsoft LX 3000 headset : https://bbs.archlinux.org/viewtopic.php … 44#p763244

Offline

#11 2013-10-31 19:05:01

giner
Member
Registered: 2007-02-28
Posts: 26
Website

Re: Choose Sound Card in Terminal [SOLVED]

If you use pulseaudio then this can help https://aur.archlinux.org/packages/switch-sound

Offline

#12 2015-03-17 05:03:44

DVNO
Member
Registered: 2014-08-10
Posts: 19

Re: Choose Sound Card in Terminal [SOLVED]

Trilby wrote:

The alsa wiki has lots of information and is worth perusing.  But for the present issue I think the arch wiki alsa page should be plenty and will keep it simpler.

Figure out how your cards are numbered and look at this same .asoundrc from the wiki

defaults.pcm.card 2
defaults.pcm.device 0
defaults.ctl.card 2

Then you could even write a script something like

#!/bin/bash
if [[ "$1" == "usb" ]]; then
cat <<EOF1 > ~/.asoundrc
defaults.pcm.card 2
defaults.pcm.device 0
defaults.ctl.card 2
EOF1
else
cat <<EOF2 > ~/.asoundrc
defaults.pcm.card 1
defaults.pcm.device 0
defaults.ctl.card 1
EOF2
fi

Just adjust those numbers to match your cards.

Edit: I suppose I should say what the script does.  If you called that script "mysound" and put it somewhere in your path, then you could use commands like "mysound usb" or "mysound default" to choose which device to use.

WHOA. Nice one mate. I'm running Openbox + basic ALSA backend on my laptop with a Logitech G35 USB Headset plugged in; The little script worked like a charm.

I suppose it's super off-topic but I've been wanting to learn Bash for coding scripts and such... Perhaps you could give me some starting pointers?

Again, thanks for the tip, mate. Cheers!

Offline

#13 2015-03-17 12:03:50

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,564
Website

Re: Choose Sound Card in Terminal [SOLVED]

DVNO, I'm glad that was useful.  But please do not "necrobump" old threads, especially solved ones.

If you want to build on this solution, start a new thread and link back to this one.  If you just want to learn bash scripting, there are many resources out there, and several threads on the forums where they have been collected.  A good starting point would be Greg's wiki.

Closed.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB