Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
leng-yue committed Mar 30, 2023
1 parent 15c235a commit d259486
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion fish_diffusion/modules/pitch_extractors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .builder import PITCH_EXTRACTORS
from .crepe import CrepePitchExtractor
from .libf0 import PyinPitchExtractor, SaliencePitchExtractor
from .parsel_mouth import ParselMouthPitchExtractor
from .world import DioPitchExtractor, HarvestPitchExtractor
from .libf0 import PyinPitchExtractor, SaliencePitchExtractor

__all__ = [
"PITCH_EXTRACTORS",
Expand Down
32 changes: 16 additions & 16 deletions fish_diffusion/modules/pitch_extractors/libf0.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
import libf0
import numpy as np

from .builder import PITCH_EXTRACTORS, BasePitchExtractor


@PITCH_EXTRACTORS.register_module()
class PyinPitchExtractor(BasePitchExtractor):
def __call__(self, x, sampling_rate=44100, pad_to=None):
Expand All @@ -22,20 +23,19 @@ def __call__(self, x, sampling_rate=44100, pad_to=None):

# Extract pitch using libf0.pyin
pyin_tuple = libf0.pyin(
x[0].cpu().numpy(),
Fs=sampling_rate,
voicing_prob=0.6,
F_min=self.f0_min,
F_max=self.f0_max,
)
x[0].cpu().numpy(),
Fs=sampling_rate,
voicing_prob=0.6,
F_min=self.f0_min,
F_max=self.f0_max,
)

frequencies = pyin_tuple[0]

# Replace NaN frames with zeros
nan_indices = np.isnan(frequencies)
if np.any(nan_indices):
frequencies[nan_indices] = 0


f0 = frequencies

Expand All @@ -45,7 +45,8 @@ def __call__(self, x, sampling_rate=44100, pad_to=None):
# f0 = np.pad(f0, (total_pad // 2, total_pad - total_pad // 2), "constant")

return self.post_process(x, sampling_rate, f0, pad_to)



@PITCH_EXTRACTORS.register_module()
class SaliencePitchExtractor(BasePitchExtractor):
def __call__(self, x, sampling_rate=44100, pad_to=None):
Expand All @@ -66,13 +67,12 @@ def __call__(self, x, sampling_rate=44100, pad_to=None):

# Extract pitch using libf0.salience
salience_tuple = libf0.salience(
x[0].cpu().numpy(),
Fs=sampling_rate,
F_min=self.f0_min,
F_max=self.f0_max,
)
x[0].cpu().numpy(),
Fs=sampling_rate,
F_min=self.f0_min,
F_max=self.f0_max,
)

f0 = salience_tuple[0]

return self.post_process(x, sampling_rate, f0, pad_to)

0 comments on commit d259486

Please sign in to comment.