Browse Source
Remove torchaudio
Signed-off-by: Jael Gu <mengjia.gu@zilliz.com>
main
2 changed files with
1 additions and
17 deletions
-
torch_vggish.py
-
vggish_input.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) |
|
|
|
|
|
@ -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) |
|
|
|