Set GPIO pin high when audio is playing and low when audio is stopped

Hi there, i’m trying to switch a relais to power up my amp when sound is playing. Audio is playing on my DAC. The DAC is audio card 1. The pin I want to switch is GPIO4 (pin 7). How can I get this to work. Can someone help me with this?

Thanks in advance

Is there someone who can help me with this?

Hello! How is the DAC connected to your Raspberry Pi? Is it through USB? If so, you could probably use Python (or a preferred language) to read data coming in from the serial port and then use it to switch the GPIO pins. Can you provide a schematic or the type of DAC which you are using?

Yes i can. The DAC I’m using is this one from amazon: Raspiaudio

I know how to switch the GPIO pins with python but I don’t know how to detect is the pi is playing sound or not.

Can you help me out?

There are quite a few options for detecting audio. One way is to check whether your sound card is outputting a signal. This might be a way to do it detect audio output - Raspberry Pi Forums .

You can also use a python script for capturing noises: How get sound input from microphone in python, and process it on the fly? - Stack Overflow

You could also add a sound detector to your setup How to Detect Sound With the Raspberry Pi - Circuit Basics . Although, it might also detect other noises in the environment.

It seems like your audio shield is comapitable with alsamixer. I would look into alsamixer and see if you can use it to check whether your speaker is making noise and then see how you can access the data from alsamixer using python. Here is a tool for accessing alsa using python: GitHub - larsimmisch/pyalsaaudio: ALSA wrappers for Python