forked from esuyoonn/2026_Spring_DSL_Modeling_CV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
23 lines (19 loc) · 775 Bytes
/
utils.py
File metadata and controls
23 lines (19 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# utils.py
import numpy as np
# Function for computing mean and std for calibration
def personal_baseline(f0, rms, frame_times, speech_mask, T_cal):
cal_mask = (frame_times <= T_cal) & speech_mask
# pitch baseline (voiced only)
voiced_cal = cal_mask & (~np.isnan(f0))
if np.sum(voiced_cal) >= 8:
mu_f0 = float(np.mean(f0[voiced_cal]))
sd_f0 = float(np.std(f0[voiced_cal]) + 1e-8)
else:
mu_f0, sd_f0 = float(np.nanmean(f0)), float(np.nanstd(f0) + 1e-8)
# energy baseline (speech only)
if np.sum(cal_mask) >= 8:
mu_e = float(np.mean(rms[cal_mask]))
sd_e = float(np.std(rms[cal_mask]) + 1e-8)
else:
mu_e, sd_e = float(np.mean(rms)), float(np.std(rms) + 1e-8)
return mu_f0, sd_f0, mu_e, sd_e