File size: 1,527 Bytes
8ad2ab3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aef3b1e
8ad2ab3
 
 
 
 
aef3b1e
8ad2ab3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
import whisper
import numpy as np
from .compute_vers_score import compute_vers_score

def convert_numpy_types(obj):
    """Convert NumPy types to Python native types for JSON serialization."""
    if isinstance(obj, np.integer):
        return int(obj)
    elif isinstance(obj, np.floating):
        return float(obj)
    elif isinstance(obj, np.ndarray):
        return obj.tolist()
    elif isinstance(obj, dict):
        return {k: convert_numpy_types(v) for k, v in obj.items()}
    elif isinstance(obj, list):
        return [convert_numpy_types(i) for i in obj]
    else:
        return obj

def main(file_path: str, model_size: str = "base", filler_count = None) -> dict:
    try:
        # Load whisper model
        whisper_model = whisper.load_model(model_size)
        
        # Compute VERS score
        results = compute_vers_score(file_path, whisper_model, filler_count)
        
        # Convert any NumPy types to native Python types
        results = convert_numpy_types(results)

        # Structure response with rounded values
        # (using Python's built-in round function which returns Python native float)
        response = {
            "VERS Score": round(results['VERS'], 2)
            # "ESS": round(results['ESS'], 2),
            # "LCS": round(results['LCS'], 2),
            # "SRS": round(results['SRS'], 2),
            # "Insight": results['insight'],
        }
        
        return response

    except Exception as e:
        raise RuntimeError(f"Error during analysis: {str(e)}")