rein0421 commited on
Commit
f692912
·
verified ·
1 Parent(s): 665f551

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -1,11 +1,6 @@
1
- from flask import Flask, request, jsonify,render_template,Flask, jsonify, request, send_from_directory
2
  import base64
3
-
4
  import os
5
- import shutil
6
-
7
-
8
-
9
 
10
  app = Flask(__name__)
11
 
@@ -25,11 +20,17 @@ def upload_audio():
25
  # Base64デコード
26
  audio_binary = base64.b64decode(audio_data)
27
 
28
- # WAVファイルとして保存
29
- with open('recorded_audio.wav', 'wb') as f:
 
 
 
 
 
 
30
  f.write(audio_binary)
31
 
32
- return jsonify({"message": "音声が正常に保存されました"}), 200
33
  except Exception as e:
34
  return jsonify({"error": str(e)}), 500
35
 
 
1
+ from flask import Flask, request, jsonify, render_template, send_from_directory
2
  import base64
 
3
  import os
 
 
 
 
4
 
5
  app = Flask(__name__)
6
 
 
20
  # Base64デコード
21
  audio_binary = base64.b64decode(audio_data)
22
 
23
+ # 永続化用ディレクトリ "data" がなければ作成
24
+ persist_dir = "data"
25
+ if not os.path.exists(persist_dir):
26
+ os.makedirs(persist_dir)
27
+
28
+ # WAVファイルとして "data" フォルダに保存
29
+ filepath = os.path.join(persist_dir, "recorded_audio.wav")
30
+ with open(filepath, 'wb') as f:
31
  f.write(audio_binary)
32
 
33
+ return jsonify({"message": "音声が正常に保存されました", "filepath": filepath}), 200
34
  except Exception as e:
35
  return jsonify({"error": str(e)}), 500
36