..or just attach a speaker to the Pi's analog 3.5mm jack !kghunt wrote:The pi doesn't have an internal speaker. You will need to attach one to the GPIOs.
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.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.
Code: Select all
from pygame import mixer
mixer.init()
alert=mixer.Sound('bell.wav')
alert.play()
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.mikerr wrote:To play a wav file:...
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!mikerr wrote:For a low latency beep you could preload/generate a square wave into an array, and play that.
