pred_ppg_c
Closed this issue · 2 comments
EmreOzkose commented
Hi, thank you for sharing code.
In whisperconvert_longaudio , there is from preprocess_ppg import pred_ppg_c
, but actually there is not any pred_ppg_c
function. Can you share that ?
moonnee commented
hi, you can add codes below to preprocess_ppg.py. I find this works.
def pred_ppg_c(whisper: Whisper, wavPath):
audio, sr = librosa.load(wavPath,sr=None)
if len(audio) >= sr * 29:
print(wavPath,"cut to 29s")
audio = audio[:sr * 29]
#librosa.output.write_wav("your_audio_file.wav", audio, sr)
sf.write(wavPath, audio, sr)
audio = load_audio(wavPath)
audln = audio.shape[0]
ppgln = audln // 320
# audio = pad_or_trim(audio)
mel = log_mel_spectrogram(audio).to(whisper.device)
with torch.no_grad():
ppg = whisper.encoder(mel.unsqueeze(0)).squeeze().data.cpu().float().numpy()
if ppgln>ppg.shape[0]:
print("ppgln>ppg.shape[0]")
ppg = ppg[:ppgln,] # [length, dim=1024]
#if audln // 320<ppg.shape[0]:
# print("audln // 320<ppg.shape[0]")
return ppg
EmreOzkose commented
thank you