Question

I am trying to save a wav file. data is an numpy array with data type of int16. When I run my code, it give me following error, which I don't understand.

wf.setsampwidth(p.get_sample_size(pyaudio.paInt16))
TypeError: unbound method get_sample_size() must be called with PyAudio instance as first argument (got int instance instead)
Exception wave.Error: Error('sample width not specified',) in <bound method Wave_write.__del__ of <wave.Wave_write instance at 0x02B777D8>> ignored 

My Code:

p = pyaudio.PyAudio
wf = wave.open(Config.WAVE_FORMATTED_OUTPUT_FILENAME, 'wb')
wf.setnchannels(Config.CHANNELS)
wf.setsampwidth(p.get_sample_size(Config.FORMAT))
wf.setframerate(Config.RATE)
wf.writeframes(b''.join(data))
wf.close()

My Config

class Config():
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"
WAVE_FORMATTED_OUTPUT_FILENAME = "new_output.wav"

The big picture is:

I extracted out data from the wav file. I am appending image bits at the end of a data array. Now saving the data in back in wav format.

Was it helpful?

Solution

Maybe you meant:

p = pyaudio.PyAudio()

instead of

p = pyaudio.PyAudio
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top