Skip to content

Commit

Permalink
Remove unnecessary import of librosa
Browse files Browse the repository at this point in the history
Signed-off-by: Joaquin Anton <[email protected]>
  • Loading branch information
jantonguirao committed Jun 8, 2024
1 parent cd4ad7b commit 24be184
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
24 changes: 20 additions & 4 deletions dali/test/python/decoder/test_audio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright (c) 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,14 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import scipy.io.wavfile
import librosa
import numpy as np
from nvidia.dali import Pipeline, pipeline_def
import nvidia.dali.fn as fn
import nvidia.dali.ops as ops
import nvidia.dali.types as types
import scipy.io.wavfile
import numpy as np
import os
from test_audio_decoder_utils import generate_waveforms, rosa_resample
from test_audio_decoder_utils import generate_waveforms
from test_utils import compare_pipelines, get_files

names = ["/tmp/dali_test_1C.wav", "/tmp/dali_test_2C.wav", "/tmp/dali_test_4C.wav"]
Expand Down Expand Up @@ -97,6 +98,21 @@ def iter_setup(self):
self.feed_input(self.raw_file, list)


def rosa_resample(input, in_rate, out_rate):
if input.shape[1] == 1:
return librosa.resample(input[:, 0], orig_sr=in_rate, target_sr=out_rate)[:, np.newaxis]

channels = [
librosa.resample(np.array(input[:, c]), orig_sr=in_rate, target_sr=out_rate)
for c in range(input.shape[1])
]
ret = np.zeros(shape=[channels[0].shape[0], len(channels)], dtype=channels[0].dtype)
for c, a in enumerate(channels):
ret[:, c] = a

return ret


def test_decoded_vs_generated():
pipeline = DecoderPipeline()
pipeline.build()
Expand Down
16 changes: 0 additions & 16 deletions dali/test/python/test_audio_decoder_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import math
import librosa


def generate_waveforms(length, frequencies):
Expand All @@ -18,18 +17,3 @@ def window(x):

wave = np.sin(X[:, np.newaxis] * (np.array(frequencies) * (2 * math.pi)))
return wave * window(X)[:, np.newaxis]


def rosa_resample(input, in_rate, out_rate):
if input.shape[1] == 1:
return librosa.resample(input[:, 0], orig_sr=in_rate, target_sr=out_rate)[:, np.newaxis]

channels = [
librosa.resample(np.array(input[:, c]), orig_sr=in_rate, target_sr=out_rate)
for c in range(input.shape[1])
]
ret = np.zeros(shape=[channels[0].shape[0], len(channels)], dtype=channels[0].dtype)
for c, a in enumerate(channels):
ret[:, c] = a

return ret

0 comments on commit 24be184

Please sign in to comment.