update audduio2pose v1.0

This commit is contained in:
Sen Liang committed 2022-04-24 14:06:52 +08:00
1 parent c2797657f8
commit 3a15011f4d
28 files changed
+1817 -483

No files matched your search

+20 -15
View File
@@ -52,9 +52,13 @@ if __name__ == "__main__":
# path_audio = Path("/yrfs/lsen/DATA/Actor2/processing/AA7A9568/audio/audio_trim_120s.wav")
# vid_valid = set(["BU6A9965","BU6A9978"])
path_audio = Path("/mfs/lsen/DATA/Actor3/processing/BU6A9965/audio/audio_trim_60s.wav")
# path_audio = Path("/mfs/lsen/DATA/Actor3/processing/BU6A9965/audio/audio_trim_60s.wav")
# path_audio = Path("/mfs/lsen/DATA/Actor3/processing/BU6A9978/audio/audio_trim_60s.wav")
# path_audio = Path("data/ali_test_d.wav")
path_audio = Path("data/bank-demo.wav")
# path_audio = Path("/mfs/lsen/DATA/Actor2/happy/4R3A0004/audio/audio_trim_60s.wav")
# path_audio = Path("/yrfs/lsen/DATA/Actor1/processing/2-23min/audio/audio_trim_120_120s.wav")
# path_audio = Path("data/test/outputs20220319.wav")
# path_audio = Path("./data/47e6d985dc11469ab7f6f47cc0b5e625_trim.wav")
@@ -81,21 +85,22 @@ if __name__ == "__main__":
# Load data_audio and extract features
# load raw speech
audio_raw, sample_rate = torchaudio.load(path_audio)
print(f"audio_raw shape = {audio_raw.shape}, sr = {sample_rate}, duration = {(len(audio_raw[0])/sample_rate)}")
raw_speech, sample_rate = torchaudio.load(path_audio)
print(f"raw_speech shape = {raw_speech.shape}, sr = {sample_rate}, duration = {(len(raw_speech[0])/sample_rate)}")
if len(audio_raw.shape) == 2:
audio_raw = audio_raw[0]
if len(raw_speech.shape) == 2:
raw_speech = raw_speech[0]
if sample_rate != 16000:
resampler = torchaudio.transforms.Resample(sample_rate, 16_000)
audio_raw = resampler(audio_raw).squeeze().numpy()
print(f"resampling: audio_raw shape = {audio_raw.shape}, sr = {16000}, duration = {(len(audio_raw)/16000)}")
raw_speech = resampler(raw_speech).squeeze().numpy()
sample_rate= 16000
print(f"resampling: raw_speech shape = {raw_speech.shape}, sr = {16000}, duration = {(len(raw_speech)/16000)}")
# padding to
len_align = (audio_raw.shape[0] // 16000 ) * 16000
audio_raw = audio_raw[: len_align]
print(f"after audio_raw shape = {audio_raw.shape}, sr = {sample_rate}, duration = {(len(audio_raw)/sample_rate)}")
len_align = (raw_speech.shape[0] // (16000 // 50) ) * (16000 // 50)
raw_speech = raw_speech[: len_align]
print(f"after raw_speech shape = {raw_speech.shape}, sr = {sample_rate}, duration = {(len(raw_speech)/sample_rate)}")
# load wav2Vec model
print("load Wav2Vec2Model ...")
@@ -106,10 +111,10 @@ if __name__ == "__main__":
# padding half frame length for bed and end
npad = int(0.5 * 16000* ( 1 / 50) + 0.5)
audio_raw = np.pad(audio_raw, pad_width=((npad, npad)), mode="edge")
print(f"after padding audio_raw = {audio_raw.shape}, dtype={audio_raw.dtype}")
pad_speech = np.pad(raw_speech, pad_width=((npad, npad)), mode="edge")
print(f"after padding pad_speech = {pad_speech.shape}, dtype={pad_speech.dtype}")
inputs = processor(audio_raw, sampling_rate=16000, return_tensors="pt")
inputs = processor(pad_speech, sampling_rate=16000, return_tensors="pt")
inputs = inputs.to(device)
with torch.no_grad():
@@ -131,5 +136,5 @@ if __name__ == "__main__":
model.setup(opt) # load model
# model.remove_weightnorm()
model.infer(cond, path_audio, \
f"{path_audio.stem}_infer_{Path(opt.MODEL.path_checkpoint).stem}_epoch_{opt.MODEL.load_epoch:03d}")
path_save = f"{path_audio.stem}_infer_{Path(opt.MODEL.path_checkpoint).stem}_epoch_{opt.MODEL.load_epoch:03d}"
model.infer(cond, raw_speech, path_save)