Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
1873d1e
1
Parent(s):
af69235
音声ファイル処理の結果をユーザー指定の形式に合わせてJSON形式で返却するように変更。セグメント内の単語情報を含める処理を追加。
Browse files
app.py
CHANGED
@@ -297,23 +297,46 @@ def process_audio_file(audio_filepath: str) -> dict: # Gradioから渡される
|
|
297 |
# transcribe_audio_core内でエラー通知はされているはず
|
298 |
return {"error": "Transcription failed. Check logs and messages for details."}
|
299 |
|
300 |
-
# 結果をJSON形式で返却
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
|
318 |
return result
|
319 |
|
|
|
297 |
# transcribe_audio_core内でエラー通知はされているはず
|
298 |
return {"error": "Transcription failed. Check logs and messages for details."}
|
299 |
|
300 |
+
# 結果をJSON形式で返却 (ユーザー指定の形式に合わせる)
|
301 |
+
output_segments = []
|
302 |
+
word_idx = 0
|
303 |
+
for seg_data in vis_data:
|
304 |
+
s_start_time = float(seg_data[0])
|
305 |
+
s_end_time = float(seg_data[1])
|
306 |
+
s_text = seg_data[2]
|
307 |
+
segment_words_list: List[dict] = []
|
308 |
+
|
309 |
+
if word_vis_data: # word_vis_data が存在する場合のみ処理
|
310 |
+
temp_current_word_idx = word_idx
|
311 |
+
while temp_current_word_idx < len(word_vis_data):
|
312 |
+
w_data = word_vis_data[temp_current_word_idx]
|
313 |
+
w_start_time = float(w_data[0])
|
314 |
+
w_end_time = float(w_data[1])
|
315 |
+
|
316 |
+
# 単語がセグメントの範囲内にあるかチェック (多少の誤差を許容)
|
317 |
+
if w_start_time >= s_start_time and w_end_time <= s_end_time + 0.1:
|
318 |
+
segment_words_list.append({
|
319 |
+
"start": w_start_time,
|
320 |
+
"end": w_end_time,
|
321 |
+
"word": w_data[2]
|
322 |
+
})
|
323 |
+
temp_current_word_idx += 1
|
324 |
+
elif w_start_time < s_start_time: # 単語がセグメントより前に開始している場合はスキップ
|
325 |
+
temp_current_word_idx += 1
|
326 |
+
elif w_start_time > s_end_time: # 単語がセグメントより後に開始している場合はループを抜ける
|
327 |
+
break
|
328 |
+
else: # その他のケース (ほぼありえないが念のため)
|
329 |
+
temp_current_word_idx += 1
|
330 |
+
word_idx = temp_current_word_idx
|
331 |
+
|
332 |
+
output_segments.append({
|
333 |
+
"start": s_start_time,
|
334 |
+
"end": s_end_time,
|
335 |
+
"text": s_text,
|
336 |
+
"words": segment_words_list
|
337 |
+
})
|
338 |
+
|
339 |
+
result = {"segments": output_segments}
|
340 |
|
341 |
return result
|
342 |
|