Sarath0x8f commited on
Commit
f5db1d8
·
verified ·
1 Parent(s): 02ce658

Delete demo_app.py

Browse files
Files changed (1) hide show
  1. demo_app.py +0 -48
demo_app.py DELETED
@@ -1,48 +0,0 @@
1
- import gradio as gr
2
- import soundfile as sf
3
- import numpy as np
4
- import tempfile
5
- import os
6
-
7
- # Define the file path of the audio file you want to play directly
8
- direct_audio_file_path = "Audio/translated_audio.wav" # Replace this with the actual file path
9
-
10
- # Function to handle audio streaming
11
- def audio_streaming(audio=None):
12
- # If an audio file is provided as input, use it; otherwise, use the direct file path
13
- if audio is None:
14
- audio = direct_audio_file_path
15
-
16
- # Load the audio file
17
- data, samplerate = sf.read(audio)
18
-
19
- # Ensure data is in float32 format
20
- data = np.array(data, dtype=np.float32)
21
-
22
- # Save to a temporary file that Gradio can use for audio playback
23
- with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
24
- sf.write(tmp_file.name, data, samplerate)
25
- temp_audio_path = tmp_file.name
26
-
27
- # Return the file path to Gradio
28
- return temp_audio_path
29
-
30
- # Gradio interface
31
- with gr.Blocks() as demo:
32
- gr.Markdown("### Audio Streaming App")
33
-
34
- # Button to play audio from the predefined file path
35
- play_button = gr.Button("Play Direct Audio")
36
-
37
- # Define output for streamed audio
38
- audio_output = gr.Audio(label="Streamed Audio")
39
-
40
- # Set up the Gradio interface to handle the button click
41
- play_button.click(
42
- fn=audio_streaming,
43
- inputs=None, # No input needed for direct play
44
- outputs=audio_output
45
- )
46
-
47
- if __name__ == "__main__":
48
- demo.launch()