| 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] |
| } |
| |
| |
| top_3_results = [] |
| for i, compare_helper in enumerate(result[:3]): |
| score = compare_helper.data[0] |
| test_label = compare_helper.data[1] |
| library_label = compare_helper.data[2] |
| |
| |
| 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' |
| } |