From 2157407b9968ea355f6e6b219718eb4e6a5d4a22 Mon Sep 17 00:00:00 2001 From: Andrew Lunn Date: Thu, 4 Sep 2025 10:28:24 -0500 Subject: [PATCH] _save_wave_file: Use int16 type for sample When writing the audio sample, struct.pack() is used to convert the integer sample value into a byte like object. Using 'i' results in a 4 byte object, where as a 2 byte object is expected. As a result the waveform ends up being twice the required frequency, and so not valid DTMF tones. Use the 'h' formatter, so a int16 is generated. Signed-off-by: Andrew Lunn --- opentone/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentone/__init__.py b/opentone/__init__.py index d7e3ceb..a1c2112 100644 --- a/opentone/__init__.py +++ b/opentone/__init__.py @@ -60,7 +60,7 @@ def _save_wave_file(self, raw_data, file_path): f.setnframes(len(raw_data)) f.setcomptype(self.COMPRESSION_TYPE, self.COMPRESSION_NAME) for i in raw_data: - f.writeframes(struct.pack('i', i)) + f.writeframes(struct.pack('h', i)) f.close() def _get_silence(self, duration_in_ms=None):