Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,21 +25,21 @@ class TextFileReader:
|
|
25 |
self.current_index = max(self.current_index - 1, 0)
|
26 |
return self.get_current_line()
|
27 |
|
28 |
-
# Initialize the text reader
|
29 |
reader = TextFileReader()
|
30 |
|
31 |
# Define a function to save the text lines to a file
|
32 |
def save_text_lines(file):
|
33 |
lines = reader.read_lines(file)
|
34 |
-
with open("text_lines.txt", "w") as f:
|
35 |
f.write("\n".join(reader.lines))
|
36 |
return lines
|
37 |
|
38 |
# Define a function to save the audio file
|
39 |
def save_audio_file(audio):
|
40 |
-
|
|
|
41 |
f.write(audio['data'])
|
42 |
-
return
|
43 |
|
44 |
# Define the Gradio interface
|
45 |
with gr.Blocks() as demo:
|
@@ -69,13 +69,14 @@ with gr.Blocks() as demo:
|
|
69 |
next_button.click(fn=forward_output, inputs=None, outputs=current_line)
|
70 |
|
71 |
with gr.Row():
|
72 |
-
audio_record = gr.Audio(
|
73 |
audio_output = gr.Audio(label="Recorded Audio")
|
74 |
|
75 |
def display_audio(audio):
|
76 |
-
save_audio_file(audio) # Save the audio file
|
77 |
-
return
|
78 |
|
79 |
audio_record.change(fn=display_audio, inputs=audio_record, outputs=audio_output)
|
80 |
|
81 |
demo.launch()
|
|
|
|
25 |
self.current_index = max(self.current_index - 1, 0)
|
26 |
return self.get_current_line()
|
27 |
|
|
|
28 |
reader = TextFileReader()
|
29 |
|
30 |
# Define a function to save the text lines to a file
|
31 |
def save_text_lines(file):
|
32 |
lines = reader.read_lines(file)
|
33 |
+
with open("/tmp/text_lines.txt", "w") as f:
|
34 |
f.write("\n".join(reader.lines))
|
35 |
return lines
|
36 |
|
37 |
# Define a function to save the audio file
|
38 |
def save_audio_file(audio):
|
39 |
+
audio_path = "/tmp/recorded_audio.wav"
|
40 |
+
with open(audio_path, "wb") as f:
|
41 |
f.write(audio['data'])
|
42 |
+
return audio_path
|
43 |
|
44 |
# Define the Gradio interface
|
45 |
with gr.Blocks() as demo:
|
|
|
69 |
next_button.click(fn=forward_output, inputs=None, outputs=current_line)
|
70 |
|
71 |
with gr.Row():
|
72 |
+
audio_record = gr.Audio(source="microphone", type="file", label="Record Audio")
|
73 |
audio_output = gr.Audio(label="Recorded Audio")
|
74 |
|
75 |
def display_audio(audio):
|
76 |
+
audio_path = save_audio_file(audio) # Save the audio file
|
77 |
+
return audio_path
|
78 |
|
79 |
audio_record.change(fn=display_audio, inputs=audio_record, outputs=audio_output)
|
80 |
|
81 |
demo.launch()
|
82 |
+
|