Why do computers have speakers inside of them that are pretty much only used for stuff before the OS boots? Are there other uses? Why were they added? Do newer computers still have them?
The PC speaker is generally the first output device to be activated during the boot process of an IBM-PC derived computer. Since it is active before the graphics card, it can be used to communicate error codes related to problems that prevent the much more complex initialization of the graphics card to take place. For example the Video BIOS usually cannot activate a graphics card unless working RAM memory is present in the system, while beeping the speaker is doable with just ROM and the CPU registers. Usually, different error codes will be signaled by specific beeping patterns, such as e.g. "one beep; pause; three beeps; pause; repeat". These patterns are motherboard specific and are usually documented in the technical manual of the motherboard.
if you read more, you can catch where they are used. and your last question will be related with type of motherboard ..but for sure, it's rarely used nowadays.
For IBM PC-compatibles, POST beeps. The speaker can be controlled from software, but the interface is very crude, and keeps the CPU fairly busy.
Other computers (Mac, Amiga) have more impressive internal speaker interfaces, and can do more.
Computers played music before they had VDTs. Home computers have had speakers of varying capabilities at least as far back as the Apple 2, whose speaker was no more advanced than the IBM PC's speaker.
The IBM compatible computer world did not have sound cards as "normal" until the mid-nineties, following the success of AdLib and SoundBlaster cards. By that point, the IBM PC platform had existed, with its internal speaker, for more than a decade.
Many motherboards these days have a tiny cylinder attached directly to the board with a tiny buzzer-speaker that does the beeps instead of using a header to attach a separate speaker.
What’s interesting is that even with the replacement of the BIOS with EFI, there is still a need to report errors using bleeps and bloops because if the video card isn’t functioning (or the system cannot boot enough to get to the video card), then there is no way to communicate the problem. (That said, there are POST cards that display errors on a double-digit seven-segment display LED, and some motherboards even come with them built-in.)
Another use for the internal speaker is of course for sounds. Many older games used the speaker for their output, and while plenty no longer work correctly, some still can with the right finagling.
Also, another use is/was for speech. One of my favorite files from the old days—thank goodness I still have it—is
TRAN.EXE It is a small (47KB) program that does speech synthesis with the internal speaker, and does a surprisingly good job of it too. Yes, you heard correctly, speech! on the buzzer! Of course, it doesn’t work well on modern system, certainly not Windows, though I’ll try it in DOS mode (to be accurate it does work in Windows on a fast system, it just plays the sound too fast, so perhaps programs like MoSlo might help). Either way, you can configure DOSBox to emulate the internal speaker and run it in there to see how cool it was.
The internal speaks used to always be pizo-buzzers; a simple speaker that can easily generate different tones. These were initially used mostly for beeping out error codes (especially when the code was related to the video or other output adapter not working), and to get the users attention (more people than you'd think don't look at the screen while typing).
Today they're generally not used much. But they're still there, largely to beep out error codes if your video card fails. Sometimes they'll be connected to the sound card, so the PC can play sounds without having external speakers connected.