From c84eed91002ddad9001cee23c003171e01e31eab Mon Sep 17 00:00:00 2001 From: Jael Gu Date: Wed, 1 Jun 2022 17:10:40 +0800 Subject: [PATCH] Support all int types of audio data Signed-off-by: Jael Gu --- vggish.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/vggish.py b/vggish.py index ab8d014..9b8a054 100644 --- a/vggish.py +++ b/vggish.py @@ -61,10 +61,8 @@ class Vggish(NNOperator): def preprocess(self, frames: List[AudioFrame]): sr = frames[0].sample_rate audio = numpy.hstack(frames) - if audio.dtype == numpy.int32: - audio = audio / 2147483648.0 - elif audio.dtype == numpy.int16: - audio = audio / 32768.0 + ii = numpy.iinfo(audio.dtype) + audio = 2 * audio / (ii.max - ii.min + 1) try: audio = audio.transpose() audio_tensors = vggish_input.waveform_to_examples(audio, sr, return_tensor=True)