File size: 2,303 Bytes
e99e064
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8618140
e99e064
 
 
8618140
e99e064
 
 
 
 
 
8618140
e99e064
8618140
e99e064
 
 
 
 
 
 
 
 
b4eefc1
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
import os
import glob
from compare import get_one_result
from segment_transcription import segment_transcription

def inference(audio_path):
    segment_datas = segment_transcription(audio_path)
    result = get_one_result(segment_datas)
    final_result = result_formatting(result)
    return final_result

def result_formatting(result):
    """
    get_one_result์—์„œ ๋‚˜์˜จ ๊ฒฐ๊ณผ๋ฅผ ํฌ๋งทํŒ…
    result: sorted list of CompareHelper objects
    """
    if not result or len(result) == 0:
        return {
            'matches': [],
            'message': 'No matches found'
        }
    
    # ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ ์ฒดํฌ
    if isinstance(result, list) and len(result) > 0 and isinstance(result[0], str):
        return {
            'matches': [],
            'message': result[0]  # "there is no note for this song"
        }
    
    # ์ƒ์œ„ 3๊ฐœ ๊ฒฐ๊ณผ ์ถ”์ถœ
    top_3_results = []
    for i, compare_helper in enumerate(result[:3]):
        score = compare_helper.data[0]  # similarity score
        test_label = compare_helper.data[1]  # test song info
        library_label = compare_helper.data[2]  # matched song info
        
        # ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ ˆ์ด๋ธ”์—์„œ ์ •๋ณด ์ถ”์ถœ
        song_title = library_label.get('title', 'Unknown Song')
        library_time = library_label.get('time', 0)  # ๋งค์น˜๋œ ๊ตฌ๊ฐ„์˜ ์‹œ๊ฐ„
        library_time2 = library_label.get('time2', 0)
        
        # ํ…Œ์ŠคํŠธ ๋ ˆ์ด๋ธ”์—์„œ ์ •๋ณด ์ถ”์ถœ
        test_time = test_label.get('time', 0) if test_label else 0  # ์ž…๋ ฅ ๊ณก์˜ ์‹œ๊ฐ„
        test_time2 = test_label.get('time2', 0) if test_label else 0
        
        match_info = {
            'rank': i + 1,
            'score': float(score),
            'song_title': song_title,
            'test_time': float(test_time),  # ์ž…๋ ฅ ๊ณก์—์„œ ๋งค์น˜๋œ ์‹œ๊ฐ„
            'test_time2' : float(test_time2),
            'library_time': float(library_time),  # ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ณก์—์„œ ๋งค์น˜๋œ ์‹œ๊ฐ„
            'library_time2': float(library_time2),
            'confidence': f"{score * 100:.1f}%",
            'time_match': f"Input: {test_time:.1f}s โ†” Library: {library_time:.1f}s"
        }
        
        top_3_results.append(match_info)
    
    return {
        'matches': top_3_results,
        'message': 'success'
    }