-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpreprocess.py
More file actions
30 lines (21 loc) · 749 Bytes
/
Copy pathpreprocess.py
File metadata and controls
30 lines (21 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# optional, saves the preprocessed mel spectrogram for improved training efficiency.
from pathlib import Path
from tqdm import tqdm
import mlx.core as mx
from e2_tts_mlx.model import log_mel_spectrogram
import torchaudio
def files_with_extensions(root: Path, extensions: list = ["wav"]):
files = []
for ext in extensions:
files.extend(list(root.rglob(f"*.{ext}")))
files = sorted(files)
return files
path = Path("...").expanduser()
files = files_with_extensions(path)
for file in tqdm(files):
mel_file = file.with_suffix(".mel.npz")
if mel_file.exists():
continue
audio, sr = torchaudio.load(file)
audio = audio.squeeze().numpy()
mx.savez(mel_file.as_posix(), log_mel_spectrogram(audio))