Narf03
Posts: 243
Joined: Mon Jun 11, 2012 3:44 pm
Location: Malaysia

How do I play a beep sound

Sat Jul 07, 2012 7:01 pm

Simple question, but I tried hours googling and testing, still doesn't work with Pi + python + Debian, how to make a beep sound ? Thanks.

kghunt
Posts: 383
Joined: Sun Mar 04, 2012 9:28 am

Re: How do I play a beep sound

Sun Jul 08, 2012 8:48 pm

The pi doesn't have an internal speaker. You will need to attach one to the GPIOs.

mikerr
Posts: 2825
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: How do I play a beep sound

Mon Jul 09, 2012 1:53 pm

kghunt wrote:The pi doesn't have an internal speaker. You will need to attach one to the GPIOs.
..or just attach a speaker to the Pi's analog 3.5mm jack !
Android app - Raspi Card Imager - download and image SD cards - No PC required !

Narf03
Posts: 243
Joined: Mon Jun 11, 2012 3:44 pm
Location: Malaysia

Re: How do I play a beep sound

Mon Jul 09, 2012 4:07 pm

Err this is python area, so I'm expecting some codes :?
Thanks, and ya I got 3.5 mm jack connected and capable of playing music.

MadCow42
Posts: 106
Joined: Sun Jul 01, 2012 12:48 am

Re: How do I play a beep sound

Mon Jul 09, 2012 4:29 pm

Narf03 wrote:Err this is python area, so I'm expecting some codes :?
Thanks, and ya I got 3.5 mm jack connected and capable of playing music.
Actually I need to do something similar... encode two clock signals into an audio signal (left/right stereo). I was thinking that because I'm already doing a lot of GPIO output in the same system, the lowest overhead method might be to simply connect two GPIO pins to a line-out cable (with appropriate resistors... which I'll have to figure out still) and modulate the GPIO accordingly. You could probably do that to generate a beep at a certain frequency if you needed... but it's a kludge.

Anyone tinker with this stuff yet?

Kevin.

mikerr
Posts: 2825
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: How do I play a beep sound

Mon Jul 09, 2012 4:54 pm

To play a wav file:

Code: Select all

from pygame import mixer
mixer.init() 
alert=mixer.Sound('bell.wav')
alert.play()
Android app - Raspi Card Imager - download and image SD cards - No PC required !

MadCow42
Posts: 106
Joined: Sun Jul 01, 2012 12:48 am

Re: How do I play a beep sound

Mon Jul 09, 2012 5:02 pm

mikerr wrote:To play a wav file:...
Thanks Mike - my needs are a bit unique and wacky, so I may fall back on PyGame but my audio won't be coming from a file - it'll have to be dynamically generated (a timing signal - basically just a series of ticks at very specific times). Also, timing/lag/overhead is a huge potential issue, so I'm concerned that PyGame may be too heavy for my "simple" needs.

But - all options are still on the table until I've actually done testing!

Kevin

mikerr
Posts: 2825
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: How do I play a beep sound

Mon Jul 09, 2012 6:43 pm

For a low latency beep you could preload/generate a square wave into an array, and play that.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

MadCow42
Posts: 106
Joined: Sun Jul 01, 2012 12:48 am

Re: How do I play a beep sound

Mon Jul 09, 2012 6:51 pm

mikerr wrote:For a low latency beep you could preload/generate a square wave into an array, and play that.
Yes... but to be difficult, it won't be a constant speed. I'll have to deal with slight variations, along with ramp-up and ramp-down, etc. Unfortunately the precision I'm looking for is (unrealistically?) high. I know Debian isn't real-time, but at least I can expect perfect correlation between "move stepper motor one step" and "now make one tick on the clock output". I couldn't get there trying to time to a WAV output I don't think. But - I do appreciate the suggestions!

Kevin.

kghunt
Posts: 383
Joined: Sun Mar 04, 2012 9:28 am

Re: How do I play a beep sound

Mon Jul 09, 2012 7:02 pm

I just harvested a little beeper from a broken board that was lying around and attached it to a gpio and gnd.

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: How do I play a beep sound

Mon Jul 09, 2012 7:22 pm

....but they are usually +5volt devices, but let us know if it works ;)


T.
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

kghunt
Posts: 383
Joined: Sun Mar 04, 2012 9:28 am

Re: How do I play a beep sound

Mon Jul 09, 2012 7:23 pm

"I just" was past tense. It works fine. :-)

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: How do I play a beep sound

Tue Jul 10, 2012 6:35 am

Jolly good :) Useful to know.

T.
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Kampfsemmel
Posts: 1
Joined: Sat Apr 25, 2015 10:45 am
Location: Austria

Re: How do I play a beep sound

Sat Apr 25, 2015 10:50 am

Hi, everyone!

I guess that this is the right thread for this.
I am completely new to Raspberry and even Linux at all, but so far I am very pleased with all the possibilities it provides compared to a Windows system.
I found an old BIOS-Speaker with a pin connector some days ago and wondered if it would be possible to use it with the Pi.
The first useful idea I had about that was to just play a short beep after successful boot to know, when booting has completed.

I know that might not sound interesting for you guys, but I did not find anything helpful for a noob like me.
Any suggestions how to do it?

Thanks!
free open NTP-Server running raspbian: gasslfeld.at

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13092
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How do I play a beep sound

Sat Apr 25, 2015 3:33 pm

actually the PWM audio coming out the A/V output is actually generated by to GPIO's that can be driven by a PWM generator, (and normally are by the audio driver) but they are also normal GPIO's that can be controlled directly like any others (or you could directly control the PWM engine).
they are GPIO40 (right audio) and GPIO45 (left audio).

see the BCM2835-ARM-Peripherals data sheet to fid out how. https://www.raspberrypi.org/documentati ... herals.pdf

gsgs
Posts: 134
Joined: Sun Dec 13, 2015 6:48 pm
Location: Germany
Contact: Website

Re: How do I play a beep sound

Sat Dec 26, 2015 3:04 pm

don't we have "in" and "out" assembly commands as I'm used to have with x86 ?
Then a small assembly program to produce tones of desired frequency
and length for the ear-port or some of the pins or TV-speaker.
In GWBasic there was a play-command or just beep

------------------------------------------

quick search:
http://www.keil.com/forum/5182/
from 2004

The ARM architecture doesn't specify a
separate I/O space -- everything is memory-
mapped, so:

1) There are no dedicated (fast-path) I/O
instructions -- load and store is all you
get.
2) All I/O goes out over an external bus;
this may or may not cost much, but it's
(architecturally) there.

we can toggle I/O lines at about 8MHz

Dealing with input/output (I/O) activity can be the central challenge for many
real-time programmers because routine desktop computing successfully hides
its complexity, structure and dynamics.

https://books.google.de/books?id=sWDEBQ ... ut&f=false

sorry for the long url, I don't know what infos google all packed into it

---------------------------------------------
viewtopic.php?t=39897&p=328160
--------------------------------------------

https://www.cl.cam.ac.uk/projects/raspb ... /ok03.html
-------------------------------------------------





looking for a simple executable that writes a value x to port y
or reads the value from port y

very fundamental. Very important. Does it exist ?

Return to “Python”