rearranged repo

This commit is contained in:
Plachta
2023-04-21 21:17:45 +08:00
parent 05dbf649a1
commit eb7eb8a022
9 changed files with 46 additions and 22 deletions
+21 -21
View File
@@ -1,22 +1,22 @@
import os import os
import json import json
import torchaudio import torchaudio
raw_audio_dir = "./raw_audio/" raw_audio_dir = "./raw_audio/"
denoise_audio_dir = "./denoised_audio/" denoise_audio_dir = "./denoised_audio/"
filelist = list(os.walk(raw_audio_dir))[0][2] filelist = list(os.walk(raw_audio_dir))[0][2]
# 2023/4/21: Get the target sampling rate # 2023/4/21: Get the target sampling rate
with open("./configs/finetune_speaker.json", 'r', encoding='utf-8') as f: with open("./configs/finetune_speaker.json", 'r', encoding='utf-8') as f:
hps = json.load(f) hps = json.load(f)
target_sr = hps['data']['sampling_rate'] target_sr = hps['data']['sampling_rate']
for file in filelist: for file in filelist:
if file.endswith(".wav"): if file.endswith(".wav"):
os.system(f"demucs --two-stems=vocals {raw_audio_dir}{file}") os.system(f"demucs --two-stems=vocals {raw_audio_dir}{file}")
for file in filelist: for file in filelist:
file = file.replace(".wav", "") file = file.replace(".wav", "")
wav, sr = torchaudio.load(f"./separated/htdemucs/{file}/vocals.wav", frame_offset=0, num_frames=-1, normalize=True, wav, sr = torchaudio.load(f"./separated/htdemucs/{file}/vocals.wav", frame_offset=0, num_frames=-1, normalize=True,
channels_first=True) channels_first=True)
# merge two channels into one # merge two channels into one
wav = wav.mean(dim=0).unsqueeze(0) wav = wav.mean(dim=0).unsqueeze(0)
if sr != target_sr: if sr != target_sr:
wav = torchaudio.transforms.Resample(orig_freq=sr, new_freq=target_sr)(wav) wav = torchaudio.transforms.Resample(orig_freq=sr, new_freq=target_sr)(wav)
torchaudio.save(denoise_audio_dir + file + ".wav", wav, target_sr, channels_first=True) torchaudio.save(denoise_audio_dir + file + ".wav", wav, target_sr, channels_first=True)
@@ -1,6 +1,7 @@
from moviepy.editor import AudioFileClip from moviepy.editor import AudioFileClip
import whisper import whisper
import os import os
import json
import torchaudio import torchaudio
import librosa import librosa
import torch import torch
@@ -28,6 +29,9 @@ if __name__ == "__main__":
'zh': "[ZH]", 'zh': "[ZH]",
} }
assert(torch.cuda.is_available()), "Please enable GPU in order to run Whisper!" assert(torch.cuda.is_available()), "Please enable GPU in order to run Whisper!"
with open("./configs/finetune_speaker.json", 'r', encoding='utf-8') as f:
hps = json.load(f)
target_sr = hps['data']['sampling_rate']
model = whisper.load_model(args.whisper_size) model = whisper.load_model(args.whisper_size)
speaker_annos = [] speaker_annos = []
for file in filelist: for file in filelist:
@@ -62,7 +66,7 @@ if __name__ == "__main__":
print(f"Transcribed segment: {speaker_annos[-1]}") print(f"Transcribed segment: {speaker_annos[-1]}")
# trimmed_wav_seg = librosa.effects.trim(wav_seg.squeeze().numpy()) # trimmed_wav_seg = librosa.effects.trim(wav_seg.squeeze().numpy())
# trimmed_wav_seg = torch.tensor(trimmed_wav_seg[0]).unsqueeze(0) # trimmed_wav_seg = torch.tensor(trimmed_wav_seg[0]).unsqueeze(0)
torchaudio.save(savepth, wav_seg, 22050, channels_first=True) torchaudio.save(savepth, wav_seg, target_sr, channels_first=True)
if len(speaker_annos) == 0: if len(speaker_annos) == 0:
print("Warning: no long audios & videos found, this IS expected if you have only uploaded short audios") print("Warning: no long audios & videos found, this IS expected if you have only uploaded short audios")
print("this IS NOT expected if you have uploaded any long audios, videos or video links. Please check your file structure or make sure your audio/video language is supported.") print("this IS NOT expected if you have uploaded any long audios, videos or video links. Please check your file structure or make sure your audio/video language is supported.")
+20
View File
@@ -0,0 +1,20 @@
import os
import json
import argparse
import torchaudio
def main():
with open("./configs/finetune_speaker.json", 'r', encoding='utf-8') as f:
hps = json.load(f)
target_sr = hps['data']['sampling_rate']
filelist = list(os.walk("./sampled_audio4ft"))[0][2]
if target_sr != 22050:
for wavfile in filelist:
wav, sr = torchaudio.load("./sampled_audio4ft" + "/" + wavfile, frame_offset=0, num_frames=-1,
normalize=True, channels_first=True)
wav = torchaudio.transforms.Resample(orig_freq=sr, new_freq=target_sr)(wav)
torchaudio.save("./sampled_audio4ft" + "/" + wavfile, wav, target_sr, channels_first=True)
if __name__ == "__main__":
main()