Skip to content

Wave_write throws an error if a setter to an written header information is set to the same value #132445

Open
@ygerlach

Description

@ygerlach

Feature or enhancement

Proposal:

The Wave_write class does not allow to "reset" the same value. This makes some implementations quite complicated, as if you want to continuously append data to the wav file, you need to differentiate between first and the other writes.
Libraries, that use this class (for example piper-tts) are sometimes making it hard to do this right. Which is probably a bug in those libraries, but i think python should make it easier for them to not make this mistake.

import wave

with wave.open(open('out.wav', 'wb'), 'w') as w:
	w.setframerate(44100)
	w.setnchannels(1)
	w.setsampwidth(1)
	w.writeframes(b'0' * 44100)

	w.setframerate(44100)  # should not fail
	w.setnchannels(1)  # should not fail
	w.setsampwidth(1)  # should not fail

	w.setframerate(22050)  # should still fail
	w.setnchannels(2)  # should still fail
	w.setsampwidth(2)  # should still fail

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions