Emitting a constant sound or note (no interruptions) for a fixed duration is easy, but a dynamic duration, not so easy.

  • $\begingroup$ Is this related? I mean the core method given by @SimonWoods. The locator can be easily transformed to MouseOver. mathematica.stackexchange.com/questions/5304/… $\endgroup$ Aug 20, 2012 at 20:17
  • $\begingroup$ Yes, thanks @vitalykaurov. I think it is related but it still does not generate a perfectly constant sound (free of quick pauses) for a dynamic amount of time. $\endgroup$
    – M.R.
    Aug 20, 2012 at 20:31

2 Answers 2


Is this satisfactory?

 Framed@"Play flute",
 {"MouseEntered" :> EmitSound[Sound@SoundNote["C", 10*^10, "Flute"]],
  "MouseExited" :> EmitSound[Sound@SoundNote[SoundVolume -> 0]] }]
  • $\begingroup$ we answered a couple of seconds apart... although your continuous notion is much larger than mine... $\endgroup$
    – P. Fonseca
    Aug 20, 2012 at 18:24
  • $\begingroup$ @P.Fonseca, hehe, that's right $\endgroup$
    – Rojo
    Aug 20, 2012 at 18:38
  • $\begingroup$ I don't get any sound from this on v7; before I try to debug, any idea why? $\endgroup$
    – Mr.Wizard
    Aug 23, 2012 at 11:26
  • $\begingroup$ @Mr.Wizard, no. If EmitSound run separately works, I would test those events with a Print $\endgroup$
    – Rojo
    Aug 23, 2012 at 12:33
  • $\begingroup$ "MouseEntered" and "MouseExited" are apparently not recognized in version 7. $\endgroup$
    – Mr.Wizard
    Aug 23, 2012 at 12:39

Do you mean something like this:

Mouseover[off,Dynamic[Refresh[EmitSound[Play[Sin[700 t + 25 t Sin[350 t]], {t, 0, 1}]],
UpdateInterval -> 1]; on]]

UPDATE - re-edited

For a "continuous" sound

 Dynamic[EmitSound[Sound[SoundNote["C", 1, "Violin"], SoundVolume -> 0]]; off, 
  UpdateInterval -> 1], 
 Dynamic[EmitSound[Sound[SoundNote["C", 500, "Violin"]]]; on, 
  UpdateInterval -> 1]]


Based on @Rojo EventHandler code, here's an idea for organizing different sound effects on the same notebook:

with the help of NotebookDynamicExpression:

SetOptions[EvaluationNotebook[], NotebookDynamicExpression :> Dynamic[
   inst == "quiet",
   EmitSound[Sound[SoundNote[], SoundVolume -> 0]],
   EmitSound[Sound[SoundNote[note, 500, inst]]]
   TrackedSymbols :> {inst}]

and here is a small interface:

notes = {"C", "D", "E", "F", "G", "A", "B"}; instruments = {"Violin", 
  "Flute", "Piano", "Guitar"};
    Framed[#[[2]]], {"MouseEntered" :> {inst = #[[1]]; 
       note = #[[2]];}, "MouseExited" :> {inst = "quiet"}}] &, 
  Table[{i, n}, {i, instruments}, {n, notes}], {2}], 
 ItemSize -> {2, 2}]

(sorry for the formatting, I still have troubles with this...)

  • 1
    $\begingroup$ This is nice but is not constant, the breaks inbetween are what I'm trying to avoid. $\endgroup$
    – M.R.
    Aug 20, 2012 at 18:07
  • $\begingroup$ @Mike I'm still looking for a solution for that... $\endgroup$
    – P. Fonseca
    Aug 20, 2012 at 18:08
  • $\begingroup$ @rojo Nice, but I still hear momentary pauses. And did you know UpdateInterval -> 1 is an option to Dynamic, you don't need the Refresh call $\endgroup$
    – M.R.
    Aug 20, 2012 at 20:20
  • $\begingroup$ @Mike, that thing you wrote was for me or for Fonseca? I don't here any pauses in mine. Beware if you have Fonseca's output showing too when you try mine, because it updates every second to "shut the sound up", so it would shut mine $\endgroup$
    – Rojo
    Aug 21, 2012 at 3:39
  • $\begingroup$ @Rojo Quite right! Your solution has no pauses, so I will accept it, thanks. $\endgroup$
    – M.R.
    Aug 21, 2012 at 5:25

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.