File size: 2,186 Bytes
9e21eef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4af3315
9e21eef
00af04f
 
 
 
9e21eef
00af04f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9e21eef
4af3315
 
 
00af04f
 
 
 
 
4af3315
9e21eef
 
 
00af04f
9e21eef
 
 
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
import os
import sys
from app import process_audio, music_analyzer

def main():
    """
    Example function to demonstrate the application with a sample audio file.
    
    Usage:
    python example.py <path_to_audio_file>
    """
    if len(sys.argv) != 2:
        print("Usage: python example.py <path_to_audio_file>")
        return
    
    audio_file = sys.argv[1]
    if not os.path.exists(audio_file):
        print(f"Error: File {audio_file} does not exist.")
        return
    
    print(f"Processing audio file: {audio_file}")
    
    # Call the main processing function
    genre_results, lyrics, ast_results = process_audio(audio_file)
    
    # Check if we got an error message
    if isinstance(genre_results, str) and genre_results.startswith("Error"):
        print(f"Error processing audio: {genre_results}")
        return
    
    # Get emotion analysis results
    try:
        emotion_results = music_analyzer.analyze_music(audio_file)
        
        # Print results
        print("\n" + "="*50)
        print("GENRE CLASSIFICATION RESULTS:")
        print("="*50)
        print(genre_results)
        
        print("\n" + "="*50)
        print("EMOTION ANALYSIS RESULTS:")
        print("="*50)
        print(f"Tempo: {emotion_results['summary']['tempo']:.1f} BPM")
        print(f"Key: {emotion_results['summary']['key']} {emotion_results['summary']['mode']}")
        print(f"Primary Emotion: {emotion_results['summary']['primary_emotion']}")
        print(f"Primary Theme: {emotion_results['summary']['primary_theme']}")
    except Exception as e:
        print(f"\nError in emotion analysis: {str(e)}")
    
    print("\n" + "="*50)
    print("AUDIO CLASSIFICATION RESULTS (AST):")
    print("="*50)
    if ast_results and isinstance(ast_results, list) and len(ast_results) > 0:
        for result in ast_results[:5]:  # Show top 5 results
            print(f"{result['label']}: {result['score']*100:.2f}%")
    else:
        print("No audio classification results available.")
    
    print("\n" + "="*50)
    print("GENERATED LYRICS:")
    print("="*50)
    print(lyrics if lyrics else "No lyrics generated.")

if __name__ == "__main__":
    main()