473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

wave.readframes() (or conversion?)

Hi to all,
I'm using wave module with success. I'm writing data to wave file.
Typically I create a list of values (data) and pass it to
..writeframes(data) methods.

a = wave.open("/test.wav", "w")
a.writeframes([32000, 0])

This sets the first sample to 32000 and the 2nd to 0

But when I use the .readframes() method I don't know exactly what
values I extract from the open wave.
a = wave.open("/test.wav", "r")
a.readframes(1)

'\x00\x00'
What does it mean? (hexa?)
How do I convert it to an integer? I'd like to have it like 32000 or 0,
so to make some maths on it.

Thanks a lot

-a-

Andrea Valle
Laboratorio multimediale "G. Quazza"
Facoltà di Scienze della Formazione
Università degli Studi di Torino
an**********@unito.it
Jul 18 '05 #1
2 5296
andrea valle <an**********@unito.it> wrote:

I'm using wave module with success. I'm writing data to wave file.
Typically I create a list of values (data) and pass it to
.writeframes(data) methods.

a = wave.open("/test.wav", "w")
a.writeframes([32000, 0])
What version of Python are you using?? On my Win32 Python 2.3, writeframes
accepts only strings, and only after you have set the frame rate, sample
size, and number of channels.
But when I use the .readframes() method I don't know exactly what
values I extract from the open wave.
a = wave.open("/test.wav", "r")
a.readframes(1)

'\x00\x00'
What does it mean? (hexa?)
How do I convert it to an integer? I'd like to have it like 32000 or 0,
so to make some maths on it.


You get back a buffer of bytes. You can use the array() module to convert
it to a list of integers.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #2
Tim Roberts <ti**@probo.com> wrote:
andrea valle <an**********@unito.it> wrote:

I'm using wave module with success. I'm writing data to wave file.
Typically I create a list of values (data) and pass it to
.writeframes(data) methods.

a = wave.open("/test.wav", "w")
a.writeframes([32000, 0])


What version of Python are you using?? On my Win32 Python 2.3, writeframes
accepts only strings, and only after you have set the frame rate, sample
size, and number of channels.


For those who may be following this at home, Andrea and I had a private
e-mail exchange during which we discovered why HE was able to pass a list
of integers to wave.writeframes, while I got an error saying that it had to
be a string.

Turns out he's using a Mac, which is big-endian. On big-endian systems,
wave.writeframes passes its first parameter to array.array, calls byteswap,
and uses array.tofile to write it out. array.array accepts a list.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: david.kettle | last post by:
Hello Python World! I've been playing with the 'wave' and 'audioop' modules in the library, and I have a question. When I tried to read a "wav" file with samples in 32-bit float, I got the...
6
by: Xanax | last post by:
Hi all, I need to produce a sine wave and use the WaveOut APi to sound it on my sound card. I also need to compute Fast Fourier Transform to modify the Sine wave. Any ideas on where to start or...
4
by: vikram | last post by:
in a stereo type of wave file i want to know what is this left & right info in a wave file??? how do i read the left & right info from a .wav file to a buffer..
5
by: m.topczewski | last post by:
Hello, I'm a beginner in c++, i have to write a program that will take couple of segments from one wave file, and store them in another wave file to be played back later. Here's the code i have...
0
by: Simrat Kaur Sandhu | last post by:
hello friends can anybody tell me how to read data from a wave file.. i have writen code as ... class file { private: FILE *fp; char id; char *sound_buffer; //four bytes to hold 'RIFF' long...
0
by: Karthik | last post by:
Hi, I want to record a sound wave from a mic and at the same time invert it and play the inverted wave.My code goes as follows, however nothing is written into the E:\inverted.wav file.Thanks in...
1
by: homevista | last post by:
Part II: Wave file - How to read to a buffer Wave (or Wav) is the standard format for storing audio data on the PC. As software developers, we are interested in the internal structure of the file...
6
by: homevista | last post by:
PART III: Putting things together In part I we examined the modem to verify that it supported voice. If so, we took a note about the voice data format that we would use. In the second part, we...
1
by: Cole | last post by:
hey guys. when i use the readframes() function it returns bytecode. how would i convert that to integers???
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.