[Tutor] How can Python use the head phone jack?
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Thu, 23 May 2002 06:40:31 -0700 (PDT)
On Thu, 23 May 2002 alan.gauld@bt.com wrote:
> > OK, what I'm really asking is, is there anyway for Python to convert
> > data into two different sounds (e.g. a high sound for "1" and a low
> > sound for "0") and send it out to the speaker/audio/headphone jack?
>
> Yes but its platform dependant. But Python does have sound functions and
> PyGame has quite sophisticated support based, I believe, on DirectX on
> Windows
You can find out more about the pygame library here:
http://pygame.org
I haven't tried this yet, but you could probably using pygame.sndarray to
generate beeps and pauses. You might want to talk with the pygame folks
about this. They have a separate mailing list for pygame here:
http://www.pygame.org/info.shtml#maillist
You can probably grab data from a file, byte by byte, and play the
individual bits of each byte. Something like:
###
import sys, pygame
def playSoundByte(byte):
## Do some beeps here for each bit. Dunno what this will
## look like yet, but it probably involves a little
## bit shifting.
pass
if __name__ == '__main__':
myfile = open(sys.argv[1])
for byte in myfile.read():
playSoundByte(byte)
###
I don't quite know how to access the microphone from pygame; try asking
on the pygame mailing list for that one.
> > rid of or use those old audio tapes and then I thought it'd be really
> > cool to make Python use the ausio tapes for storage, like the
> > Commodore 64.
>
> Hmm, That wasn't even cool on the C64! :-)
Even so, this sounds like a very fun project, even if it is "impractical".
Toy problems are great, in spite of (or because of) their limited
practicality: no one else has probably done it yet. *grin*
James, go for it!