mob-i-l
Posts: 273
Joined: Sat Dec 29, 2012 2:45 am
Location: Lund, Skåne/Scania, Sweden
Contact: Website Facebook Google+ Twitter YouTube

A beep that works in Raspbian Stretch

Sat Feb 03, 2018 4:08 pm

Here is a Bash-function for Raspberry Pi that beeps with a frequency (Hz) for a time (s) that can have decimals.

Code: Select all

raspi-beep () { ( speaker-test -t sine -c 2 -s 2 -f $1 & TASK_PID=$! ; sleep $2 ; kill -s SIGINT $TASK_PID ) > /dev/null
}

Test:

Code: Select all

raspi-beep 440 .7 ; raspi-beep 880 .5
There is a beep in Raspbian Stretch, but that doesn't work, but you can install it:
sudo apt install beep

I think the original beep should be fixed so that it works with e.g. the songs in https://github.com/ShaneMcC/beeps .

Also
ESC [ 10 ; n ] Set bell frequency in Hz.
ESC [ 11 ; n ] Set bell duration in msec.
does not work in Linux Console (that you can change to by e.g. Ctrl+Alt+F1 in X and back with Ctrl+Alt+F7).

Code: Select all

printf "\e[10;440]\e[11;700]\a\e[10;880]\e[11;500]\a"
should sound as above, but is now silent. See

Code: Select all

man console_codes
. This ought also be fixed.
Have Pi0&1A&1B&1B+&2B&3B&4B w/ Raspbian. Started w/ BASIC on ABC80&ZX81 then Forth, Z80… https://scratch.mit.edu/users/mobluse/ https://github.com/mobluse/ https://twitter.com/mobluse/ https://YouTube.com/MOBiL4u/

User avatar
scruss
Posts: 2548
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: A beep that works in Raspbian Stretch

Sat Feb 03, 2018 8:06 pm

beep is an ancient (c. 2002) command for making the PC Speaker make (horrid, square-wave) noise. As the Raspberry Pi has no PC speaker compatibility (or pcspkr module), it's not likely to work. Also, since beep is an upstream Debian package, the replacement package would have to be called something other than beep. So your compatibility is shot from the outset.

It might be better to convert these scripts to RTTTL or sox/play synth commands.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: A beep that works in Raspbian Stretch

Sat Feb 03, 2018 8:41 pm

like this

Code: Select all

play -n synth .3 sine A

User avatar
scruss
Posts: 2548
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: A beep that works in Raspbian Stretch

Sun Feb 04, 2018 1:01 am

Yup. Or even:

Code: Select all

play -n synth pl "F2" pl "G2" pl "C3" pl "D3" pl "E3" pl "F3" pl "F#3" pl "G3" pl "A3" pl "A#3" pl "B3" pl "C4" pl "C#4" pl "D4" pl "D#4" pl "E4" pl "F4" pl "F#4" pl "G4" pl "G#4" pl "A4" pl "A#4" pl "B4" pl "C5" pl "C#5" pl "D5" pl "D#5" pl "E5" pl "F5" pl "F#5" pl "G5" pl "G#5" pl "A5" pl "A#5" pl "B5" pl "C6" delay 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15 1.2 1.25 1.3 1.35 1.4 1.45 1.5 1.55 1.6 1.65 1.7 1.75 remix - fade 0 6 .1 reverb norm -1
which, if you're of a certain age, you'll remember as the “Bagpuss wakes up” sound. In reality, it's all 36 strings of an Autoharp® strummed slowly with a touch of reverb.

I'd like to hear beep try that one …
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

mob-i-l
Posts: 273
Joined: Sat Dec 29, 2012 2:45 am
Location: Lund, Skåne/Scania, Sweden
Contact: Website Facebook Google+ Twitter YouTube

Re: A beep that works in Raspbian Stretch

Mon Feb 05, 2018 4:31 pm

Thanks!

An alternative to above is after

Code: Select all

sudo apt install sox

Code: Select all

raspi-beep2 () { play -n -c 2 synth $2 sin $1 2> /dev/null; }

Code: Select all

raspi-beep2 440 .7 ; raspi-beep2 880 .5
It is slightly louder. The first alternative is built-in.
Have Pi0&1A&1B&1B+&2B&3B&4B w/ Raspbian. Started w/ BASIC on ABC80&ZX81 then Forth, Z80… https://scratch.mit.edu/users/mobluse/ https://github.com/mobluse/ https://twitter.com/mobluse/ https://YouTube.com/MOBiL4u/

Return to “Raspbian”