diff --git a/paddlespeech/audiotools/core/__init__.py b/paddlespeech/audiotools/core/__init__.py index b505b7590..3443a7676 100644 --- a/paddlespeech/audiotools/core/__init__.py +++ b/paddlespeech/audiotools/core/__init__.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. from . import util +from ...t2s.modules import fft_conv1d +from ...t2s.modules import FFTConv1D from ._julius import highpass_filter from ._julius import highpass_filters from ._julius import lowpass_filter @@ -24,5 +26,3 @@ from ._julius import SplitBands from .audio_signal import AudioSignal from .audio_signal import STFTParams from .loudness import Meter -from ...t2s.modules import fft_conv1d -from ...t2s.modules import FFTConv1D diff --git a/paddlespeech/audiotools/core/audio_signal.py b/paddlespeech/audiotools/core/audio_signal.py index 7dcb5e120..74e8cac67 100644 --- a/paddlespeech/audiotools/core/audio_signal.py +++ b/paddlespeech/audiotools/core/audio_signal.py @@ -19,7 +19,7 @@ import numpy as np import paddle import soundfile -from .util import random_state, info as utilinfo, ensure_tensor, move_to_device, exp_compat, _get_value, bool_setitem_compat, bool_index_compat +from . import util from ._julius import resample_frac from .display import DisplayMixin from .dsp import DSPMixin @@ -245,10 +245,10 @@ class AudioSignal( -------- >>> signal = AudioSignal.excerpt("path/to/audio", duration=5) """ - info = utilinfo(audio_path) + info = util.info(audio_path) total_duration = info.duration - state = random_state(state) + state = util.random_state(state) lower_bound = 0 if offset is None else offset upper_bound = max(total_duration - duration, 0) offset = state.uniform(lower_bound, upper_bound) @@ -305,7 +305,7 @@ class AudioSignal( duration=5 ) """ - state = random_state(state) + state = util.random_state(state) if loudness_cutoff is None: excerpt = cls.excerpt(audio_path, state=state, **kwargs) else: @@ -533,7 +533,7 @@ class AudioSignal( duration=duration, sr=None, mono=False, ) - data = ensure_tensor(data) + data = util.ensure_tensor(data) if data.shape[-1] == 0: raise RuntimeError( f"Audio file {audio_path} with offset {offset} and duration {duration} is empty!" @@ -574,7 +574,7 @@ class AudioSignal( AudioSignal AudioSignal loaded from array """ - audio_data = ensure_tensor(audio_array) + audio_data = util.ensure_tensor(audio_array) if str(audio_data.dtype) == paddle.float64: audio_data = audio_data.astype("float32") @@ -778,11 +778,11 @@ class AudioSignal( AudioSignal with all tensors moved to specified device. """ if self._loudness is not None: - self._loudness = move_to_device(self._loudness, device) + self._loudness = util.move_to_device(self._loudness, device) if self.stft_data is not None: - self.stft_data = move_to_device(self.stft_data, device) + self.stft_data = util.move_to_device(self.stft_data, device) if self.audio_data is not None: - self.audio_data = move_to_device(self.audio_data, device) + self.audio_data = util.move_to_device(self.audio_data, device) return self def float(self): @@ -1486,7 +1486,7 @@ class AudioSignal( @magnitude.setter def magnitude(self, value): - self.stft_data = value * exp_compat(1j * self.phase) + self.stft_data = value * util.exp_compat(1j * self.phase) return def log_magnitude(self, @@ -1551,17 +1551,17 @@ class AudioSignal( @phase.setter def phase(self, value): # - self.stft_data = self.magnitude * exp_compat(1j * value) + self.stft_data = self.magnitude * util.exp_compat(1j * value) return # Operator overloading def __add__(self, other): new_signal = self.clone() - new_signal.audio_data += _get_value(other) + new_signal.audio_data += util._get_value(other) return new_signal def __iadd__(self, other): - self.audio_data += _get_value(other) + self.audio_data += util._get_value(other) return self def __radd__(self, other): @@ -1569,20 +1569,20 @@ class AudioSignal( def __sub__(self, other): new_signal = self.clone() - new_signal.audio_data -= _get_value(other) + new_signal.audio_data -= util._get_value(other) return new_signal def __isub__(self, other): - self.audio_data -= _get_value(other) + self.audio_data -= util._get_value(other) return self def __mul__(self, other): new_signal = self.clone() - new_signal.audio_data *= _get_value(other) + new_signal.audio_data *= util._get_value(other) return new_signal def __imul__(self, other): - self.audio_data *= _get_value(other) + self.audio_data *= util._get_value(other) return self def __rmul__(self, other): @@ -1704,7 +1704,7 @@ class AudioSignal( key] if self._loudness is not None else None # stft_data = self.stft_data[ # key] if self.stft_data is not None else None - stft_data = bool_index_compat( + stft_data = util.bool_index_compat( self.stft_data, key) if self.stft_data is not None else None sources = None @@ -1742,7 +1742,7 @@ class AudioSignal( self._loudness[key] = value._loudness if self.stft_data is not None and value.stft_data is not None: # self.stft_data[key] = value.stft_data - self.stft_data = bool_setitem_compat(self.stft_data, key, + self.stft_data = util.bool_setitem_compat(self.stft_data, key, value.stft_data) return diff --git a/paddlespeech/audiotools/core/util.py b/paddlespeech/audiotools/core/util.py index 087388b47..234f30d37 100644 --- a/paddlespeech/audiotools/core/util.py +++ b/paddlespeech/audiotools/core/util.py @@ -32,7 +32,6 @@ import soundfile from flatten_dict import flatten from flatten_dict import unflatten -from .audio_signal import AudioSignal from paddlespeech.utils import satisfy_paddle_version from paddlespeech.vector.training.seeding import seed_everything @@ -232,7 +231,7 @@ def ensure_tensor( def _get_value(other): # - + from .audio_signal import AudioSignal if isinstance(other, AudioSignal): return other.audio_data return other @@ -801,6 +800,7 @@ def collate(list_of_dicts: list, n_splits: int=None): batch = {} for k, v in dict_of_lists.items(): if isinstance(v, list): + from .audio_signal import AudioSignal if all(isinstance(s, AudioSignal) for s in v): batch[k] = AudioSignal.batch(v, pad_signals=True) else: @@ -872,6 +872,7 @@ def generate_chord_dataset( """ import librosa + from .audio_signal import AudioSignal from ..data.preprocess import create_csv min_midi = librosa.note_to_midi(min_note)