Update app.py
Browse files
app.py
CHANGED
@@ -155,49 +155,50 @@ def create_interface():
|
|
155 |
"""음성 입력 초기화"""
|
156 |
return None
|
157 |
|
|
|
158 |
def analyze_voice(audio_path, state):
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
|
202 |
def map_acoustic_to_emotion(features):
|
203 |
"""음향학적 특성을 감정으로 매핑"""
|
|
|
155 |
"""음성 입력 초기화"""
|
156 |
return None
|
157 |
|
158 |
+
# analyze_voice 함수 부분만 수정
|
159 |
def analyze_voice(audio_path, state):
|
160 |
+
"""음성 분석 개선"""
|
161 |
+
if audio_path is None:
|
162 |
+
return state, "음성을 먼저 녹음해주세요.", "", "", ""
|
163 |
+
|
164 |
+
try:
|
165 |
+
# 오디오 로드
|
166 |
+
y, sr = librosa.load(audio_path, sr=16000)
|
167 |
+
|
168 |
+
# 1. 음향학적 특성 분석
|
169 |
+
acoustic_features = {
|
170 |
+
"energy": float(np.mean(librosa.feature.rms(y=y))),
|
171 |
+
"tempo": float(librosa.beat.tempo(y)[0]),
|
172 |
+
"pitch": float(np.mean(librosa.feature.zero_crossing_rate(y))),
|
173 |
+
"volume": float(np.mean(np.abs(y)))
|
174 |
+
}
|
175 |
|
176 |
+
# 음성의 특성에 따른 감정 매핑
|
177 |
+
voice_emotion = map_acoustic_to_emotion(acoustic_features)
|
178 |
+
|
179 |
+
# 2. 음성-텍스트 변환
|
180 |
+
transcription = speech_recognizer(y)
|
181 |
+
text = transcription["text"]
|
182 |
+
|
183 |
+
# 3. 텍스트 감정 분석
|
184 |
+
text_sentiment = korean_sentiment(text)[0]
|
185 |
+
|
186 |
+
# 결과 포맷팅
|
187 |
+
voice_result = f"음성 감정: {voice_emotion['emotion']} (강도: {voice_emotion['intensity']:.2f})"
|
188 |
+
text_result = f"텍스트 감정: {text_sentiment['label']} ({text_sentiment['score']:.2f})"
|
189 |
+
|
190 |
+
# 프롬프트 생성
|
191 |
+
prompt = generate_detailed_prompt(text, voice_emotion, text_sentiment, acoustic_features)
|
192 |
+
|
193 |
+
return (
|
194 |
+
state,
|
195 |
+
text,
|
196 |
+
voice_result,
|
197 |
+
text_result,
|
198 |
+
prompt
|
199 |
+
)
|
200 |
+
except Exception as e:
|
201 |
+
return state, f"오류 발생: {str(e)}", "", "", ""
|
202 |
|
203 |
def map_acoustic_to_emotion(features):
|
204 |
"""음향학적 특성을 감정으로 매핑"""
|