Edit: You could actually do this on pre ALSA linux and can possibly do this on modern BSD, OSS created a DSP device which you could write directly too, even from a shell. Assuming memory serves here, I remember writing to /dev/dsp from the shell but it is possible there was some intermediary which I am forgetting about.
SOUND tone, duration
and there was also a
PLAY program-in-some-DSL
that could play a sequence of notes. As I recall the C64 had a sound chip that was better than anything else at the time but there weren't commands to use it from BASIC so you would have to use a few POKE commands to control it directly. That was still pretty efficient because you could write a few bytes to a memory-mapped I/O port and it would play w/o the CPU having to do anything.
Radio Shack came out with more than one "sound card" for the CoCo which worked roughly the same as the SID chip in the C64 though.
I'd say today people have higher standards. The PLAY command on the CoCo was monophonic, "real" music involves multiple notes at the same time (polyphonic) and would have a more complex API to specify. Whether you are using MIDI or FM synthesis or samples the range of configuration you could apply to get the notes you want is vast.
Certainly you could make some library that would let you bang out notes in Python with very little code, but for most people who want to add music to a program I think they'd much rather play an MP3.