exploring resourcepackage to handle embedded .wav files

my app plays a couple of sounds. i would like to embed the wav files directly into my app, as i have done with icons.

per suggestion on this list, i am trying resourcepackage. i'm not really familiar with packages, and i find the resourcepackage doc to be thin.

img2py generates a .py file containing my icon, and creates a 'getIcon' method to read it back. this works fine.

i used resourcepackage's 'scan.py' utility to convert my *wav files into *wav.py modules. But i observe there is no special method to read back the encoded .wav file.

in the absence of any special 'getWav' function, i am simply importing the new wav modules. My sound files are stored in 'data' attributes of the *wav.py modules.

wx.Sound() takes a filename arg, or a resource arg, followed by a boolean indicating the arg type.

i assume that my py-encoded wav files should be considered resource files.

wx.Sound plays files, but not the embedded .wav data. Do I need to 'decode' the embedded .wav files somehow? wx.Sound reports
Sound.IsOk(),meaning the load was successful.

I attach wav.py, a small app that plays files successfully, but remains silent when embedded .wav modules are imported and played. I also attach the original .wav files and the generated *wav.py modules

to run wav.py, you need to create a Sound directory and put the wavs and wav.py modules into that directory.

i assume i am either misusing resourcepackage, or i am mishandling wx.Sound(). any thoughts are appreciated.

wav.py (2.24 KB)

EXPLODE.WAV (23 KB)

DRUMROLL_WAV.py (20.5 KB)

DRUMROLL.WAV (19 KB)

EXPLODE_WAV.py (24.8 KB)

Jim Peterson wrote:
...

per suggestion on this list, i am trying resourcepackage. i'm not really familiar with packages, and i find the resourcepackage doc to be thin.

Sorry about that.

img2py generates a .py file containing my icon, and creates a 'getIcon' method to read it back. this works fine.

Which would be about the same *if* there were a mechanism for loading a .wav file from a data-string (which is how img2py and resourcepackage work). The getIcon is just regular Python code that loads the data-string.

i assume that my py-encoded wav files should be considered resource files.

Looking at the docs for wxSound I *don't* see any way to load from a string or stream, so you may very well be SOL for this. There's an undocumented extra constructor for wx.Sound with the signature:

    wx.Sound( size, data )

which looks like what you're looking for, but it doesn't appear to actually be implemented under the covers. I've attached a version of your file that attempts to use that constructor, but with wxPython 2.5 it just gives an exception. Possibly Robin can comment on when/whether that constructor will be implemented.

wx.Sound plays files, but not the embedded .wav data. Do I need to 'decode' the embedded .wav files somehow? wx.Sound reports
Sound.IsOk(),meaning the load was successful.

I'm surprised that returns okay, the "resources" there are almost certainly asking for names for loading from a DLL.

Good luck,
Mike

wav.py (2.08 KB)

···

________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/
  blog: http://zope.vex.net/~mcfletch/plumbing/

Jim Peterson wrote:

wx.Sound plays files, but not the embedded .wav data. Do I need to 'decode' the embedded .wav files somehow? wx.Sound reports
Sound.IsOk(),meaning the load was successful.

I attach wav.py, a small app that plays files successfully, but remains silent when embedded .wav modules are imported and played. I also attach the original .wav files and the generated *wav.py modules

For the record, I was testing Sound.IsOk, instead of Sound.IsOk()

This correction reveals that the wx.Sound initialization fails.

Mike C. Fletcher wrote:

Looking at the docs for wxSound I *don't* see any way to load from a string or stream, so you may very well be SOL for this. There's an undocumented extra constructor for wx.Sound with the signature:

   wx.Sound( size, data )

running your version of the test program generates a traceback:

Traceback (most recent call last):
   File "C:\JIM\PROJECT\PYTHON\wavtest.py", line 32, in OnResDrum
     sound = wx.Sound(len(drumroll), drumroll)
   File "C:\Python23\Lib\site-packages\wx\misc.py", line 2027, in __init__
     newobj = _misc.new_Sound(*args)
TypeError: No matching function for overloaded 'new_Sound'

which I infer is consistent with the 'not implemented' assessment.

wx.Sound plays files, but not the embedded .wav data. Do I need to 'decode' the embedded .wav files somehow? wx.Sound reports
Sound.IsOk(),meaning the load was successful.

I'm surprised that returns okay, the "resources" there are almost certainly asking for names for loading from a DLL.

Alas, it doees not return okay. I was trying

if wx.Sound.IsOk:

instead of

if wx.Sound.IsOk()

I bow my head in shame.

Mike C. Fletcher wrote:

Looking at the docs for wxSound I *don't* see any way to load from a string or stream, so you may very well be SOL for this. There's an undocumented extra constructor for wx.Sound with the signature:

   wx.Sound( size, data )

which looks like what you're looking for, but it doesn't appear to actually be implemented under the covers. I've attached a version of your file that attempts to use that constructor, but with wxPython 2.5 it just gives an exception. Possibly Robin can comment on when/whether that constructor will be implemented.

Yep. There was a bug in the typemap declaration that prevented it from being used in 2.5.1.5. It's been fixed and tested in the current CVS and I also backed off from using overloading for that constructor so it is now:

  sound = wx.SoundFromData(data)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!