After waiting for days for my license I now got the opportunity to install Wolfram Mathematica 8 at home. However, neither the Play nor the Speak functions are doing anything as it seems that Mathematica cannot produce any sound output due to unknown reasons. Might anyone have an idea how I can fix this?

  • Does the Mathematica documentation say anything about sound? If there's a configuration somewhere where pulseaudio is a possible setting, select it. – Gilles 'SO- stop being evil' Jun 17 '11 at 18:49
  • @Gilles: I found a "solution" here however apt doesn't know the arts package. Any idea how to install it? – Christian Ivicevic Jun 17 '11 at 19:06
  • Mathematica tries to use OSS, while most linux dists use ALSA. See No sound in Mathematica 8.0.1 under Linux – Simon Jul 8 '11 at 13:12

Ubuntu uses the PulseAudio sound system. It comes with the paplay command to play a sound file. The approach you found on the Ubuntu wiki should work, but you need to use paplay (or some other equivalent program) rather than the now obsolete aRts.

Here's some code adapted from the Ubuntu wiki. Add it to your ~/.Mathematica/Kernel/init.m or to a file that it includes. In addition to running paplay rather than artsplay, I've changed it to pipe the data rather than store it in a temporary file. Untested.

$SoundDisplayFunction =
      stream = OpenWrite["!pacat", BinaryFormat -> True];
      BinaryWrite[stream, ExportString[#1, "WAV"]];
    ] &

See also No sound in Mathematica 8.0.1 under Linux, which reports that a similar approach worked in Mathematica 8 (with ALSA rather than PulseAudio).

|improve this answer|||||
  • 1
    +1; Although to get it working I had to replace OpenWrite["!paplay"] with OpenWrite["!pacat",BinaryFormat -> True]. Also, you get the normal graphics output if you append a #1 to the end of your $SoundDisplayFunction. Finally, I've updated my answer to further discuss OSS (which Mathematica wants to use) versus ALSA/PA (that Ubuntu uses). – Simon Jul 8 '11 at 13:07

The problem is that that version of Mathematica using OSS and that your Ubuntu using ALSA.

Add the following 'sound.m' script to ~/.Mathematica/Kernel:

(* ::Package:: *)

  * Set up a $SoundDisplayFunction for the
  * Linux version of Mathematica and potentially other unixes, too.



$SoundDisplayFunction :=
            Export[$SoundDisplay, #1];
         (* is there a way to get the sample rate, etc. from the audio 
stream? *)
         playCmd = "/usr/bin/play";
         soundFileName = "/tmp/" <> ToString[Unique["sound"]] <> ".wav";
         playCmd = playCmd <> " " <> soundFileName;

         Export[soundFileName, #1, "WAV"];
         Run["/bin/rm -f " <> soundFileName];
        ] &



(********************CODE ENDS***************************)

After creating 'sound.m', add the following line
to ~/.Mathematica/Kernel/init.m :


Restart Mathematica to reload the kernel.

|improve this answer|||||
  • I get a "Set::wrsym: Symbol $SoundDisplayFunction is Protected." error when starting Mathematica Also, I assume everything after "CODE ENDS" should not be in sound.m, right? thanks – Geremia Jan 11 '14 at 2:11
  • Also, when playing sounds in Mathematica, I get this error (although I hear the sound): «Export::infer: "Cannot infer format of file \!(\"stdout\")."» thanks – Geremia Jan 11 '14 at 2:20
  • Also, is there a similar fix as this for CDF Player? – Geremia Jan 11 '14 at 2:26
  • Also, this solution doesn't seem to work with other functions like FrequencyModulation. – Geremia Jan 11 '14 at 2:39

I had the same problem. After upgrading to Mathematica 10, sound generation works on Linux.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.