I have an old device which has a speaker for sound output. Now I would like to analyze the output of the device by connecting it to the line in port of a computer. As the old device does not have any line out (just the build in speaker) I wonder if it would be possible to open the device, disconnect the wires to the speaker and instead solder it to a 3.5mm sound cable. Then connect the cable to my line in port. Would it be possible to record any sound from the device? The quality of the sound is not that important for the analysis (I just need to detect some alerts and be able to differentiate them).
Yes, probably, but not directly. The output to the speaker has the same waveform as what you want, but it is an amplified signal that has a lot of power to be able to drive the speaker rather than the low level of signal involved in capturing and moving audio signals around in recording gear.
If you directly hooked up the connectors going to the speaker to your audio capture port, you would almost certainly fry your audio capture card and might fry parts of the computer as well. It's way WAY too much power, especially if it was any kind of large speaker.
You could use devices called pads to drop the level of the signal back down, but you would need quite heavy padding to bring an amplified speaker output down to line level and you would need to know the exact power level of the signal to be able to calculate the correct padding. If you don't have fairly clean pads, there's also a decent possibility of such heavy padding introducing it's own distortion.
A preferable approach if you are decent at electronics would be to see if the device has a distinct amplifier in it. If it does, you could possibly grab the line level signal prior to going through the amplifier and capture that directly instead, but it would involve some deeper electronics understanding and likely a bit of soldering.
You could just connect the line-in in parallel but it probably makes more sense to put in a passive DI box (which consists of just a transformer suitable for sound frequency) in between. Without a DI, avoiding ground loops and level mismatches when connecting a speaker output to a sound input becomes more of a hit-and-miss proposition: it might work, or possibly not. DI boxes save you from fiddling around here.