Spaces:
Runtime error
Runtime error
Implement function to combine segments
Browse files
app.py
CHANGED
@@ -35,10 +35,31 @@ def diarization(audio_file: tuple[int, np.array]) -> np.array:
|
|
35 |
|
36 |
return np.array(list(diarization.itertracks(yield_label=True)))
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
|
40 |
demo = gr.Interface(
|
41 |
-
fn=
|
42 |
inputs=gr.Audio(type="numpy"),
|
43 |
outputs="text",
|
44 |
)
|
|
|
35 |
|
36 |
return np.array(list(diarization.itertracks(yield_label=True)))
|
37 |
|
38 |
+
def combine_segments(segments: np.array) -> np.array:
|
39 |
+
new_arr = []
|
40 |
+
prev_label = None
|
41 |
+
for row in segments:
|
42 |
+
if prev_label is None or row[2] != prev_label:
|
43 |
+
new_arr.append(row)
|
44 |
+
prev_label = row[2]
|
45 |
+
else:
|
46 |
+
new_arr[-1][0] = new_arr[-1][0] | row[0]
|
47 |
+
new_arr[-1][1] = new_arr[-1][1]
|
48 |
+
new_arr[-1][2] = prev_label
|
49 |
+
return np.array(new_arr)
|
50 |
+
|
51 |
+
def split_audio(audio_file: tuple[int, np.array], segments):
|
52 |
+
pass
|
53 |
+
|
54 |
+
|
55 |
+
def transcribe(audio_file: tuple[int, np.array]) -> str:
|
56 |
+
segments = diarization(audio_file)
|
57 |
+
segments = combine_segments(segments)
|
58 |
+
return segments
|
59 |
|
60 |
|
61 |
demo = gr.Interface(
|
62 |
+
fn=transcribe,
|
63 |
inputs=gr.Audio(type="numpy"),
|
64 |
outputs="text",
|
65 |
)
|