rein0421 commited on
Commit
611943f
·
verified ·
1 Parent(s): 9d18ad4

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -4,14 +4,11 @@ from pydub import AudioSegment # 変換用にpydubをインポート
4
  import os
5
  import shutil
6
  from process import AudioProcessor
7
- from transcription import TranscriptionMaker
8
 
9
  process=AudioProcessor()
10
- transcription = TranscriptionMaker()
11
  app = Flask(__name__)
12
 
13
  users = []
14
- segments_dir = ""
15
 
16
  # トップページ(テンプレート: index.html)
17
  @app.route('/')
@@ -24,6 +21,7 @@ def index():
24
  def feedback():
25
  return render_template('feedback.html')
26
 
 
27
  # 会話詳細画面(テンプレート: talkDetail.html)
28
  @app.route('/talk_detail', methods=['GET', 'POST'])
29
  def talk_detail():
@@ -38,17 +36,11 @@ def userregister():
38
  def confirm():
39
  return jsonify({'members': users}), 200
40
 
41
- # 書き起こし作成エンドポイント
42
- @app.route('/transcription',methods =['GET','POST'])
43
- def transcription():
44
- global segments_dir
45
- text = transcription.create_transcription(segments_dir)
46
- return jsonify({'transcription': text}),200
47
 
48
  # 音声アップロード&解析エンドポイント
49
  @app.route('/upload_audio', methods=['POST'])
50
  def upload_audio():
51
- global segments_dir
52
  try:
53
  data = request.get_json()
54
  # name か users のいずれかが必須。どちらも無い場合はエラー
@@ -58,8 +50,6 @@ def upload_audio():
58
  # Base64デコードして音声バイナリを取得
59
  audio_binary = base64.b64decode(data['audio_data'])
60
 
61
-
62
-
63
  upload_name = 'tmp'
64
  audio_dir = "/tmp/data"
65
  os.makedirs(audio_dir, exist_ok=True)
@@ -79,13 +69,16 @@ def upload_audio():
79
  # 複数人の場合は参照パスのリストを、1人の場合は単一のパスを渡す
80
  if len(users) > 1:
81
  print("複数人の場合の処理")
82
- matched_time, unmatched_time,segments_dir = process.process_multi_audio(reference_paths, audio_path, threshold=0.05)
 
 
 
 
83
  else:
84
- matched_time, unmatched_time, segments_dir = process.process_audio(reference_paths[0], audio_path, threshold=0.05)
85
-
86
- total_time = matched_time + unmatched_time
87
- rate = (matched_time / total_time) * 100 if total_time > 0 else 0
88
- return jsonify({"rate": rate}), 200
89
  except Exception as e:
90
  print("Error in /upload_audio:", str(e))
91
  return jsonify({"error": "サーバーエラー", "details": str(e)}), 500
 
4
  import os
5
  import shutil
6
  from process import AudioProcessor
 
7
 
8
  process=AudioProcessor()
 
9
  app = Flask(__name__)
10
 
11
  users = []
 
12
 
13
  # トップページ(テンプレート: index.html)
14
  @app.route('/')
 
21
  def feedback():
22
  return render_template('feedback.html')
23
 
24
+
25
  # 会話詳細画面(テンプレート: talkDetail.html)
26
  @app.route('/talk_detail', methods=['GET', 'POST'])
27
  def talk_detail():
 
36
  def confirm():
37
  return jsonify({'members': users}), 200
38
 
39
+
 
 
 
 
 
40
 
41
  # 音声アップロード&解析エンドポイント
42
  @app.route('/upload_audio', methods=['POST'])
43
  def upload_audio():
 
44
  try:
45
  data = request.get_json()
46
  # name か users のいずれかが必須。どちらも無い場合はエラー
 
50
  # Base64デコードして音声バイナリを取得
51
  audio_binary = base64.b64decode(data['audio_data'])
52
 
 
 
53
  upload_name = 'tmp'
54
  audio_dir = "/tmp/data"
55
  os.makedirs(audio_dir, exist_ok=True)
 
69
  # 複数人の場合は参照パスのリストを、1人の場合は単一のパスを渡す
70
  if len(users) > 1:
71
  print("複数人の場合の処理")
72
+ matched_times = process.process_multi_audio(reference_paths, audio_path, threshold=0.05)
73
+ # 各メンバーのrateを計算
74
+ total_time = sum(matched_times)
75
+ rates = [(time / total_time) * 100 if total_time > 0 else 0 for time in matched_times]
76
+ return jsonify({"rates": rates}), 200
77
  else:
78
+ matched_time, unmatched_time = process.process_audio(reference_paths[0], audio_path, threshold=0.05)
79
+ total_time = matched_time + unmatched_time
80
+ rate = (matched_time / total_time) * 100 if total_time > 0 else 0
81
+ return jsonify({"rate": rate}), 200
 
82
  except Exception as e:
83
  print("Error in /upload_audio:", str(e))
84
  return jsonify({"error": "サーバーエラー", "details": str(e)}), 500