File size: 3,398 Bytes
1e3bdcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ed64ea8
 
1e3bdcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
import argparse
import pandas as pd
from tqdm import tqdm
import warnings

# Suppress warnings
warnings.filterwarnings("ignore")

from metrics.srmr_metric import calculate_srmr
from metrics.sigmos_metric import calculate_sigmos
from metrics.vqscore_metric import calculate_vqscore
from metrics.wvmos_metric import calculate_wvmos

METRIC_DESCRIPTIONS = {
    'SRMR': 'Technical measurement of reverberation and room acoustics',
    'SIGMOS_DISC': 'Audio continuity and smoothness',
    'VQScore': 'Overall voice quality assessment',
    'WVMOS': 'Predicted subjective quality rating',
    'SIGMOS_OVRL': 'Comprehensive overall audio quality',
    'SIGMOS_REVERB': 'Perceived reverberation quality'
}

import config
THRESHOLDS = config.THRESHOLDS

def evaluate_file(file_path):
    # Calculate all scores first
    scores = {}
    
    # SRMR
    scores['SRMR'] = calculate_srmr(file_path)
    
    # SIGMOS
    sigmos_scores = calculate_sigmos(file_path)
    if sigmos_scores:
        scores.update(sigmos_scores)
    else:
        scores['SIGMOS_DISC'] = None
        scores['SIGMOS_OVRL'] = None
        scores['SIGMOS_REVERB'] = None
        
    # VQScore
    scores['VQScore'] = calculate_vqscore(file_path)
    
    # WVMOS
    scores['WVMOS'] = calculate_wvmos(file_path)
    
    # Build list of rows for this file
    rows = []
    filename = os.path.basename(file_path)
    
    for metric, threshold in THRESHOLDS.items():
        score = scores.get(metric)
        
        if score is None:
            status = 'ERROR'
        elif score >= threshold:
            status = 'PASS'
        else:
            status = 'FAIL'
            
        row = {
            'Filename': filename,
            'Metric': metric,
            'Description': METRIC_DESCRIPTIONS.get(metric, ''),
            'Threshold': threshold,
            'Score': score,
            'PASS OR FAIL': status
        }
        rows.append(row)
        
    return rows

def main():
    parser = argparse.ArgumentParser(description='TTS Audio Quality Evaluation')
    parser.add_argument('input_path', help='Path to audio file or directory')
    parser.add_argument('--output', default='evaluation_report.csv', help='Output CSV file')
    args = parser.parse_args()
    
    input_path = args.input_path
    files = []
    
    if os.path.isdir(input_path):
        for root, dirs, filenames in os.walk(input_path):
            for filename in filenames:
                if filename.lower().endswith(('.wav', '.mp3', '.flac')):
                    files.append(os.path.join(root, filename))
    elif os.path.isfile(input_path):
        files.append(input_path)
    else:
        print(f"Invalid path: {input_path}")
        return
    
    print(f"Found {len(files)} files to evaluate.")
    
    all_rows = []
    for file_path in tqdm(files):
        try:
            file_rows = evaluate_file(file_path)
            all_rows.extend(file_rows)
        except Exception as e:
            import traceback
            traceback.print_exc()
            print(f"Failed to process {file_path}: {e}")
            
    df = pd.DataFrame(all_rows)
    
    # Ensure column order
    cols = ['Filename', 'Metric', 'Description', 'Threshold', 'Score', 'PASS OR FAIL']
    df = df[cols]
    
    df.to_csv(args.output, index=False)
    print(f"Report saved to {args.output}")

if __name__ == '__main__':
    main()