Spaces:
Build error
Build error
Improve recording UI/UX
Browse files
app.py
CHANGED
|
@@ -16,6 +16,7 @@ def main(page: ft.Page):
|
|
| 16 |
on_state_changed=lambda e: update_recording_status(e.data)
|
| 17 |
)
|
| 18 |
recording_status = ft.Text()
|
|
|
|
| 19 |
audio_player = None # Initialize audio_player as None
|
| 20 |
|
| 21 |
page.overlay.append(audio_recorder) # Only add audio_recorder to overlay initially
|
|
@@ -26,15 +27,19 @@ def main(page: ft.Page):
|
|
| 26 |
|
| 27 |
def start_recording(e):
|
| 28 |
record_button.disabled = True
|
| 29 |
-
stop_button.disabled =
|
| 30 |
play_button.disabled = True
|
|
|
|
|
|
|
| 31 |
page.update()
|
| 32 |
|
| 33 |
nonlocal temp_recording_file
|
| 34 |
temp_recording_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
| 35 |
logger.info(f"Starting recording to {temp_recording_file.name}")
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def stop_recording(e):
|
| 40 |
record_button.disabled = False
|
|
@@ -61,7 +66,12 @@ def main(page: ft.Page):
|
|
| 61 |
audio_player.play()
|
| 62 |
|
| 63 |
def update_recording_status(status):
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
page.update()
|
| 66 |
|
| 67 |
record_button = ft.ElevatedButton("Start Recording", on_click=start_recording)
|
|
@@ -84,7 +94,7 @@ def main(page: ft.Page):
|
|
| 84 |
|
| 85 |
page.add(
|
| 86 |
ft.Text("Simple Audio Recorder", size=24),
|
| 87 |
-
ft.Row([record_button, stop_button, play_button]),
|
| 88 |
recording_status,
|
| 89 |
ft.ElevatedButton("List Devices", on_click=handle_list_devices),
|
| 90 |
ft.ElevatedButton("Test AudioEncodings", on_click=handle_audio_encoding_test),
|
|
|
|
| 16 |
on_state_changed=lambda e: update_recording_status(e.data)
|
| 17 |
)
|
| 18 |
recording_status = ft.Text()
|
| 19 |
+
loading_animation = ft.ProgressRing(visible=False)
|
| 20 |
audio_player = None # Initialize audio_player as None
|
| 21 |
|
| 22 |
page.overlay.append(audio_recorder) # Only add audio_recorder to overlay initially
|
|
|
|
| 27 |
|
| 28 |
def start_recording(e):
|
| 29 |
record_button.disabled = True
|
| 30 |
+
stop_button.disabled = True
|
| 31 |
play_button.disabled = True
|
| 32 |
+
loading_animation.visible = True
|
| 33 |
+
recording_status.value = "Preparing to record..."
|
| 34 |
page.update()
|
| 35 |
|
| 36 |
nonlocal temp_recording_file
|
| 37 |
temp_recording_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
| 38 |
logger.info(f"Starting recording to {temp_recording_file.name}")
|
| 39 |
+
|
| 40 |
+
audio_recorder.start_recording(temp_recording_file.name, wait_timeout=2)
|
| 41 |
+
|
| 42 |
+
# The actual recording start will be handled in update_recording_status
|
| 43 |
|
| 44 |
def stop_recording(e):
|
| 45 |
record_button.disabled = False
|
|
|
|
| 66 |
audio_player.play()
|
| 67 |
|
| 68 |
def update_recording_status(status):
|
| 69 |
+
if status == "recording":
|
| 70 |
+
stop_button.disabled = False
|
| 71 |
+
loading_animation.visible = False
|
| 72 |
+
recording_status.value = "Recording in progress..."
|
| 73 |
+
else:
|
| 74 |
+
recording_status.value = f"Recording status: {status}"
|
| 75 |
page.update()
|
| 76 |
|
| 77 |
record_button = ft.ElevatedButton("Start Recording", on_click=start_recording)
|
|
|
|
| 94 |
|
| 95 |
page.add(
|
| 96 |
ft.Text("Simple Audio Recorder", size=24),
|
| 97 |
+
ft.Row([record_button, stop_button, play_button, loading_animation]),
|
| 98 |
recording_status,
|
| 99 |
ft.ElevatedButton("List Devices", on_click=handle_list_devices),
|
| 100 |
ft.ElevatedButton("Test AudioEncodings", on_click=handle_audio_encoding_test),
|