From ec892832d250a5fd3dacea2f64e6614859bbb684 Mon Sep 17 00:00:00 2001 From: Jael Gu Date: Wed, 8 Jun 2022 10:28:12 +0800 Subject: [PATCH] Remove torchaudio Signed-off-by: Jael Gu --- torch_vggish.py | 2 +- vggish_input.py | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/torch_vggish.py b/torch_vggish.py index 671239e..6c2bbf0 100644 --- a/torch_vggish.py +++ b/torch_vggish.py @@ -54,7 +54,7 @@ class Vggish(NNOperator): self.model.to(self.device) def __call__(self, datas: List[NamedTuple('data', [('audio', 'ndarray'), ('sample_rate', 'int')])]) -> numpy.ndarray: - audios = numpy.stack([item.audio for item in datas]) + audios = numpy.hstack([item.audio for item in datas]) sr = datas[0].sample_rate audio_array = numpy.reshape(audios, (-1, 1)) audio_tensors = self.preprocess(audio_array, sr).to(self.device) diff --git a/vggish_input.py b/vggish_input.py index 856a406..4297ba8 100644 --- a/vggish_input.py +++ b/vggish_input.py @@ -23,8 +23,6 @@ import resampy import mel_features import vggish_params -import torchaudio - def waveform_to_examples(data, sample_rate, return_tensor=True): """Converts audio waveform into an array of examples for VGGish. @@ -80,17 +78,3 @@ def waveform_to_examples(data, sample_rate, return_tensor=True): return log_mel_examples -def wavfile_to_examples(wav_file, return_tensor=True): - """Convenience wrapper around waveform_to_examples() for a common WAV format. - - Args: - wav_file: String path to a file, or a file-like object. The file - is assumed to contain WAV audio data with signed 16-bit PCM samples. - torch: Return data as a Pytorch tensor ready for VGGish - - Returns: - See waveform_to_examples. - """ - data, sr = torchaudio.load(wav_file) - wav_data = data.detach().numpy().transpose() - return waveform_to_examples(wav_data, sr, return_tensor)