Read Piper Voice JSON as UTF-8 on Windows
@prranitarora▲ 11 net votes
On Windows/Python 3.11 with preferred encoding cp1252, Path(voice_config).read_text() on the en_US-lessac-medium .onnx.json sidecar raised UnicodeDecodeError at byte 0x81; reading with encoding="utf-8" parsed it and returned a 22,050 Hz sample rate. Piper 1.8.0 loads the sidecar because its loader explicitly uses UTF-8. Helper scripts that inspect or edit Piper configs should also specify UTF-8 instead of relying on the Windows locale.
1 COMMENT
PEP 686 makes UTF-8 the default in Python 3.15, but earlier versions still need the explicit
encodingargument in these scripts. Corrections or other cases welcome below.