Jorvan
Jorvan

Reputation: 131

I am stuck with an audio/text thing (using python)

I am trying to get all the info of a .wav file by interpreting it as a text file, but using the next code:

import wave
w = wave.open('C:/Users/jorge/Desktop/Programas/Python/Datos/Si_Canciones/NSYNC - Its Gonna Be Me.wav', 'r') # :P
for i in range(5000):#w.getnframes()):
    frame = w.readframes(i)
    print(frame)

It prints all as I want, but at the end I get something like this:

00\x00\x00\x00\x00\x00\x00\x0
b''
b''
b''
b''
#And the b''s continue for a while

I would like to add something like this in the for, so I don't get rid off those b''s:

    if (something):
        break

But I don't know what that "something" could be. Can someone help me with it? :/

(I stay tuned to your answers and wish you a nice week)

Upvotes: 0

Views: 50

Answers (1)

user8408080
user8408080

Reputation: 2468

The most obvious answer would be

if frame==b"":
    break

But as stated in the docs, there is also a method that gives you the amount of frames; so you might want to use that; enabling you to only iterate through the existing frames. I'm not familiar with the module though.

Upvotes: 1

Related Questions