File size: 2,046 Bytes
72de3c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import torchaudio
from transformers import pipeline
import numpy as np

# Load model for speech emotion recognition
emotion_pipeline = pipeline("audio-classification", model="superb/hubert-large-superb-er")

# Voice Analysis Logic
def analyze_voice(audio):
    if audio is None:
        return "Please record or upload your voice."

    # Get emotion
    results = emotion_pipeline(audio["array"])
    top = max(results, key=lambda x: x["score"])
    emotion = top["label"].capitalize()
    confidence = round(top["score"] * 100, 2)

    # Personality interpretation (rule-based)
    personality_map = {
        "Happy": "You sound energetic, warm, and approachable. Possibly a social butterfly or a natural leader.",
        "Sad": "You're deep and thoughtful. Often empathetic and emotionally intelligent.",
        "Angry": "You radiate power and confidence. A strong-willed individual who’s not afraid to speak out.",
        "Neutral": "Balanced and calm. Likely introspective and logical in decision-making.",
        "Fearful": "You might be cautious, observant, and sensitive to surroundings.",
        "Disgust": "Sharp-witted with a strong sense of right and wrong.",
        "Surprise": "Curious and spontaneous. You embrace the unexpected with open arms."
    }

    persona = personality_map.get(emotion, "A unique voice with a unique mind. Hard to label, easy to admire.")

    return f"""

## πŸŽ™οΈ Voice2Persona-AI Report

**Detected Emotion**: {emotion}  

**Confidence**: {confidence}%  

**Inferred Personality Vibe**:  

{persona}

    """

# Gradio UI
demo = gr.Interface(
    fn=analyze_voice,
    inputs=gr.Audio(source="microphone", type="numpy", label="🎀 Record or Upload Your Voice"),
    outputs=gr.Markdown(),
    title="πŸ”Š Voice2Persona-AI",
    description="Speak for 5–10 seconds and get a fun AI-generated personality profile based on your tone & emotion.",
    theme="soft",
    live=True
)

if __name__ == "__main__":
    demo.launch()