Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,7 @@ def cosine_similarity(vec1, vec2):
|
|
23 |
vec2 = vec2 / np.linalg.norm(vec2)
|
24 |
return np.dot(vec1, vec2)
|
25 |
|
26 |
-
def segment_audio(path, target_path='
|
27 |
"""音声を指定秒数ごとに分割する"""
|
28 |
os.makedirs(target_path, exist_ok=True)
|
29 |
base_sound = AudioSegment.from_file(path)
|
@@ -63,6 +63,8 @@ app = Flask(__name__)
|
|
63 |
def index():
|
64 |
return send_from_directory('.', 'index.html')
|
65 |
|
|
|
|
|
66 |
@app.route('/upload_audio', methods=['POST'])
|
67 |
def upload_audio():
|
68 |
try:
|
@@ -76,12 +78,19 @@ def upload_audio():
|
|
76 |
with open(audio_path, 'wb') as f:
|
77 |
f.write(audio_binary)
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
80 |
matched_time, unmatched_time = process_audio(reference_audio, audio_path, threshold=0.1)
|
81 |
-
|
|
|
82 |
|
83 |
return jsonify({"rate": rate}), 200
|
84 |
except Exception as e:
|
|
|
|
|
85 |
return jsonify({"error": "サーバーエラー", "details": str(e)}), 500
|
86 |
|
87 |
if __name__ == '__main__':
|
|
|
23 |
vec2 = vec2 / np.linalg.norm(vec2)
|
24 |
return np.dot(vec1, vec2)
|
25 |
|
26 |
+
def segment_audio(path, target_path='/tmp/setup_voice', seg_duration=1.0):
|
27 |
"""音声を指定秒数ごとに分割する"""
|
28 |
os.makedirs(target_path, exist_ok=True)
|
29 |
base_sound = AudioSegment.from_file(path)
|
|
|
63 |
def index():
|
64 |
return send_from_directory('.', 'index.html')
|
65 |
|
66 |
+
|
67 |
+
|
68 |
@app.route('/upload_audio', methods=['POST'])
|
69 |
def upload_audio():
|
70 |
try:
|
|
|
78 |
with open(audio_path, 'wb') as f:
|
79 |
f.write(audio_binary)
|
80 |
|
81 |
+
# 参照音声ファイルのパスが正しいか確認!
|
82 |
+
reference_audio = '/path/to/sample.wav' # ※sample.wavの絶対パスに変更するか、正しい場所に配置する
|
83 |
+
if not os.path.exists(reference_audio):
|
84 |
+
return jsonify({"error": "参照音声ファイルが見つかりません", "details": reference_audio}), 500
|
85 |
+
|
86 |
matched_time, unmatched_time = process_audio(reference_audio, audio_path, threshold=0.1)
|
87 |
+
total_time = matched_time + unmatched_time
|
88 |
+
rate = (matched_time / total_time) * 100 if total_time > 0 else 0
|
89 |
|
90 |
return jsonify({"rate": rate}), 200
|
91 |
except Exception as e:
|
92 |
+
# ログにエラー内容を出力(デバッグ中のみ有効にすることを推奨)
|
93 |
+
print("Error in /upload_audio:", str(e))
|
94 |
return jsonify({"error": "サーバーエラー", "details": str(e)}), 500
|
95 |
|
96 |
if __name__ == '__main__':
|