Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
genisplaja committed Nov 28, 2024
1 parent 4d4e5b8 commit ac31c0c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/environment-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ dependencies:
- pip:
- "keras<3.0.0"
- "tensorflow>=2.12.0,<2.16"
- "torch==2.0.0"
- "torchaudio==2.0.1"
- "torch==1.13"
- "torchaudio"
- "essentia"
- "soundfile>=0.12.1"
- "opencv-python~=4.6.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def separate(
clusters=5,
scheduler=4,
chunk_size=3,
normalize_input=True,
gpu="-1",
):
"""Separate singing voice from mixture.
Expand All @@ -103,6 +104,8 @@ def separate(
relevant if the input is an array of data instead of a filepath.
:param clusters: Number of clusters to use to build the separation masks.
:param scheduler: Scheduler factor to weight the clusters to be more or less restirctive with the interferences.
:param chunk_size: Size of the chunks to process the audio signal.
:param normalize_input: Normalize the input audio signal.
:param gpu: Id of the available GPU to use (-1 by default, to run on CPU), use string: '0', '1', etc.
:return: Singing voice signal.
"""
Expand Down Expand Up @@ -153,6 +156,12 @@ def separate(
f"Downsampling to mono... your audio is stereo, \
and the model is trained on mono audio."
)

if normalize_input:
# Normalizing audio for better performance overall
mean = tf.reduce_mean(mixture, keepdims=True)
std = tf.math.reduce_std(mixture, keepdims=True)
mixture = (mixture - mean) / (1e-6 + std)

output_voc = np.zeros(mixture.shape)
hopsized_chunk = int((chunk_size * self.sample_rate) / 2)
Expand Down
7 changes: 5 additions & 2 deletions tests/melody/test_deepsrgm.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def _get_features():
feat = deepsrgm.get_features(
os.path.join(TESTDIR, "resources", "melody", "pitch_test.wav")
)
feat_1 = deepsrgm.get_features(np.zeros(44100))
feat_2 = deepsrgm.get_features(
feat_1 = deepsrgm.get_features(np.zeros([44100]))
feat_2 = deepsrgm.get_features(np.zeros([1, 44100]))
feat_3 = deepsrgm.get_features(np.zeros([2, 44100]))
feat_3 = deepsrgm.get_features(np.zeros([44100, 2]))
feat_4 = deepsrgm.get_features(
os.path.join(TESTDIR, "resources", "melody", "pitch_test.wav")
)

Expand Down
16 changes: 8 additions & 8 deletions tests/melody/test_essentia_extractors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pytest
import librosa

import numpy as np

Expand All @@ -15,9 +16,9 @@ def _predict_normalized_pitch():
pitch = melodia.extract(
os.path.join(TESTDIR, "resources", "melody", "pitch_test.wav")
)
pitch_2 = melodia.extract(np.zeros(44100))
pitch_3 = melodia.extract(np.zeros(2, 44100)) # Testing input array
pitch_4 = melodia.extract(np.zeros(44100, 2)) # Testing input array
pitch_2 = melodia.extract(np.zeros([44100]))
pitch_3 = melodia.extract(np.zeros([2, 44100])) # Testing input array
pitch_4 = melodia.extract(np.zeros([44100, 2])) # Testing input array

assert isinstance(pitch, np.ndarray)
assert np.shape(pitch) == (699, 2)
Expand Down Expand Up @@ -70,11 +71,10 @@ def _predict_normalized_pitch():
tonic = tonic_multipitch.extract(
os.path.join(TESTDIR, "resources", "melody", "pitch_test.wav")
)
tonic_2 = tonic_multipitch.extract(np.zeros(44100)) # Testing input array
tonic_3 = tonic_multipitch.extract(np.zeros(2, 44100)) # Testing input array
tonic_4 = tonic_multipitch.extract(np.zeros(44100, 2)) # Testing input array


audio = librosa.load(os.path.join(TESTDIR, "resources", "melody", "pitch_test.wav"), sr=44100)[0]
tonic_2 = tonic_multipitch.extract(audio) # Testing input array
tonic_3 = tonic_multipitch.extract(np.stack([audio, audio])) # Testing input array
tonic_4 = tonic_multipitch.extract(np.stack([audio, audio]).T) # Testing input array

assert isinstance(tonic, float)
assert tonic == 157.64892578125
Expand Down

0 comments on commit ac31c0c

Please sign in to comment.