rein0421 commited on
Commit
0bf3050
·
verified ·
1 Parent(s): 7475ce4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -5
app.py CHANGED
@@ -19,17 +19,16 @@ def upload_audio():
19
  if not audio_data:
20
  return jsonify({"error": "音声データが送信されていません"}), 400
21
 
22
- # Base64デコード(例外発生時はエラー内容を返す)
23
  try:
24
  audio_binary = base64.b64decode(audio_data)
25
  except Exception as decode_err:
26
  return jsonify({"error": "Base64デコードに失敗しました", "details": str(decode_err)}), 400
27
 
28
- # 書き込み用ディレクトリ "data" の作成(既にあれば何もしない)
29
- persist_dir = "data"
30
  os.makedirs(persist_dir, exist_ok=True)
31
 
32
- # ファイルの保存
33
  filepath = os.path.join(persist_dir, "recorded_audio.wav")
34
  with open(filepath, 'wb') as f:
35
  f.write(audio_binary)
@@ -37,7 +36,6 @@ def upload_audio():
37
  return jsonify({"message": "音声が正常に保存されました", "filepath": filepath}), 200
38
 
39
  except Exception as e:
40
- # サーバー内部エラーの場合、詳細をログに出力
41
  app.logger.error("エラー: %s", str(e))
42
  return jsonify({"error": "サーバー内部エラー", "details": str(e)}), 500
43
 
 
19
  if not audio_data:
20
  return jsonify({"error": "音声データが送信されていません"}), 400
21
 
22
+ # Base64デコード
23
  try:
24
  audio_binary = base64.b64decode(audio_data)
25
  except Exception as decode_err:
26
  return jsonify({"error": "Base64デコードに失敗しました", "details": str(decode_err)}), 400
27
 
28
+ # 書き込み用ディレクトリとして /tmp/data を使用(/tmp は書き込み可能)
29
+ persist_dir = "/tmp/data"
30
  os.makedirs(persist_dir, exist_ok=True)
31
 
 
32
  filepath = os.path.join(persist_dir, "recorded_audio.wav")
33
  with open(filepath, 'wb') as f:
34
  f.write(audio_binary)
 
36
  return jsonify({"message": "音声が正常に保存されました", "filepath": filepath}), 200
37
 
38
  except Exception as e:
 
39
  app.logger.error("エラー: %s", str(e))
40
  return jsonify({"error": "サーバー内部エラー", "details": str(e)}), 500
41