I'm trying to create a beeping sound to be played on my speakers from the shell.

I can easily accomplish this using aplay, but, it takes a second or so before it actually plays.

I need to have it practically instant, as I'm using it in a (headless) shell script to play a sound on a keypress. Using aplay the beep comes way too late.

I'm thinking to write something directly to a /dev sound device or something, but haven't been successful with this yet.

I'm using a Odroid-W (Raspberry Pi-clone), and have heard that, at least on the Pi, the audio jack is actually wired to two PWM GPIO pins (40, 45), writing to these pins directly however yields only silence.

It doesn't need to be a fancy sound, any buzz or beep will do.

(if all fails then I'll probably wire a GPIO pin to a makeshift mixer and connect that to the amp.)

  • 1
    There is the BEL character which should produce a beep assuming that terminal feature is enabled and connected to some sound producing something...
    – thrig
    Apr 17, 2017 at 18:36
  • I think this is maybe supposed to have one of those "PC speakers" wired up. It did not output sound to the speakers for me.. en.wikipedia.org/wiki/Bell_character
    – svenema
    Apr 17, 2017 at 19:17
  • Any nontrivial audio will also depend on your platform. The aplay I suppose suggests Linux with ALSA?
    – tripleee
    Apr 17, 2017 at 19:23
  • If you have latencies of a second, something in your audio setup is definitely wrong. Look at your logs for errors. The RaspPi uses the PWM (pulse-width modulation) output to produce sound, so yes, writing to the GPIO pins instead of using the PWM registers will produce nothing. The kernel driver will write to the PWM registers for you, and should do this fast enough, under normal cirumstances.
    – dirkt
    Apr 17, 2017 at 19:26
  • @tripleee: Yes, Debian Jesse
    – svenema
    Apr 17, 2017 at 19:41

1 Answer 1


As latency is important for the "feel" of the application (audible user feedback) I have decided to produce it by connecting an active buzzer (the active part here eliminates the need of a PWM output) to one of the gpio pins, this produces sound instantly. GPIO pins can be accessed directly using Drogons WiringPi command line utility. Downside is that you don't have control over the sound itself, but the beep that is produced is good enough for now.

To improve/control sound, one could look into a software PWM and a passive buzzer or speaker.

More information on WiringPi: http://wiringpi.com/

What's an active buzzer?: https://electronics.stackexchange.com/questions/224374/active-vs-passive-buzzer

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.