Spaces:
Running
Running
Update process.py
Browse files- __pycache__/process.cpython-310.pyc +0 -0
- __pycache__/transcription.cpython-310.pyc +0 -0
- app.py +2 -2
- process.py +27 -9
- transcription.py +1 -48
__pycache__/process.cpython-310.pyc
CHANGED
Binary files a/__pycache__/process.cpython-310.pyc and b/__pycache__/process.cpython-310.pyc differ
|
|
__pycache__/transcription.cpython-310.pyc
CHANGED
Binary files a/__pycache__/transcription.cpython-310.pyc and b/__pycache__/transcription.cpython-310.pyc differ
|
|
app.py
CHANGED
@@ -325,8 +325,8 @@ def upload_audio():
|
|
325 |
# 複数人の場合は参照パスのリストを、1人の場合は単一のパスを渡す
|
326 |
if len(users) > 1:
|
327 |
print("複数人の場合の処理")
|
328 |
-
matched_times,
|
329 |
-
total_audio = transcripter.
|
330 |
# 各メンバーのrateを計算
|
331 |
total_time = sum(matched_times)
|
332 |
rates = [(time / total_time) * 100 if total_time > 0 else 0 for time in matched_times]
|
|
|
325 |
# 複数人の場合は参照パスのリストを、1人の場合は単一のパスを渡す
|
326 |
if len(users) > 1:
|
327 |
print("複数人の場合の処理")
|
328 |
+
matched_times, merged_segments = process.process_multi_audio(reference_paths, audio_path, users, threshold=0.05)
|
329 |
+
total_audio = transcripter.save_marged_segments(merged_segments)
|
330 |
# 各メンバーのrateを計算
|
331 |
total_time = sum(matched_times)
|
332 |
rates = [(time / total_time) * 100 if total_time > 0 else 0 for time in matched_times]
|
process.py
CHANGED
@@ -245,21 +245,17 @@ class AudioProcessor():
|
|
245 |
print(f"類似度計算でエラーが発生しました: {e}")
|
246 |
return None
|
247 |
|
248 |
-
def process_audio(self, reference_path, input_path, user,output_folder='/tmp/data/matched_segments', seg_duration=1.0, threshold=0.5):
|
249 |
"""
|
250 |
入力音声からリファレンス音声に類似したセグメントを抽出する
|
251 |
|
252 |
Parameters:
|
253 |
-
isSpeaking(bool): 現在のセグメントがリファレンス音声と類似しているか
|
254 |
-
wasSpeaking(bool): 1つ前のセグメントがリファレンス音声と類似しているか
|
255 |
-
current_segment(list): 一致している、または一致しない話者のセグメントのストック
|
256 |
-
merged_segments(list): 要素は(一致するか(bool), セグメントのリスト)。書き起こしに利用。
|
257 |
reference_path (str): リファレンス音声のパス
|
258 |
input_path (str): 入力音声のパス
|
|
|
259 |
output_folder (str): 類似セグメントを保存するディレクトリ
|
260 |
seg_duration (float): セグメントの長さ(秒)
|
261 |
threshold (float): 類似度の閾値
|
262 |
-
user(str): ユーザー名
|
263 |
|
264 |
Returns:
|
265 |
tuple: (マッチした時間(ミリ秒), マッチしなかった時間(ミリ秒), 分類済みのセグメント)
|
@@ -338,19 +334,20 @@ class AudioProcessor():
|
|
338 |
print(f"音声処理でエラーが発生しました: {e}")
|
339 |
return 0, 0, merged_segments
|
340 |
|
341 |
-
def process_multi_audio(self, reference_pathes, input_path, output_folder='/tmp/data/matched_multi_segments', seg_duration=1.0, threshold=0.5):
|
342 |
"""
|
343 |
入力音声から複数のリファレンス音声に類似したセグメントを抽出する
|
344 |
|
345 |
Parameters:
|
346 |
reference_pathes (list): リファレンス音声のパスのリスト
|
347 |
input_path (str): 入力音声のパス
|
|
|
348 |
output_folder (str): 類似セグメントを保存するディレクトリ
|
349 |
seg_duration (float): セグメントの長さ(秒)
|
350 |
threshold (float): 類似度の閾値
|
351 |
|
352 |
Returns:
|
353 |
-
tuple: (各リファレンスごとのマッチした時間のリスト,
|
354 |
"""
|
355 |
try:
|
356 |
# 出力先ディレクトリの中身をクリアする
|
@@ -430,13 +427,34 @@ class AudioProcessor():
|
|
430 |
|
431 |
# 各セグメントについて、最も高い類似度のリファレンスを選択
|
432 |
best_matches = []
|
|
|
433 |
for seg_sim in similarity_transposed:
|
434 |
best_ref = np.argmax(seg_sim) # 最も類似度の高いリファレンスのインデックス
|
435 |
# 閾値チェック
|
436 |
if seg_sim[best_ref] < threshold:
|
437 |
best_matches.append(None) # 閾値未満の場合はマッチなしとする
|
|
|
438 |
else:
|
439 |
best_matches.append(best_ref)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
440 |
|
441 |
# 各リファレンスごとに一致時間を集計
|
442 |
matched_time = [0] * len(reference_pathes)
|
@@ -444,7 +462,7 @@ class AudioProcessor():
|
|
444 |
if match is not None:
|
445 |
matched_time[match] += seg_duration
|
446 |
|
447 |
-
return matched_time,
|
448 |
|
449 |
except Exception as e:
|
450 |
print(f"マルチ音声処理でエラーが発生しました: {e}")
|
|
|
245 |
print(f"類似度計算でエラーが発生しました: {e}")
|
246 |
return None
|
247 |
|
248 |
+
def process_audio(self, reference_path, input_path, user, output_folder='/tmp/data/matched_segments', seg_duration=1.0, threshold=0.5):
|
249 |
"""
|
250 |
入力音声からリファレンス音声に類似したセグメントを抽出する
|
251 |
|
252 |
Parameters:
|
|
|
|
|
|
|
|
|
253 |
reference_path (str): リファレンス音声のパス
|
254 |
input_path (str): 入力音声のパス
|
255 |
+
user(str): ユーザー名
|
256 |
output_folder (str): 類似セグメントを保存するディレクトリ
|
257 |
seg_duration (float): セグメントの長さ(秒)
|
258 |
threshold (float): 類似度の閾値
|
|
|
259 |
|
260 |
Returns:
|
261 |
tuple: (マッチした時間(ミリ秒), マッチしなかった時間(ミリ秒), 分類済みのセグメント)
|
|
|
334 |
print(f"音声処理でエラーが発生しました: {e}")
|
335 |
return 0, 0, merged_segments
|
336 |
|
337 |
+
def process_multi_audio(self, reference_pathes, input_path, users, output_folder='/tmp/data/matched_multi_segments', seg_duration=1.0, threshold=0.5):
|
338 |
"""
|
339 |
入力音声から複数のリファレンス音声に類似したセグメントを抽出する
|
340 |
|
341 |
Parameters:
|
342 |
reference_pathes (list): リファレンス音声のパスのリスト
|
343 |
input_path (str): 入力音声のパス
|
344 |
+
users(list): ユーザーのリスト
|
345 |
output_folder (str): 類似セグメントを保存するディレクトリ
|
346 |
seg_duration (float): セグメントの長さ(秒)
|
347 |
threshold (float): 類似度の閾値
|
348 |
|
349 |
Returns:
|
350 |
+
tuple: (各リファレンスごとのマッチした時間のリスト, 分類済みのセグメント)
|
351 |
"""
|
352 |
try:
|
353 |
# 出力先ディレクトリの中身をクリアする
|
|
|
427 |
|
428 |
# 各セグメントについて、最も高い類似度のリファレンスを選択
|
429 |
best_matches = []
|
430 |
+
speakers = []
|
431 |
for seg_sim in similarity_transposed:
|
432 |
best_ref = np.argmax(seg_sim) # 最も類似度の高いリファレンスのインデックス
|
433 |
# 閾値チェック
|
434 |
if seg_sim[best_ref] < threshold:
|
435 |
best_matches.append(None) # 閾値未満の場合はマッチなしとする
|
436 |
+
speakers.append(-1) # Noneは都合が悪いので-1
|
437 |
else:
|
438 |
best_matches.append(best_ref)
|
439 |
+
speakers.append(best_ref)
|
440 |
+
|
441 |
+
current_speaker = None
|
442 |
+
current_segments = []
|
443 |
+
merged_segments = []
|
444 |
+
for index,file in enumerate(segment_files,start=0):
|
445 |
+
file_path = os.path.join(segmented_path, file)
|
446 |
+
speaker = users[speakers[index]]
|
447 |
+
if speaker == -1:
|
448 |
+
continue
|
449 |
+
if current_speaker != speaker:
|
450 |
+
if current_segments:
|
451 |
+
merged_segments.append((current_speaker,current_segments))
|
452 |
+
current_speaker = speaker
|
453 |
+
current_segments = [file_path]
|
454 |
+
else:
|
455 |
+
current_segments.append(file_path)
|
456 |
+
if current_segments:
|
457 |
+
merged_segments.append((current_speaker,current_segments))
|
458 |
|
459 |
# 各リファレンスごとに一致時間を集計
|
460 |
matched_time = [0] * len(reference_pathes)
|
|
|
462 |
if match is not None:
|
463 |
matched_time[match] += seg_duration
|
464 |
|
465 |
+
return matched_time, merged_segments
|
466 |
|
467 |
except Exception as e:
|
468 |
print(f"マルチ音声処理でエラーが発生しました: {e}")
|
transcription.py
CHANGED
@@ -68,6 +68,7 @@ class TranscriptionMaker():
|
|
68 |
raise
|
69 |
return output_file
|
70 |
|
|
|
71 |
def combine_audio(self,audio_files):
|
72 |
if not audio_files:
|
73 |
raise
|
@@ -91,7 +92,6 @@ class TranscriptionMaker():
|
|
91 |
|
92 |
return merged_segments
|
93 |
|
94 |
-
|
95 |
# ディレクトリ内の音声ファイルを並べ替える
|
96 |
def sort_audio_files_in_directory(self, directory):
|
97 |
files = os.listdir(directory)
|
@@ -99,50 +99,6 @@ class TranscriptionMaker():
|
|
99 |
|
100 |
audio_files.sort(key=lambda x: datetime.strptime(x.split("_")[1].split(".")[0], "%Y%m%d%H%M%S"))
|
101 |
return [os.path.join(directory, f) for f in audio_files]
|
102 |
-
|
103 |
-
#ファイル名が連続しているならくっつける
|
104 |
-
'''
|
105 |
-
def merge_segments(self,segments_dir,output_dir = "/tmp/data/merged_segment"):
|
106 |
-
if not os.path.exists(output_dir):
|
107 |
-
os.makedirs(output_dir, exist_ok=True)
|
108 |
-
|
109 |
-
files = sorted([f for f in os.listdir(segments_dir) if f.endswith('.wav')])
|
110 |
-
|
111 |
-
merged_files = []
|
112 |
-
current_group = []
|
113 |
-
previous_index = None
|
114 |
-
|
115 |
-
for file in files:
|
116 |
-
# ファイル名から番号を抽出(例: "0.wav" -> 0)
|
117 |
-
file_index = int(file.split('.')[0])
|
118 |
-
|
119 |
-
# 番号が連続していない場合、新しいグループを作成
|
120 |
-
if previous_index is not None and file_index != previous_index + 1:
|
121 |
-
# 現在のグループを結合して保存
|
122 |
-
if current_group:
|
123 |
-
merged_files.append(current_group)
|
124 |
-
current_group = []
|
125 |
-
|
126 |
-
# 現在のファイルをグループに追加
|
127 |
-
current_group.append(file)
|
128 |
-
previous_index = file_index
|
129 |
-
|
130 |
-
# 最後のグループを追加
|
131 |
-
if current_group:
|
132 |
-
merged_files.append(current_group)
|
133 |
-
|
134 |
-
# グループごとに結合して保存
|
135 |
-
for i, group in enumerate(merged_files):
|
136 |
-
combined_audio = AudioSegment.empty()
|
137 |
-
for file in group:
|
138 |
-
file_path = os.path.join(segments_dir, file)
|
139 |
-
segment = AudioSegment.from_file(file_path)
|
140 |
-
combined_audio += segment
|
141 |
-
# 出力ファイル名を設定して保存
|
142 |
-
output_file = os.path.join(output_dir, self.generate_filename(3))
|
143 |
-
combined_audio.export(output_file, format='wav')
|
144 |
-
|
145 |
-
return output_dir'''
|
146 |
|
147 |
def save_marged_segments(self,merged_segments,output_directory='/tmp/data/conversations'):
|
148 |
if not merged_segments:
|
@@ -165,7 +121,6 @@ class TranscriptionMaker():
|
|
165 |
|
166 |
return output_directory
|
167 |
|
168 |
-
|
169 |
def merge_segments(self,segments):
|
170 |
combined = AudioSegment.empty() # 空のAudioSegmentを初期化
|
171 |
|
@@ -181,8 +136,6 @@ class TranscriptionMaker():
|
|
181 |
|
182 |
combined += audio
|
183 |
return combined
|
184 |
-
|
185 |
-
|
186 |
|
187 |
def generate_random_string(self,length):
|
188 |
letters = string.ascii_letters + string.digits
|
|
|
68 |
raise
|
69 |
return output_file
|
70 |
|
71 |
+
# 受け取った音声ファイルを話者ごとに整理する
|
72 |
def combine_audio(self,audio_files):
|
73 |
if not audio_files:
|
74 |
raise
|
|
|
92 |
|
93 |
return merged_segments
|
94 |
|
|
|
95 |
# ディレクトリ内の音声ファイルを並べ替える
|
96 |
def sort_audio_files_in_directory(self, directory):
|
97 |
files = os.listdir(directory)
|
|
|
99 |
|
100 |
audio_files.sort(key=lambda x: datetime.strptime(x.split("_")[1].split(".")[0], "%Y%m%d%H%M%S"))
|
101 |
return [os.path.join(directory, f) for f in audio_files]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
def save_marged_segments(self,merged_segments,output_directory='/tmp/data/conversations'):
|
104 |
if not merged_segments:
|
|
|
121 |
|
122 |
return output_directory
|
123 |
|
|
|
124 |
def merge_segments(self,segments):
|
125 |
combined = AudioSegment.empty() # 空のAudioSegmentを初期化
|
126 |
|
|
|
136 |
|
137 |
combined += audio
|
138 |
return combined
|
|
|
|
|
139 |
|
140 |
def generate_random_string(self,length):
|
141 |
letters = string.ascii_letters + string.digits
|