File size: 1,958 Bytes
bb63470 |
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 |
# 파일 구조
digital-gut/
├── app.py # 메인 Gradio 앱
├── requirements.txt # 필요한 패키지
└── README.md # 설명 문서
# app.py
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)
# 1. 음성 감정 분석
emotions = emotion_analyzer(y)
primary_emotion = emotions[0]
# 2. 음성 텍스트 변환
text_result = speech_recognizer(y)
# 3. 기본 오디오 특성 추출
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),
"상태": "오류 발생"
}
# Gradio 인터페이스 생성
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() |