-
Notifications
You must be signed in to change notification settings - Fork 0
/
saveBin.py
29 lines (23 loc) · 1.01 KB
/
saveBin.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
import librosa
from src import config_env, pca_recomposition
import os
#STFT and basis parameterizations
repo_root = os.path.abspath(os.path.join(__file__, ".."))
env = os.path.abspath(os.path.join(repo_root, "environmentVars.ini"))
config_env.load_ini_env(env)
FRAME_SIZE = int(os.environ.get("frame_size"))
SAMPLE_RATE = int(os.environ.get("sample_rate"))
NUM_COMPONENTS = int(os.environ.get("num_pca_components"))
FRAMES_PER_SEGMENT = int(os.environ.get("frames_per_segment"))
HOP_SIZE = int(FRAME_SIZE/2)
#Things you might want to do
#load resource and obtain log power spectrum
file = repo_root + "/Resources/samplesong.wav"
songname = file.split("/")[-1].split(".")[0]
song, _ = librosa.load(file)
binaryFileName = (songname + "_nc" + str(NUM_COMPONENTS)
+ "_fs" + str(FRAME_SIZE)
+ "_FPS" + str(FRAMES_PER_SEGMENT)
+ "_reconstructed.bin"
)
reconstructed_spectrogram = pca_recomposition.recompose_spectrogram(song, plot_spectrogram=False, saveBinary=True, binaryFileName=binaryFileName)