File size: 2,301 Bytes
822dda9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from .model_manager import ModelManager
from .audio_processor import AudioProcessor
from typing import Dict

class Analyzer:
    def __init__(self, model_manager: ModelManager, audio_processor: AudioProcessor):
        self.model_manager = model_manager
        self.audio_processor = audio_processor
        self.model_manager.load_models()
        
    def analyze(self, audio_path: str) -> Dict:
        # Process audio
        waveform, features = self.audio_processor.process_audio(audio_path)
        
        # Get transcription
        transcription = self.model_manager.transcribe(waveform)
        
        # Analyze emotions
        emotions = self.model_manager.analyze_emotions(transcription)
        
        # Analyze mental health indicators
        mental_health = self.model_manager.analyze_mental_health(transcription)
        
        # Combine analysis with audio features
        mental_health = self._combine_analysis(mental_health, features)
        
        return {
            'transcription': transcription,
            'emotions': {
                'scores': emotions,
                'dominant_emotion': max(emotions.items(), key=lambda x: x[1])[0]
            },
            'mental_health_indicators': mental_health,
            'audio_features': features
        }
        
    def _combine_analysis(self, mental_health: Dict, features: Dict) -> Dict:
        """Combine mental health analysis with audio features"""
        # Adjust risk scores based on audio features
        energy_level = features['energy']['mean']
        pitch_variability = features['pitch']['std']
        
        # Simple risk score adjustment based on audio features
        mental_health['depression_risk'] = (
            mental_health['depression_risk'] * 0.7 +
            (1 - energy_level) * 0.3  # Lower energy may indicate depression
        )
        
        mental_health['anxiety_risk'] = (
            mental_health['anxiety_risk'] * 0.7 +
            pitch_variability * 0.3  # Higher pitch variability may indicate anxiety
        )
        
        # Add confidence scores
        mental_health['confidence'] = {
            'depression': 0.8,  # Example confidence scores
            'anxiety': 0.8,
            'stress': 0.7
        }
        
        return mental_health