|
|
|
digital-gut/ |
|
├── app.py |
|
├── requirements.txt |
|
└── README.md |
|
|
|
|
|
import gradio as gr |
|
import numpy as np |
|
import librosa |
|
from transformers import pipeline |
|
|
|
|
|
emotion_analyzer = pipeline("audio-classification", model="MIT/ast-finetuned-speech-commands-v2") |
|
|
|
|
|
speech_recognizer = pipeline("automatic-speech-recognition", |
|
model="kresnik/wav2vec2-large-xlsr-korean") |
|
|
|
def analyze_voice(audio_file): |
|
"""음성 분석 함수""" |
|
try: |
|
|
|
y, sr = librosa.load(audio_file) |
|
|
|
|
|
emotions = emotion_analyzer(y) |
|
primary_emotion = emotions[0] |
|
|
|
|
|
text_result = speech_recognizer(y) |
|
|
|
|
|
mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13) |
|
energy = np.mean(librosa.feature.rms(y=y)) |
|
|
|
return { |
|
"감정": primary_emotion['label'], |
|
"감정_확률": f"{primary_emotion['score']:.2f}", |
|
"음성_텍스트": text_result['text'], |
|
"에너지_레벨": f"{energy:.2f}", |
|
"상태": "분석 완료" |
|
} |
|
except Exception as e: |
|
return { |
|
"error": str(e), |
|
"상태": "오류 발생" |
|
} |
|
|
|
|
|
interface = gr.Interface( |
|
fn=analyze_voice, |
|
inputs=gr.Audio(source="microphone", type="filepath", label="음성 입력"), |
|
outputs=gr.JSON(label="분석 결과"), |
|
title="디지털 굿판 - 음성 감정 분석", |
|
description="음성을 통한 감정 분석과 텍스트 변환을 수행합니다.", |
|
theme=gr.themes.Soft(), |
|
analytics_enabled=True |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch() |