forked from cgvr/DeltaVR
WIP animate mouth scale based on precalculated voiceline amplitude timelines
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import os
|
||||
import librosa
|
||||
import numpy as np
|
||||
|
||||
# === CONFIG ===
|
||||
FRAME_DURATION = 0.02 # 20 ms windows
|
||||
GAIN = 1.0 # multiply RMS values (set to e.g. 30.0 if you want larger values)
|
||||
EXTENSION = ".txt" # output file extension
|
||||
|
||||
|
||||
def process_wav(filepath):
|
||||
print(f"Processing: {filepath}")
|
||||
|
||||
# Load audio
|
||||
audio, sr = librosa.load(filepath, mono=True)
|
||||
|
||||
# Frame size in samples
|
||||
frame_len = int(FRAME_DURATION * sr)
|
||||
hop_len = frame_len
|
||||
|
||||
# Compute RMS
|
||||
rms = librosa.feature.rms(
|
||||
y=audio,
|
||||
frame_length=frame_len,
|
||||
hop_length=hop_len
|
||||
)[0]
|
||||
|
||||
# Apply optional gain
|
||||
rms = rms * GAIN
|
||||
|
||||
# Save to .txt
|
||||
out_path = os.path.splitext(filepath)[0] + EXTENSION
|
||||
np.savetxt(out_path, rms, fmt="%.8f")
|
||||
|
||||
print(f"Saved RMS → {out_path}")
|
||||
|
||||
|
||||
def process_folder(folder_path):
|
||||
print(f"Scanning folder: {folder_path}")
|
||||
|
||||
for filename in os.listdir(folder_path):
|
||||
if filename.lower().endswith(".wav"):
|
||||
filepath = os.path.join(folder_path, filename)
|
||||
process_wav(filepath)
|
||||
|
||||
print("Done!")
|
||||
|
||||
|
||||
# === Run script ===
|
||||
if __name__ == "__main__":
|
||||
folder = input("Enter folder path: ").strip()
|
||||
process_folder(folder)
|
||||
Reference in New Issue
Block a user