Switching between Speakers and Headphones
#1
I have written a couple of simple scripts that can switch the speakers and headphones and thought I share it. Pretty straightforward though, but maybe it can be updated to be written in one script and can detect whether the auxiliary port is connected to an auxiliary cable or not.

headphones.sh
Code:
#!/bin/sh
amixer -c 0 set 'Headphone' unmute
amixer -c 0 set 'Line Out' mute

speakers.sh
Code:
#!/bin/sh
amixer -c 0 set 'Headphone' mute
amixer -c 0 set 'Line Out' unmute
  Reply
#2
Dude, you have totally made my day! Thank you!
  Reply
#3
nice! rate up!
  Reply
#4
I updated the script so that instead of having two separate scripts you can have just one.

audioswap.sh
Code:
#!/bin/sh
case "$1" in
    -h|--headphones|headphones|aux)
        echo "Disabling Speakers..."
        amixer -c 0 set 'Line Out'  mute
        echo "Enabling Headphones..."
        amixer -c 0 set 'Headphone' unmute
        echo "Done."
        ;;
    -s|--speakers|speakers)
        echo "Disabling Headphones..."
        amixer -c 0 set 'Headphone' mute
        echo "Enabling Speakers..."
        amixer -c 0 set 'Line Out'  unmute
        echo "Done."
        ;;
    -?|*)
        echo "Usage:"
        echo "\tSpeakers: -h | --headphones | headphones | aux"
        echo "\tHeadphones: -s | --speakers | speakers"
        echo "\tHelp: -? | *"
        ;;
esac
  Reply
#5
Is this something is going to be integrated in the different OS?
  Reply
#6
(07-29-2020, 12:23 PM)natasha Wrote: Is this something is going to be integrated in the different OS?
In Mobian you just use the dropdown in Settings -> Sound to pick the output device. I think it was similar in PmOS when I last tried it, but that was a while back.
  Reply
#7
Absolutely fantastic!
  Reply
#8
So, @DrewTechs , is there any way to slap a button on that script and put it on the desktop (or main screen or whatever it is on the phone)? Sadly, I don't program, but it seems to me that small addition would make the OS's inability to recognize the headphones pretty negligible.

Except for when you're on the phone. ofono doesn't use alsa, I guess?
  Reply
#9
According to this site:

https://gitlab.com/ubports/community-ports/pinephone

earphone does not work on UBports. I m confused. What is working as far as audio is concerned on your UBports Pinephone?
  Reply
#10
(09-05-2020, 12:52 PM)Peter Gamma Wrote: According to this site:

https://gitlab.com/ubports/community-ports/pinephone

earphone does not work on UBports. I m confused. What is working as far as audio is concerned on your UBports Pinephone?

That's strange because I know the speakers and auxiliary ports both work but if you plug in headphones it doesn't automatically change the sound source to the auxiliary port.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)