From 7bc2dfea6e0fdbe75a55dce560a3438d144daa58 Mon Sep 17 00:00:00 2001 From: jlqian98 Date: Wed, 4 Mar 2026 15:02:34 +0800 Subject: [PATCH] update example code for each preprocess module --- preprocess/tools/f0_extraction.py | 6 +++--- preprocess/tools/lyric_transcription.py | 22 ++++++++++++-------- preprocess/tools/note_transcription/model.py | 19 ++++++++++++----- preprocess/tools/vocal_detection.py | 2 +- preprocess/tools/vocal_separation/model.py | 10 ++++----- 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/preprocess/tools/f0_extraction.py b/preprocess/tools/f0_extraction.py index 5ec2cf7..d14cc12 100644 --- a/preprocess/tools/f0_extraction.py +++ b/preprocess/tools/f0_extraction.py @@ -516,12 +516,12 @@ class F0Extractor: if __name__ == "__main__": model_path = ( - "pretrained_models/rmvpe/rmvpe.pt" + "pretrained_models/SoulX-Singer-Preprocess/rmvpe/rmvpe.pt" ) - audio_path = "./outputs/transcription/test.wav" + audio_path = "example/audio/zh_prompt.mp3" pe = F0Extractor( model_path, device="cuda", ) - f0 = pe.process(audio_path) + f0 = pe.process(audio_path, f0_path="example/audio/zh_prompt_f0.npy") diff --git a/preprocess/tools/lyric_transcription.py b/preprocess/tools/lyric_transcription.py index a0b5d2d..7843564 100644 --- a/preprocess/tools/lyric_transcription.py +++ b/preprocess/tools/lyric_transcription.py @@ -120,9 +120,10 @@ class _ASRZhModel: raw_timestamps = [[t[0] / 1000, t[1] / 1000] for t in out["timestamp"]] words, word_durs = _build_words_with_gaps(raw_words, raw_timestamps, wav_fn) - if os.path.exists(wav_fn.replace(".wav", "_f0.npy")): + f0_path = os.path.splitext(wav_fn)[0] + "_f0.npy" + if os.path.exists(f0_path): words, word_durs = _word_dur_post_process( - words, word_durs, np.load(wav_fn.replace(".wav", "_f0.npy")) + words, word_durs, np.load(f0_path) ) return words, word_durs @@ -179,9 +180,10 @@ class _ASREnModel: words, durs = _build_words_with_gaps(raw_words, raw_timestamps, wav_fn) - if os.path.exists(wav_fn.replace(".wav", "_f0.npy")): + f0_path = os.path.splitext(wav_fn)[0] + "_f0.npy" + if os.path.exists(f0_path): words, durs = _word_dur_post_process( - words, durs, np.load(wav_fn.replace(".wav", "_f0.npy")) + words, durs, np.load(f0_path) ) return words, durs @@ -248,8 +250,10 @@ class LyricTranscriber: if self.en_model is None: # Lazy-load NeMo model only when English is actually used. if v: - print("[lyric transcription] init English ASR, please make sure NeMo is installed") + print("[lyric transcription] init English ASR start, please make sure NeMo is installed and wait for a while") self.en_model = _ASREnModel(model_path=self.en_model_path, device=self.device) + if v: + print("[lyric transcription] init English ASR success") out = self.en_model.process(wav_fn) else: out = self.zh_model.process(wav_fn) @@ -271,9 +275,9 @@ class LyricTranscriber: if __name__ == "__main__": m = LyricTranscriber( - zh_model_path="pretrained_models/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch", - en_model_path="pretrained_models/parakeet-tdt-0.6b-v2/parakeet-tdt-0.6b-v2.nemo", + zh_model_path="pretrained_models/SoulX-Singer-Preprocess/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch", + en_model_path="pretrained_models/SoulX-Singer-Preprocess/parakeet-tdt-0.6b-v2/parakeet-tdt-0.6b-v2.nemo", device="cuda" ) - print(m.process("example/test/asr_zh.wav", language="Mandarin")) - print(m.process("example/test/asr_en.wav", language="English")) \ No newline at end of file + print(m.process("example/audio/zh_prompt.mp3", language="Mandarin")) + print(m.process("example/audio/en_prompt.mp3", language="English")) \ No newline at end of file diff --git a/preprocess/tools/note_transcription/model.py b/preprocess/tools/note_transcription/model.py index 4a20e2c..53c3153 100644 --- a/preprocess/tools/note_transcription/model.py +++ b/preprocess/tools/note_transcription/model.py @@ -509,14 +509,23 @@ class NoteTranscriber: if __name__ == "__main__": - items = json.load(open("example/test/rosvot_input.json", "r")) - item = items[0] + item = { + 'item_name': 'vocal_0', + 'wav_fn': 'example/audio/zh_prompt.mp3', + 'start_time_ms': 320, + 'end_time_ms': 10687, + 'origin_wav_fn': 'example/audio/zh_prompt.mp3', + 'duration': 10367, + 'words': ['', '除', '了', '想', '你', '', '除', '了', '爱', '你', '', '我', '什', '么', '什', '么', '都', '愿', '意'], + 'word_durs': [0.21, 0.36, 0.26, 0.7000000000000001, 0.96, 0.3800000000000001, 0.43999999999999995, 0.3799999999999999, 0.6400000000000001, 0.9600000000000002, 1.1199999999999999, 0.28000000000000025, 0.3799999999999999, 0.3199999999999994, 0.3200000000000003, 0.3799999999999999, 0.3200000000000003, 0.5, 1.457981859410431], + 'language': 'Mandarin' + } m = NoteTranscriber( - rosvot_model_path="pretrained_models/rosvot/rosvot/model.pt", - rwbd_model_path="pretrained_models/rosvot/rwbd/model.pt", + rosvot_model_path="pretrained_models/SoulX-Singer-Preprocess/rosvot/rosvot/model.pt", + rwbd_model_path="pretrained_models/SoulX-Singer-Preprocess/rosvot/rwbd/model.pt", device="cuda" ) - out = m.process(item) + out = m.process(item, segment_info=item) print(out) \ No newline at end of file diff --git a/preprocess/tools/vocal_detection.py b/preprocess/tools/vocal_detection.py index ac4a751..87bf499 100644 --- a/preprocess/tools/vocal_detection.py +++ b/preprocess/tools/vocal_detection.py @@ -316,5 +316,5 @@ class VocalDetector: if __name__ == "__main__": m = VocalDetector(cut_wavs_output_dir="outputs/transcription/cut_wavs") - segment_infos = m.process("./outputs/transcription/test.wav") + segment_infos = m.process("example/audio/zh_prompt.mp3", np.load("example/audio/zh_prompt_f0.npy")) print(segment_infos) diff --git a/preprocess/tools/vocal_separation/model.py b/preprocess/tools/vocal_separation/model.py index ce6679c..b4ee8bf 100644 --- a/preprocess/tools/vocal_separation/model.py +++ b/preprocess/tools/vocal_separation/model.py @@ -214,12 +214,12 @@ class VocalSeparator: if __name__ == "__main__": m = VocalSeparator( - sep_model_path="pretrained_models/mel-band-roformer-karaoke/mel_band_roformer_karaoke_becruily.ckpt", - sep_config_path="pretrained_models/mel-band-roformer-karaoke/config_karaoke_becruily.yaml", - der_model_path="pretrained_models/dereverb_mel_band_roformer/dereverb_mel_band_roformer_anvuew_sdr_19.1729.ckpt", - der_config_path="pretrained_models/dereverb_mel_band_roformer/dereverb_mel_band_roformer_anvuew.yaml", + sep_model_path="pretrained_models/SoulX-Singer-Preprocess/mel-band-roformer-karaoke/mel_band_roformer_karaoke_becruily.ckpt", + sep_config_path="pretrained_models/SoulX-Singer-Preprocess/mel-band-roformer-karaoke/config_karaoke_becruily.yaml", + der_model_path="pretrained_models/SoulX-Singer-Preprocess/dereverb_mel_band_roformer/dereverb_mel_band_roformer_anvuew_sdr_19.1729.ckpt", + der_config_path="pretrained_models/SoulX-Singer-Preprocess/dereverb_mel_band_roformer/dereverb_mel_band_roformer_anvuew.yaml", device="cuda" ) - out = m.process("example/test/separation_test.mp3") + out = m.process("example/audio/zh_prompt.mp3") print(out.vocals_dereverbed.shape)