Is it possible to use the power from the headphone jack line out to
amplify the signal in order to get the speaker to be louder?
Here's the thing: The power in the headphone jack is in the audio itself. The power in a normal wall outlet is 50/60Hz AC. The power in a headphone jack is also AC and in the frequencies that you want for your audio! There is no additional power contained in a headphone jack other than the audio itself.
So, if you could somehow convert the power in the headphone jack into something useful and convert it back into a form for driving a speaker, and could do it with 100% efficiency then you would end up with exactly what came out of the headphone jack in the first place.
In short: You can't amplify the power without another source of power. But all is not lost!
What you really want is louder audio, and a way to do that is to make your speaker more efficient. Speaker efficiency is usually expressed as "sensitivity" and is specified as XX dB at 1 meter at 1 watt. A normal speaker is 75 to 90 dB (@ 1 meter @ 1 watt). It might not look like it, but 75-90 dB is a huge range! You can simply get or build a speaker with better efficiency.
Another thing that effects efficiency is the speaker enclosure itself, and the type of speaker. Look into horn speakers. There are horn speakers that have sensitivities up to 105 dB (@1m@1w). Although these will likely be too large for your application, it might be interesting anyway.
Driving an 8 ohm speaker with a headphone jack is questionable. Some devices will do this just fine. Some devices might distort but otherwise be fine. And other devices might be permanently damaged. Unfortunately there is no good way to find out without just trying it.
In theory you could make an impedance matching transformer that would show a proper load to the headphone amplifier, but who's output is good enough to drive an 8 ohm speaker. Just keep in mind that a transformer will not increase the power, only convert the form of that power so different devices can play nice together. I have not seen such a transformer for sale, but I also have not looked for one. But in theory you could make one.
Given all the different issues, if it were me I would figure out a way to make a small battery pack with an amplifier in it. Yes, it's bigger than what you want. But it will probably be the best compromise between volume, size, cost, and robustness.
An op-amp would be the best choice. Simpler than that is a single transistor pre-amp.
Should be powered by the same input range you need, and it will be biased Vin/2.
Alternatively, you can move R1 after the input dc-blocking cap C1, and lose C2.
Best Answer
What you are looking for is called Automatic Gain Control (AGC). Many audio ADCs have AGC (I've personally used the PCM1870).
If you wish to use your MCU's ADC, I can think of a few options:
As a footnote let me warn you that if you roll your own gain logic/controller, adjustments must be made slowly and care must be taken as to not introduce audible artifacts or distortion.