|
import numpy as np |
|
|
|
def calc_ess(pitch_variation, vol_max_db, mean_volume_db, valence_scores): |
|
""" |
|
Emotional Stability Score(ESS) : Measures the consistency of the speaker's emotional tone, reflecting their ability to regulate emotions during speech. |
|
|
|
Requires: |
|
Tonal Steadiness: The lack of extreme fluctuations in emotional tone. |
|
Absence of Sudden Loudness Spikes: Indicates controlled expression without abrupt emotional shifts. |
|
Valence Stability: Consistency in the overall positive or negative tone across the speech. |
|
""" |
|
|
|
tonal_steadiness = max(0, 100 - (pitch_variation * 10)) |
|
|
|
|
|
spike = max(0, vol_max_db - mean_volume_db - 15) |
|
spike_ratio = min(spike / 30, 1.0) |
|
stability = 1 - spike_ratio |
|
loudness_stability = stability * 100 |
|
|
|
|
|
valence_stability = 100 - (np.std(valence_scores) * 20) |
|
|
|
ESS = (0.45 * float(tonal_steadiness)) + (0.35 * float(loudness_stability)) + (0.2 * float(valence_stability)) |
|
|
|
return ESS |
|
|
|
def calc_lcs(volume_std, vol_max_db, mean_volume_db): |
|
""" |
|
Loudness Control Score (LCS): Evaluates how well the speaker manages volume |
|
|
|
Requires: |
|
- Volume Stability: Consistency in speech amplitude. |
|
- Controlled Emphasis: The ability to modulate loudness smoothly for emphasis rather than abrupt changes. |
|
""" |
|
vol_stability = max(0, 100 - (volume_std * 5)) |
|
|
|
|
|
emphasis_spike = max(0, vol_max_db - mean_volume_db - 3) |
|
spike_ratio = min(emphasis_spike / 15, 1.0) |
|
emphasis_control = (1 - spike_ratio) * 100 |
|
|
|
|
|
lcs = 0.55 * vol_stability + 0.45 * emphasis_control |
|
print(f"vol_stability: {vol_stability}, emphasis_control: {emphasis_control}") |
|
return min(100, max(0, lcs)) |
|
|
|
def calc_srs(wpm, filler_count, long_pause_count, pitch_variation): |
|
""" |
|
Speech Rate Stability (SRS): Reflects the consistency of the speaker's pace and rhythm. |
|
|
|
Requires: |
|
- Words per Minute Consistency: Regularity in speech speed. |
|
- Absence of Sudden Speed Shifts: Smooth transitions without erratic tempo changes. |
|
""" |
|
ideal_wpm = 150 |
|
wpm_deviation = min(30, abs(wpm - ideal_wpm)) |
|
wpm_consistency = max(0, 100 - (wpm_deviation * 1.67)) |
|
|
|
|
|
filler_penalty = min(filler_count / 10, 1.0) |
|
pause_penalty = min(long_pause_count / 5, 1.0) |
|
pitch_penalty = min(pitch_variation / 3.0, 1.0) |
|
|
|
|
|
stability = (1 - ((filler_penalty + pause_penalty + pitch_penalty) / 3)) * 100 |
|
|
|
|
|
SRS = (0.45 * wpm_consistency) + (0.55 * stability) |
|
|
|
return min(100, max(0, SRS)) |
|
|
|
def calc_vers(filler_count, long_pause_count, pitch_variation, mean_volume_db, vol_max_db, wpm, volume_std, valence_scores): |
|
ESS = calc_ess(pitch_variation, vol_max_db, mean_volume_db, valence_scores) |
|
LCS = calc_lcs(volume_std, vol_max_db, mean_volume_db) |
|
SRS = calc_srs(wpm, filler_count, long_pause_count, pitch_variation) |
|
|
|
|
|
VERS = (0.5 * ESS) + (0.3 * LCS) + (0.2 * SRS) |
|
|
|
if VERS > 0 and VERS < 50: |
|
insight = """Poor regulation—noticeable swings in tone and uncontrolled |
|
emotional expression. Feedback: Consider exercises and professional |
|
coaching to stabilize your emotional delivery.""" |
|
elif VERS >= 50 and VERS < 80: |
|
insight = """Moderate regulation—occasional fluctuations or abrupt changes. |
|
Feedback: Work on smoothing out volume changes and maintaining a steady tone.""" |
|
elif VERS >= 80 and VERS <= 100: |
|
insight = """Excellent regulation—steady tone and controlled volume dynamics. |
|
Feedback: Continue using techniques that maintain emotional balance.""" |
|
else: |
|
insight = "Invalid score calculated" |
|
|
|
return { |
|
"VERS": int(VERS), |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|