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
@@ -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()