haepada commited on
Commit
312ddbf
·
verified ·
1 Parent(s): 188b936

Update app.py

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