Emit a beeping sound with JavaScript

Alex Nadalin
Jun 25, 2018 · 2 min read

When you go to your favorite grocery store and the cashier processes your products, he or she will most likely scan them through a barcode scanner which will emit a sound — a sound that’s only there to signal that the scan was successful, and he or she can move onto the next product.

When you develop user interfaces for repetitive tasks, and especially when some sort of scanning is required, it might make a lot of sense to think of giving your users additional feedback so that they don’t have to go back and look at the screen every time they process an action — they can probably simply hear a confirmation sound, or feel an alarming buzz.

Let’s dig a bit deeper.


If you’re giving your users a mobile device, the vibration API is a low-hanging fruit: by just navigator.vibrate(1000) you’ll have a device that buzzes for a second. Want to create interesting patterns? Then do something such as:

  • navigator.vibrate(200), a short buzz indicating the action went fine
  • navigator.vibrate(2000), a long buzz indicating there was some sort of error
  • navigator.vibrate([300, 300, 300]), 3 short buzzes indicating a task is completed

…and so on and so forth: the vibration API is absurdly easy, so I’m simply leaving it for you to experiment with it.


Something a tad better is a snippet I found today, which simplifies audio feedback quite significantly:

You can actually create songs with this kind of stuff (proof).

The WebAudio API is widely supported, so you shouldn’t have too many problems rolling it out across platforms:

At Namshi, we have provided our warehouse agents with devices to store, locate and move inventory — needless to say, combining these 2 APIs (vibration + sound) allows our efficiency to increase while working on more repetitive tasks.

Originally published at odino.org (15th June 2018).
You can follow me on
Twitter — rants are welcome! :)

Alex Nadalin

Written by

CTO at @NamshiDotCom, I like distributed systems, Golang, NodeJS, scalability, software design and µseconds. Writing https://leanpub.com/wasec :wq

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade