Bug in Python 3.13 wave module? getnchannels() error on cleanup.

Posted by Common_Base657@reddit | Python | View on Reddit | 7 comments

Hey everyone,

I ran into a really strange error today while working with the built-in wave module in Python 3.13 and thought I'd share in case anyone else encounters this or has some insight.

I was trying to do something very basic: generate a simple sine wave and save it as a WAV file using the standard library. My code was the textbook example, using wave.open() inside a with statement to handle the file.

The weird part is that my script runs, but then throws this error right at the end, seemingly during the internal cleanup process after the with block closes the file:

wave.Error: # channels not specified

My code to set the channels (wav_file.setnchannels(1)) is definitely there and in the correct order before writing the frames, so it doesn't seem to be a problem with my script's logic. It feels like the library is failing internally when the file object is being destroyed.

Has anyone else seen this with Python 3.13? Is this a known bug in the new version?

Thanks!