Happy new years
This commit is contained in:
1 parent
c7175dd7ff
commit
8c4865effb
53 files changed
+4604
-61
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import librosa
|
||||
import numpy as np
|
||||
from pathlib2 import Path
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
path_data = Path('/yrfs/lsen/DATA/LuoXData/processing2') # '../data/trinity/source'
|
||||
|
||||
v_dir_videos = sorted(path_data.glob("*"), reverse=False)
|
||||
print(f"Have {len(v_dir_videos)} dir files, \n {v_dir_videos[:3]}")
|
||||
|
||||
# for each speaker
|
||||
for i, ipath_data in enumerate(v_dir_videos):
|
||||
vid = ipath_data.stem
|
||||
|
||||
# if i >= 50: continue
|
||||
print(f"\n processing the {i}-th video {vid} ... ")
|
||||
|
||||
ipath_info = ipath_data.joinpath("video/info.json")
|
||||
ipath_audio = ipath_data.joinpath("audio/audio_trim.wav")
|
||||
ipath_save_feat = ipath_data.joinpath("audio/feat_mel_trim.npy")
|
||||
|
||||
# check
|
||||
if not ipath_audio.exists():
|
||||
print(f"NOT existing {ipath_audio}")
|
||||
continue
|
||||
|
||||
if ipath_save_feat.exists():
|
||||
print(f"have existing {ipath_save_feat}")
|
||||
continue
|
||||
|
||||
# load video info
|
||||
with open(str(ipath_info), "r") as f:
|
||||
info = json.load(f)
|
||||
fps = info["fps"]
|
||||
nframes = info["nframes"]
|
||||
print(f"info={info}")
|
||||
assert fps == 50, "fps should be 50"
|
||||
|
||||
|
||||
# load trim audio
|
||||
data, sr = librosa.load(str(ipath_audio), sr= int(0.5 + fps * ( 16000 / fps ))) # 16000 = fps * 640 让这个sr是fps的整数,
|
||||
hop_len = int(sr / fps)
|
||||
n_fft = int(sr * 0.13) # default 2048
|
||||
print(f"data={data.shape}, sr={sr}, fps={fps}, hop_len={sr/fps}, frames = {(len(data) / sr) * fps}, minmax = {np.min(data)},{np.max(data)}")
|
||||
|
||||
# melspectrogram
|
||||
mel = librosa.feature.melspectrogram(y=data, sr=sr,
|
||||
n_fft=n_fft, # FFT窗口的长度
|
||||
hop_length=hop_len, # 帧移
|
||||
win_length=n_fft, # 窗口长度,默认=n_fft
|
||||
window="hann", # 加hanming窗
|
||||
n_mels=27, # 滤波器组
|
||||
fmin=0.0, fmax=8000)
|
||||
mel = np.log(mel+1).T
|
||||
print(f"mel = {mel.shape}, frames = {(len(data) / sr) * fps}, (min,max)=({np.min(mel), np.max(mel)}")
|
||||
|
||||
# align to video
|
||||
if mel.shape[0] < nframes:
|
||||
print(f"\n skip, mel shape ={mel.shape}, frames={(len(data) / sr) * fps}")
|
||||
else:
|
||||
mel_align = mel[:nframes, :]
|
||||
|
||||
# save
|
||||
np.save(ipath_save_feat, mel_align)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user