Reputation: 335
I'm trying to write to a wav file in Python 3 using the wave module, but I get a 'sample width not specified' exception. Why is this?
def write_sample(path, sample):
"""Writes a sample to a file at path location
Arguments:
path -- file path
sample -- sample to be written
"""
with wave.open(path, 'w') as wave_file:
# set up (make generic later)
wave_file.setnchannels(1)
wave_file.setsampwidth(16)
wave_file.setframerate(44100)
sample = struct.pack(f"<{len(sample)}h", sample)
wave_file.writeframesraw(sample)
Upvotes: 1
Views: 3255
Reputation: 335
Solved, misread the .setsampwidth method as n being bits, not bytes
Upvotes: 1