Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,7 +56,7 @@ def stream(audio, chunk_length_s):
|
|
| 56 |
chunk_end_time = end_pos / sampling_rate
|
| 57 |
|
| 58 |
# Save timestamps for the current chunk
|
| 59 |
-
timestamps.append((chunk_start_time, chunk_end_time))
|
| 60 |
|
| 61 |
chunk = array[start_pos:end_pos]
|
| 62 |
chunk_mp3 = numpy_to_mp3(chunk, sampling_rate=sampling_rate)
|
|
@@ -65,7 +65,7 @@ def stream(audio, chunk_length_s):
|
|
| 65 |
first_time = round(time.time() - start_time, 2)
|
| 66 |
run_time = round(time.time() - start_time, 2)
|
| 67 |
|
| 68 |
-
yield chunk_mp3, first_time, run_time
|
| 69 |
|
| 70 |
# Save timestamps to a CSV file
|
| 71 |
with open("timestamps_30sec.csv", mode="w", newline="") as file:
|
|
@@ -82,14 +82,26 @@ def stream(audio, chunk_length_s):
|
|
| 82 |
with gr.Blocks() as demo:
|
| 83 |
with gr.Row():
|
| 84 |
with gr.Column():
|
| 85 |
-
audio_in = gr.Audio(value="librispeech.wav", sources=["upload"], type="numpy")
|
| 86 |
chunk_length = gr.Slider(minimum=2, maximum=10, value=2, step=2, label="Chunk length (s)")
|
| 87 |
run_button = gr.Button("Stream audio")
|
| 88 |
with gr.Column():
|
| 89 |
-
audio_out = gr.Audio(streaming=True, autoplay=True, format="mp3", label="
|
| 90 |
first_time = gr.Textbox(label="Time to first chunk (s)")
|
| 91 |
run_time = gr.Textbox(label="Time to current chunk (s)")
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
demo.launch()
|
|
|
|
| 56 |
chunk_end_time = end_pos / sampling_rate
|
| 57 |
|
| 58 |
# Save timestamps for the current chunk
|
| 59 |
+
timestamps.append((round(chunk_start_time, 2), round(chunk_end_time, 2)))
|
| 60 |
|
| 61 |
chunk = array[start_pos:end_pos]
|
| 62 |
chunk_mp3 = numpy_to_mp3(chunk, sampling_rate=sampling_rate)
|
|
|
|
| 65 |
first_time = round(time.time() - start_time, 2)
|
| 66 |
run_time = round(time.time() - start_time, 2)
|
| 67 |
|
| 68 |
+
yield chunk_mp3, first_time, run_time, timestamps
|
| 69 |
|
| 70 |
# Save timestamps to a CSV file
|
| 71 |
with open("timestamps_30sec.csv", mode="w", newline="") as file:
|
|
|
|
| 82 |
with gr.Blocks() as demo:
|
| 83 |
with gr.Row():
|
| 84 |
with gr.Column():
|
| 85 |
+
audio_in = gr.Audio(value="librispeech.wav", sources=["upload"], type="numpy", label="Input Audio")
|
| 86 |
chunk_length = gr.Slider(minimum=2, maximum=10, value=2, step=2, label="Chunk length (s)")
|
| 87 |
run_button = gr.Button("Stream audio")
|
| 88 |
with gr.Column():
|
| 89 |
+
audio_out = gr.Audio(streaming=True, autoplay=True, format="mp3", label="Streamed MP3 Audio")
|
| 90 |
first_time = gr.Textbox(label="Time to first chunk (s)")
|
| 91 |
run_time = gr.Textbox(label="Time to current chunk (s)")
|
| 92 |
|
| 93 |
+
with gr.Row():
|
| 94 |
+
timestamps_output = gr.Dataframe(
|
| 95 |
+
headers=["Start Time (s)", "End Time (s)"],
|
| 96 |
+
label="Timestamps for the First 30 Seconds",
|
| 97 |
+
interactive=False
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# Updated function outputs with the timestamps table
|
| 101 |
+
run_button.click(
|
| 102 |
+
fn=stream,
|
| 103 |
+
inputs=[audio_in, chunk_length],
|
| 104 |
+
outputs=[audio_out, first_time, run_time, timestamps_output]
|
| 105 |
+
)
|
| 106 |
|
| 107 |
demo.launch()
|