Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,27 +48,23 @@ def save_audio_text(audio, text):
|
|
48 |
# Debugging to print out the structure of the audio variable
|
49 |
print("Received audio data:", audio)
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
return next_line
|
67 |
-
else:
|
68 |
-
return "Audio data is not in the expected format."
|
69 |
-
except Exception as e:
|
70 |
-
print(f"Error saving audio: {e}")
|
71 |
-
return "Error saving audio."
|
72 |
|
73 |
# Define the Gradio interface
|
74 |
with gr.Blocks() as demo:
|
@@ -92,3 +88,4 @@ with gr.Blocks() as demo:
|
|
92 |
save_button.click(fn=save_audio_text, inputs=[audio_record, current_line], outputs=current_line)
|
93 |
|
94 |
demo.launch()
|
|
|
|
48 |
# Debugging to print out the structure of the audio variable
|
49 |
print("Received audio data:", audio)
|
50 |
|
51 |
+
# Check if audio is a dictionary and contains 'data'
|
52 |
+
if isinstance(audio, dict) and 'data' in audio:
|
53 |
+
audio_data = audio['data']
|
54 |
+
audio_path = f"/tmp/recordings/line_{reader.current_index}.wav"
|
55 |
+
text_path = f"/tmp/recordings/line_{reader.current_index}.txt"
|
56 |
+
|
57 |
+
with open(audio_path, "wb") as f:
|
58 |
+
f.write(audio_data)
|
59 |
|
60 |
+
with open(text_path, "w") as f:
|
61 |
+
f.write(text)
|
62 |
+
|
63 |
+
# Move to the next line after saving
|
64 |
+
next_line = reader.forward_line()
|
65 |
+
return next_line
|
66 |
+
else:
|
67 |
+
return "Audio data is not in the expected format."
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
# Define the Gradio interface
|
70 |
with gr.Blocks() as demo:
|
|
|
88 |
save_button.click(fn=save_audio_text, inputs=[audio_record, current_line], outputs=current_line)
|
89 |
|
90 |
demo.launch()
|
91 |
+
|