Device.beep()

Overview

Plays a tone through the speaker of the mobile device.

Use Cases

You want to play a custom beep with your script.

You want to override the default beeps using WLEvent.on(“Beep”, …); and play custom beep(s) instead. If you want information about playing default beeps, see the Beep event in WLEvent.on().

Remarks

Calls to Device.beep() are asynchronous and added to a beep queue, meaning that this call will immediately return.

Format

Device.beep(frequency, durationMilliseconds, trailingSilence, volume);

Parameter Description Type Required Notes
frequency Tone frequency in hertz. Number Required Integer between 100 and 20000
durationMilliseconds Duration of the tone in milliseconds, where 1000 milliseconds is equal to 1 second. Number Required Integer between 1 and 100000
trailingSilence Amount of time in milliseconds that no tone should be played. Number Required Integer between 0 and 100000
volume Override volume of the generated beep. Number Optional

Number between 0.0 and 1.0 (loudest). If this parameter is undefined, the beep uses the volume set with Device.setBeepVolume().

Added in version 2.1.21

Example 1

Copy
/* The device will beep for a duration of 500 milliseconds
 * with a 50 millisecond trailing silence. 
 */
 
 Device.beep(200,500,50);

Example 2

Copy
/* The scan beep is replaced with a tada.wav.
 */
WLEvent.on("Beep", function (event) {
    if(event.type == "3")
    {
        Device.beepPlayFile("tada.wav");
        event.eventHandled = true;
    }
});

Example 3

Copy
/* The device will beep for a duration of 500 milliseconds
 * with a volume of 0.3 and
 * with a 50 millisecond trailing silence.
 */

Device.beep(2000, 500, 50, 0.3);