I think the scipy wavefile function doesn't like Sage ints.  So if
your last line is:

wavfile.write("./noisyholanew.wav",int(44100), xnew)

there are no errors, although when I try to play it (with a input wav
of two sine waves) I don't hear anything.

-M. Hampton

On Sep 20, 10:37 am, j wade <[email protected]> wrote:
> Hello,
>
> I am attempting to create a .wav file from an array in sage using the
> package wavfile.  I am importing a .wav file using the package
> wavfile, and then using the python wavelets package 'pywt' to create
> the array.  Here are the commands:
>
> import pywt, scipy, numpy
> from scipy.io import wavfile
> x=wavfile.read('/directory/file.wav')
> (cA, cD)=pywt.dwt(x[1],'db1')
> xnew=pywt.idwt(cA,cD,'db1')
> wavfile.write("noisyholanew.wav",44100, xnew)
>
> The last command generates the following error message:
> ------------------------------------------------------------------
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "_sage_input_23.py", line 10, in <module>
>     exec compile(u'open("___code___.py","w").write("# -*- coding:
> utf-8 -*-\\n" +
> _support_.preparse_worksheet_cell(base64.b64decode("d2F2ZmlsZS53cml0ZSgibm9pc3lob2xhbmV3LndhdiIsNDQxMDAsIHhuZXcp"),globals())
> +"\\n"); execfile(os.path.abspath("___code___.py"))
>   File "", line 1, in <module>
>
>   File "/tmp/tmpJPm6LZ/___code___.py", line 3, in <module>
>     exec
> compile(u'wavfile.write("noisyholanew.wav",_sage_const_44100 , xnew)
>   File "", line 1, in <module>
>
>   File "/home/jeremy/Programs/sage-4.5.3/local/lib/python2.6/site-
> packages/scipy/io/wavfile.py", line 99, in write
>     fid.write(struct.pack('ihHIIHH', 16, 1, noc, rate, sbytes, ba,
> bits))
> SystemError: Objects/longobject.c:336: bad argument to internal
> function
>
> noisyholanew.wav
> -------------------------------------------------------------------
>
> xnew is the array.  type(xnew) returns <type 'numpy.ndarray'>.
>
> When I run this series of commands in a python shell, I receive no
> error, and a .wav file is generated.
>
> I would like to be able to run this series of commands in sage as
> well.
>
> I am using Sage 4.5.3 (compiled from source) and Python 2.6.4 on
> Ubuntu 9.10.
>
> Thanks!

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to