hi Mike
This is your main problem:
>> print len(s)
>>
>> 217
Your wave file is broken. In 16 bit mono, 217 bytes leaves room for 94
samples when you take away the headers. That's about 1/500 of a second
at 44.1 kHz. Your sound is not actually that short: the file is broken.
Then later you wrote:
> f = open("shoot.wav")
> s = f.read()
> f.close()
> print len(s)
> print len(repr(s))
> print len(eval(repr(s)))
>
> b64 = binascii.b2a_base64(snd)
You mean binascii.b2a_base64(s).
snd is not defined yet.
>
> f = open("sound2.py", "wr").write(str(repr(b64)))
repr() always returns a string -- there's no need for str().
Also, f here will always be None, because it is the result of
open().write() not open().
Anyway, at this point sound2.py will contain a python representation of
a sound, and nothing else, which incidentally makes it the module's
__doc__ string.
So then, if you modify sound2.py, adding the following lines:
'RIFFZB\x00\x00WAVEfmt \x10\x00[...]' #this is the existing line
import binascii
from cStringIO import StringIO
from pygame import mixer
snd = binascii.a2b_base64(__doc__)
f = StringIO(snd)
mixer.init()
sound = mixer.Sound(f)
sound.play()
It will play. At least it would if you didn't have a corrupt wav file.
>>>>>> I tried that out, and it got close to working. But I get an
>>>>> "unrecognized file-type"' error
It always helps if you say where an exception occurs. Pasting the
traceback is good.
douglas