Spaces:
Running
Running
Commit
•
c98669c
1
Parent(s):
a1ea619
bump bitrate
Browse files
app.py
CHANGED
@@ -21,9 +21,9 @@ def numpy_to_mp3(audio_array, sampling_rate):
|
|
21 |
channels=1
|
22 |
)
|
23 |
|
24 |
-
# Export the audio segment to MP3 bytes
|
25 |
mp3_io = io.BytesIO()
|
26 |
-
audio_segment.export(mp3_io, format="mp3")
|
27 |
|
28 |
# Get the MP3 bytes
|
29 |
mp3_bytes = mp3_io.getvalue()
|
@@ -48,7 +48,7 @@ def stream(audio, chunk_length_s):
|
|
48 |
if idx == 0:
|
49 |
first_time = round(time.time() - start_time, 2)
|
50 |
run_time = round(time.time() - start_time, 2)
|
51 |
-
yield
|
52 |
|
53 |
with gr.Blocks() as demo:
|
54 |
with gr.Row():
|
@@ -57,11 +57,10 @@ with gr.Blocks() as demo:
|
|
57 |
chunk_length = gr.Slider(minimum=2, maximum=10, value=2, step=2, label="Chunk length (s)")
|
58 |
run_button = gr.Button("Stream audio")
|
59 |
with gr.Column():
|
60 |
-
audio_out = gr.Audio(streaming=True, autoplay=True, label="
|
61 |
-
audio_out_mp3 = gr.Audio(streaming=True, autoplay=True, format="mp3", label="mp3")
|
62 |
first_time = gr.Textbox(label="Time to first chunk (s)")
|
63 |
run_time = gr.Textbox(label="Time to current chunk (s)")
|
64 |
|
65 |
-
run_button.click(fn=stream, inputs=[audio_in, chunk_length], outputs=[audio_out,
|
66 |
|
67 |
demo.launch()
|
|
|
21 |
channels=1
|
22 |
)
|
23 |
|
24 |
+
# Export the audio segment to MP3 bytes - use a high bitrate to maximise quality
|
25 |
mp3_io = io.BytesIO()
|
26 |
+
audio_segment.export(mp3_io, format="mp3", bitrate="320k")
|
27 |
|
28 |
# Get the MP3 bytes
|
29 |
mp3_bytes = mp3_io.getvalue()
|
|
|
48 |
if idx == 0:
|
49 |
first_time = round(time.time() - start_time, 2)
|
50 |
run_time = round(time.time() - start_time, 2)
|
51 |
+
yield chunk_mp3, first_time, run_time
|
52 |
|
53 |
with gr.Blocks() as demo:
|
54 |
with gr.Row():
|
|
|
57 |
chunk_length = gr.Slider(minimum=2, maximum=10, value=2, step=2, label="Chunk length (s)")
|
58 |
run_button = gr.Button("Stream audio")
|
59 |
with gr.Column():
|
60 |
+
audio_out = gr.Audio(streaming=True, autoplay=True, format="mp3", label="mp3")
|
|
|
61 |
first_time = gr.Textbox(label="Time to first chunk (s)")
|
62 |
run_time = gr.Textbox(label="Time to current chunk (s)")
|
63 |
|
64 |
+
run_button.click(fn=stream, inputs=[audio_in, chunk_length], outputs=[audio_out, first_time, run_time])
|
65 |
|
66 |
demo.launch()
|