User avatar
owatnext
Posts: 16
Joined: Thu Sep 08, 2016 1:33 pm

Select Between Multiple Audio Outputs

Wed Oct 05, 2016 2:09 am

Hello.
This question is a bit of a two-parter. I'll go ahead and list the question, then elaborate.
1) Could I hook up a small speaker to the GPIO?
2) Can I have my Pi 3 automatically determine between two or three possible places to output audio? Say… with Python?

Elaboration:
1) I would like to add a small speaker to my Pi 3 by using two of the GPIO ports. Can I do this without subtracting the ability of the 3.5mm audio jack?
If doing this were to disable the jack, could I somehow add (yet another) audio jack? I would like to avoid using USB sound cards, but if that is my only option, it will have to do.

2) Can I possibly write a small background script or program that polls ports and outputs to a certain one if a condition is met?
I would like to have three options for audio output. I would like to have my Pi to, as a baseline, output to the speaker aforementioned, and to poll the headphone jack to see if it is plugged in to. If it is, then it would output to the jack instead of the speaker. If that condition failed, then it would check to see if the HDMI port has activity going on. If it does, then it will route the audio that way, otherwise it would continue to play sound from the speaker.
It would also be helpful if the program continued to run and then if I, say, unplugged the headphone jack, it would default back to the speaker.

Thank you for any help you can provide!
um i like it tha best wen ur nice to me

klricks
Posts: 7154
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Select Between Multiple Audio Outputs

Wed Oct 05, 2016 4:11 am

Depends on what you mean by audio.....
Connecting speakers to GPIO directly would not be possible. You would at least need a transistor driver and/or an amplifying circuit of some sort.

Of course nothing will happen without your own programming or coding specific to each GPIO speaker.

The audio you are going to get will be very primitive. Clicks and pops and squeaks. Square wave generated tones like a PC motherboard speaker, electronic organ etc. Maybe even 'robot' speech .........

If you want real sound then you will need USB sound card(s).......

I don't know of any provision in the RPi to sense headphones or speakers attached to the 3.5mm audio port. Though that could be done with a GPIO and some external circuitry.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

User avatar
owatnext
Posts: 16
Joined: Thu Sep 08, 2016 1:33 pm

Re: Select Between Multiple Audio Outputs

Wed Oct 05, 2016 1:08 pm

klricks wrote:Connecting speakers to GPIO directly would not be possible. You would at least need a transistor driver and/or an amplifying circuit of some sort.
You mean something like this, right? https://learn.adafruit.com/introducing- ... io-outputs
Maybe I could apply the same concept to my Pi 3.

My main goal is to allow for a small external speaker (think like the speaker on your phone) that doesn't need to be high fidelity. It needs to provide distinguishable audio, though.
Second is similar to a phone as well. When you plug in headphones, your phone stops using it's own speaker and opts for the device you introduced.

Thank you. :)
um i like it tha best wen ur nice to me

Return to “Graphics, sound and multimedia”