As far as I know, Mathematica has never really supported sound in Linux.
The command Play was introduced in version 3,
and the whole sound system overhauled in version 6.
If you search comp.soft-sys.math.mathematica,
you'll find questions going back all the way to version 3.
In version 6, the command EmitSound was introduced.
This now underlies most of the Mathematica sound generation,
but I couldn't find a quick way to fix/hack it for linux,
since EmitSound does some preprocessing
(figuring out what types of objects its been given)
before passing the sound to the frontend to evaluate.
The default sound driver/API used in most linux installs is ALSA (wiki).
It became the default in 2002 in the linux kernel 2.6
and OSS was marked as "depreciated"
(although OSS is still under active development).
Many Linux distributions now use PulseAudio
which sits on top of the underlying ALSA sound.
(Anyone with a better understanding of Linux sound should feel free to edit this!)
Mathematica introduced sound in version 3 (1996) and thus used OSS for its *nix variants.
This is still the case, despite OSS no longer being the default in almost any Linux variant.
Knowing this gives us a possible solution: use an OSS emulation layer
(see, e.g., http://wiki.debian.org/SoundFAQ).
The simplest is to use an userspace mode emulation and run Mathematica through aoss
aoss mathematica
or the PulseAudio equivalent
padsp mathematica
The problem with both of these is that it only works with MIDI sounds,
not with sampled sounds.
At least this is true on my Ubuntu 10.10 system
and the linux system of Scott Kruger (of the WRI Technical Support team).
A bug report has been filed on this issue.
Alternatively, you can load the OSS compatibility into your kernel
apt-get install alsa-oss
modprobe snd_pcm_oss
modprobe snd_mixer_oss
and you can add snd_pcm_oss and snd_mixer_oss to /etc/modules
to load them at boottime.
These modules are not readily available in Ubuntu 10.10
since they decided to remove the backwards compatibility.
I can not test the above without recompiling my kernel...
Since the above OSS emulation is not currently working perfectly,
here's a couple of quick work-arounds based on some of the discussions I've seen
(e.g., a b c) and rewritten to use default ALSA commands.
For sampled sound, use aplay:
ALSASound[snd_, "WAV"] := Module[{playCmd = "aplay", soundFileName},
soundFileName = "/dev/shm/" <> ToString[Unique["MmaSound"]] <> ".wav";
playCmd = playCmd <> " " <> soundFileName;
Export[soundFileName, snd, "WAV"];
Run["(" <> playCmd <> ";" <> "/bin/rm -f " <> soundFileName <> ")&"];]
e.g., ALSASound[Play[Sin[1000 t^2], {t, 0, 1}], "WAV"].
You should also be able to Export straight onto the appropriate /dev/snd/ device...
but I couldn't get that working.
For midi use aplaymidi.
For this to work you need some sort of software/hardware midi synth installed.
I have timidity running on port 128. (See here for help)
ALSASound[snd_, "MIDI"] :=
Module[{playCmd = "aplaymidi", port = "128:0", soundFileName},
soundFileName = "/dev/shm/" <> ToString[Unique["MmaSound"]] <> ".mid";
playCmd = playCmd <> " -p " <> port <> " " <> soundFileName;
Export[soundFileName, snd, "MIDI"];
Run["(" <> playCmd <> ";" <> "/bin/rm -f " <> soundFileName <> ")&"];]
e.g., ALSASound[Sound[SoundNote /@ CharacterRange["A", "G"]], "MIDI"]
You can now wrap the appropriate ALSASound command around any sound object.
You could also redefine Play to use ALSASound:
SetOptions[Play, DisplayFunction -> ((ALSASound[#, "WAV"]; #) &)];
This is essentially equivalent to setting $SoundDisplayFunction,
as recommended by many of the discussions around the internet.
This option setting will play the sound, then output the normal graphics.
Play[Sin[1000 t^2], {t, 0, 1}]

but the start/stop buttons will not work, since they are based on EmitSound.
To make a simple Beep[] equivalent, try
ALSABeep[] := Play[Sin[5000 t], {t, 0, .1},
DisplayFunction -> (ALSASound[#, "WAV"]&)]
Finally, if you install the festival text-to-speech
(or any other text-to-speech program),
then you can replace the Mathematica Speak functionality, e.g.,
FestivalSpeak[str_String] := (Run["(echo \"" <> str <> "\" | esddsp festival --tts)&"];)
FestivalSpeak[expr_] := FestivalSpeak[SpokenString[expr]]