-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
41 lines (30 loc) · 991 Bytes
/
demo.py
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
31
32
33
34
35
36
37
38
39
40
41
from audio_embedding import extract_embeddings
from model_engine import get_model, get_processor
from utils import concat_and_rescale, save_embeddings
from tqdm import tqdm
import pandas as pd
import numpy as np
import uuid
import os
model = get_model()
processor = get_processor()
BLOCK_LENGTH = 1280
TARGET_SR = 16000
# AUDIO_PATH = r"D:\RAS\DVORAK_UMAP\dvorak_01.wav"
# OUTPUT_PATH = f"./outputs/embedding_{uuid.uuid4()}"
root_path = r"D:\RAS\DVORAK_UMAP"
for filename in tqdm(os.listdir(root_path)[13:]):
# File
ABS_PATH = os.path.join(root_path, filename)
OUTPUT_PATH = f"./outputs/embedding_{os.path.splitext(filename)[0]}.npy"
# Extract Embeddings
raw_embeddings = extract_embeddings(
audio_path=ABS_PATH,
model=model,
processor=processor,
block_length=BLOCK_LENGTH,
target_sr=TARGET_SR,
)
embeddings = concat_and_rescale(raw_embeddings)
# Save Embeddings
save_embeddings(OUTPUT_PATH, embeddings)