Spaces:
Build error
Build error
Fixed pop and add exp backoff
Browse files
app.py
CHANGED
|
@@ -51,7 +51,6 @@ async def main(page: ft.Page):
|
|
| 51 |
async def stop_recording_flet(e):
|
| 52 |
record_button.disabled = False
|
| 53 |
stop_button.disabled = True
|
| 54 |
-
play_button.disabled = False
|
| 55 |
|
| 56 |
page.update()
|
| 57 |
nonlocal audio_player
|
|
@@ -73,12 +72,13 @@ async def main(page: ft.Page):
|
|
| 73 |
|
| 74 |
# Create audio_player using the base64 string from audio_storage
|
| 75 |
if page.session_id in audio_storage:
|
| 76 |
-
base64_audio = audio_storage
|
| 77 |
audio_player = ft.Audio(src=f"data:audio/wav;base64,{base64_audio}")
|
| 78 |
page.overlay.append(audio_player)
|
| 79 |
else:
|
| 80 |
logger.error(f"Audio data not found for session {page.session_id}")
|
| 81 |
|
|
|
|
| 82 |
page.update()
|
| 83 |
logger.info(page.controls)
|
| 84 |
|
|
@@ -283,11 +283,17 @@ async def get_audio(session_id: str):
|
|
| 283 |
audio_data = audio_storage.pop(session_id)
|
| 284 |
|
| 285 |
return JSONResponse(content={"audio_data": audio_data})
|
| 286 |
-
|
| 287 |
# Add this helper function to wait for the audio data
|
| 288 |
-
async def wait_for_audio_data(session_id,
|
| 289 |
-
|
|
|
|
|
|
|
| 290 |
if session_id in audio_storage:
|
| 291 |
return
|
| 292 |
-
await asyncio.sleep(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
logger.error(f"Timeout waiting for audio data for session {session_id}")
|
|
|
|
|
|
| 51 |
async def stop_recording_flet(e):
|
| 52 |
record_button.disabled = False
|
| 53 |
stop_button.disabled = True
|
|
|
|
| 54 |
|
| 55 |
page.update()
|
| 56 |
nonlocal audio_player
|
|
|
|
| 72 |
|
| 73 |
# Create audio_player using the base64 string from audio_storage
|
| 74 |
if page.session_id in audio_storage:
|
| 75 |
+
base64_audio = audio_storage.pop(page.session_id)
|
| 76 |
audio_player = ft.Audio(src=f"data:audio/wav;base64,{base64_audio}")
|
| 77 |
page.overlay.append(audio_player)
|
| 78 |
else:
|
| 79 |
logger.error(f"Audio data not found for session {page.session_id}")
|
| 80 |
|
| 81 |
+
play_button.disabled = False
|
| 82 |
page.update()
|
| 83 |
logger.info(page.controls)
|
| 84 |
|
|
|
|
| 283 |
audio_data = audio_storage.pop(session_id)
|
| 284 |
|
| 285 |
return JSONResponse(content={"audio_data": audio_data})
|
|
|
|
| 286 |
# Add this helper function to wait for the audio data
|
| 287 |
+
async def wait_for_audio_data(session_id, max_wait_time=5, initial_interval=0.01):
|
| 288 |
+
start_time = time.time()
|
| 289 |
+
interval = initial_interval
|
| 290 |
+
while time.time() - start_time < max_wait_time:
|
| 291 |
if session_id in audio_storage:
|
| 292 |
return
|
| 293 |
+
await asyncio.sleep(interval)
|
| 294 |
+
# Exponential backoff with a maximum interval of 0.5 seconds
|
| 295 |
+
interval = min(interval * 1.5, 0.5)
|
| 296 |
+
|
| 297 |
+
# If we've reached this point, we've timed out
|
| 298 |
logger.error(f"Timeout waiting for audio data for session {session_id}")
|
| 299 |
+
|