freddyaboulton HF Staff commited on
Commit
f33d9a7
·
1 Parent(s): 091d479

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from pydub import AudioSegment
3
+
4
+ def stream_audio(audio_file):
5
+ audio = AudioSegment.from_mp3(audio_file)
6
+ i = 0
7
+ chunk_size = 3000
8
+
9
+ while chunk_size*i < len(audio):
10
+ chunk = audio[chunk_size*i:chunk_size*(i+1)]
11
+ i += 1
12
+ if chunk:
13
+ file = f"/tmp/{i}.mp3"
14
+ chunk.export(file, format="mp3")
15
+ yield file
16
+
17
+ demo = gr.Interface(
18
+ fn=stream_audio,
19
+ inputs=gr.Audio(type="filepath", label="Audio file to stream"),
20
+ outputs=gr.Audio(autoplay=True, streaming=True),
21
+ )
22
+
23
+ if __name__ == "__main__":
24
+ demo.queue().launch()