From be5f9627da1c3406d082213d729a2c70efae537c Mon Sep 17 00:00:00 2001 From: CatalinVoss Date: Tue, 16 Mar 2021 09:29:47 -0700 Subject: [PATCH] Don't throw on mono audio any more since everything should work? --- training/coqui_stt_training/util/audio.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/training/coqui_stt_training/util/audio.py b/training/coqui_stt_training/util/audio.py index 8e65c0c7..953b4a4a 100644 --- a/training/coqui_stt_training/util/audio.py +++ b/training/coqui_stt_training/util/audio.py @@ -579,17 +579,18 @@ def get_dtype(audio_format): def pcm_to_np(pcm_data, audio_format=DEFAULT_FORMAT): - if audio_format.channels != 1: - raise ValueError('Mono-channel audio required') + # Handles both mono and stero audio dtype = get_dtype(audio_format) samples = np.frombuffer(pcm_data, dtype=dtype) samples = samples.astype(np.float32) / np.iinfo(dtype).max - return np.expand_dims(samples, axis=1) + + if audio_format.channels == 1: + return np.expand_dims(samples, axis=1) + else: + return samples def np_to_pcm(np_data, audio_format=DEFAULT_FORMAT): - if audio_format.channels != 1: - raise ValueError('Mono-channel audio required') dtype = get_dtype(audio_format) np_data = np_data.squeeze() np_data = np_data * np.iinfo(dtype).max