So I want to know if I can connect a headphone jack to an arduino to run sound into a spectrum analyser instead of a mic and how would I go about doing this? I want it to work so if Im playing a game with speakers its comes on and if I using a headset if still works even if there is no external noise
If you want more details, you have to give more details first What have you tried for example?
You must not connect an audio line directly to an Arduino analog pin. It will damage the pin, because an audio signal is ac, so half the waveform is negative. The analog inputs are DC and will be damaged by the negative voltages.
One way to do this is with an msgeq7 chip (maybe 2 left and right channels). This chip can have the audio signal connected directly to it and it analyses the audio in 7 frequency bands and reports the volume in each band to the arduino.
Another item to consider is a DFRobot Audio Analyzer. Works good.
Another item to consider is a DFRobot Audio Analyzer.
Same thing - it contains exactly the chip I was talking about.
How about using two opamps? Similar to this video (from 4:20)
Opamps are way cheaper, tho more coding will be required.
opamps, short for "operational amplifier".