Function Repository Resource:

Ding

Source Notebook

Generate the ding sound of a tiny bell

Contributed by: Jules Manson

ResourceFunction["Ding"][]

generates an audible ding at maximum volume 1.

ResourceFunction["Ding"][vol]

generates an audible ding at a set volume vol.

Details

ResourceFunction["Ding"] is meant to be an alternative to Beep for producing ResourceFunction["Ding"]/Beep pass/fail audible alerts after completion of time intensive calculations, on evaluation of critical events whose results are not immediately viewable, or upon execution of background tasks.
Plays a sound note of pitch G6 for a duration of 0.333 seconds.
All mentions of volume are relative to the current volume level on computer or device.
Only integer, rational, or real values in the range 0 to 1 are valid. Mathematical functions that reduce to a positive number within range may work but this is not recommended.
The output of ResourceFunction["Ding"] is Null.

Examples

Basic Examples (4) 

Generate a ding at the default volume of 1:

In[1]:=
ResourceFunction["Ding"][]

Generate a ding at moderate volume with a rational number 3/4:

In[2]:=
ResourceFunction["Ding"][3/4]

Generate a ding at half volume:

In[3]:=
ResourceFunction["Ding"][0.5]

Values greater than 1 are clipped to 1 but a warning message is issued:

In[4]:=
ResourceFunction["Ding"][1000]

Scope (2) 

Contrast Ding with Beep using a Do loop to repeat sounds:

In[5]:=
Do[(ResourceFunction["Ding"][]; Pause[3]; Beep[]; Pause@3;), {3}]

Generate a ding to alert on True condition:

In[6]:=
If[True, (ResourceFunction["Ding"][]; True), (Beep[]; False), (Do[(ResourceFunction["Ding"][]; Pause[0.1];), {3}]; Indeterminate)]
Out[6]=

Generate a Beep to alert on False condition:

In[7]:=
If[False, (ResourceFunction["Ding"][]; True), (Beep[]; False), (Do[(ResourceFunction["Ding"][]; Pause[0.1];), {3}]; Indeterminate)]
Out[7]=

Generate a quick triple ding to alert on Indeterminate condition:

In[8]:=
If[Indeterminate, (ResourceFunction["Ding"][]; True), (Beep[]; False), (Do[(ResourceFunction["Ding"][]; Pause[0.15];), {3}]; Indeterminate)]
Out[8]=

Applications (2) 

Create an audible alert with Ding after a long calculation completes:

In[9]:=
Timing[Module[{beeg = Iconize[PadeApproximant[MittagLefflerE[4, x], {x, 1, 5}], "beeg output"], x}, ResourceFunction["Ding"][]; beeg]]
Out[9]=

Define a function for a TimeConstrained expression alerting Ding with returned results or Beep on $Aborted:

In[10]:=
conexpr[t_] := With[{
   label = Sequence["conexpr[", t, "] \[Rule] "],
   expr := Timing[(sum = 0; Do[sum += i, {i, 10000000}]; ResourceFunction["Ding"][]; sum)],
   failexpr := (Beep[]; $Aborted)
   },
  Row[{label, TimeConstrained[expr, t, failexpr]}]
  ]

To ensure we see the two cases we need to evaluate with excessive constraints. First we do excessively short:

In[11]:=
conexpr[1]
Out[11]=

Now we try an excessively long constraint:

In[12]:=
conexpr[10]
Out[12]=

Possible Issues (2) 

Only one ding can be heard because all notes will be produced on top of one another:

In[13]:=
(ResourceFunction["Ding"][]; ResourceFunction["Ding"][]; ResourceFunction["Ding"][])

Add a short Pause after every ding:

In[14]:=
(ResourceFunction["Ding"][]; Pause[0.15]; ResourceFunction["Ding"][]; Pause[0.15]; ResourceFunction["Ding"][]; Pause[0.15];)

Neat Examples (1) 

Emulate the classic ringing of a rotary phone:

In[15]:=
Do[(Pause[6]; Do[(ResourceFunction["Ding"][]; Pause[.13]), 18]), 5];

Publisher

Jules Manson

Version History

  • 1.0.0 – 14 June 2022

Related Resources

Author Notes

Jules Manson took time off from from his engineering duties to return to CSULB as a Physics student. While there he was introduced to Mathematica as a required course and instantly fell in love with it. He is active at Mathematica Stack Exchange (and other communities on SE) and Quora. If you like his work you can find more of his content (Wolfram packages) over at GitHub.

License Information