-
Notifications
You must be signed in to change notification settings - Fork 1.2k
resolve dependencies #1426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resolve dependencies #1426
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,8 +2,6 @@ | |||||||||||||||||||
| import torch, torchvision, imageio, os | ||||||||||||||||||||
| import imageio.v3 as iio | ||||||||||||||||||||
| from PIL import Image | ||||||||||||||||||||
| import torchaudio | ||||||||||||||||||||
| from diffsynth.utils.data.audio import read_audio | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| class DataProcessingPipeline: | ||||||||||||||||||||
|
|
@@ -249,23 +247,27 @@ def __call__(self, data): | |||||||||||||||||||
| class LoadAudio(DataProcessingOperator): | ||||||||||||||||||||
| def __init__(self, sr=16000): | ||||||||||||||||||||
| self.sr = sr | ||||||||||||||||||||
| def __call__(self, data: str): | ||||||||||||||||||||
| import librosa | ||||||||||||||||||||
| input_audio, sample_rate = librosa.load(data, sr=self.sr) | ||||||||||||||||||||
| self.audio_loader = librosa.load | ||||||||||||||||||||
|
|
||||||||||||||||||||
| def __call__(self, data: str): | ||||||||||||||||||||
| input_audio, sample_rate = self.audio_loader(data, sr=self.sr) | ||||||||||||||||||||
| return input_audio | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| class LoadAudioWithTorchaudio(DataProcessingOperator, FrameSamplerByRateMixin): | ||||||||||||||||||||
|
|
||||||||||||||||||||
| def __init__(self, num_frames=121, time_division_factor=8, time_division_remainder=1, frame_rate=24, fix_frame_rate=True): | ||||||||||||||||||||
| FrameSamplerByRateMixin.__init__(self, num_frames, time_division_factor, time_division_remainder, frame_rate, fix_frame_rate) | ||||||||||||||||||||
| import torchaudio | ||||||||||||||||||||
| self.audio_loader = torchaudio.load | ||||||||||||||||||||
|
|
||||||||||||||||||||
| def __call__(self, data: str): | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| reader = self.get_reader(data) | ||||||||||||||||||||
| num_frames = self.get_num_frames(reader) | ||||||||||||||||||||
| duration = num_frames / self.frame_rate | ||||||||||||||||||||
| waveform, sample_rate = torchaudio.load(data) | ||||||||||||||||||||
| waveform, sample_rate = self.audio_loader(data) | ||||||||||||||||||||
|
Comment on lines
267
to
+270
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a resource leak here: the
Suggested change
|
||||||||||||||||||||
| target_samples = int(duration * sample_rate) | ||||||||||||||||||||
| current_samples = waveform.shape[-1] | ||||||||||||||||||||
| if current_samples > target_samples: | ||||||||||||||||||||
|
|
@@ -285,10 +287,12 @@ def __init__(self, target_sample_rate=None, target_duration=None): | |||||||||||||||||||
| self.target_sample_rate = target_sample_rate | ||||||||||||||||||||
| self.target_duration = target_duration | ||||||||||||||||||||
| self.resample = True if target_sample_rate is not None else False | ||||||||||||||||||||
| from diffsynth.utils.data.audio import read_audio | ||||||||||||||||||||
| self.audio_loader = read_audio | ||||||||||||||||||||
|
|
||||||||||||||||||||
| def __call__(self, data: str): | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| waveform, sample_rate = read_audio(data, resample=self.resample, resample_rate=self.target_sample_rate) | ||||||||||||||||||||
| waveform, sample_rate = self.audio_loader(data, resample=self.resample, resample_rate=self.target_sample_rate) | ||||||||||||||||||||
| if self.target_duration is not None: | ||||||||||||||||||||
| target_samples = int(self.target_duration * sample_rate) | ||||||||||||||||||||
| current_samples = waveform.shape[-1] | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
LoadAudiooperator returns a numpy array (fromlibrosa.load), whereas other audio operators in this file (likeLoadAudioWithTorchaudioandLoadPureAudioWithTorchaudio) return torch tensors. This inconsistency can cause issues in data pipelines that expect a uniform tensor format. Additionally,LoadAudioonly returns the waveform, while the others return a(waveform, sample_rate)tuple. Consider standardizing the output format across all audio operators.