flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
10.02k stars 392 forks source link

StartRecording: test-audio-file.wav error #3548

Open yst-one opened 1 week ago

yst-one commented 1 week ago

Duplicate Check

Describe the bug

C:\Users\Administrator\PycharmProjects\mybilibili\main.py:12: DeprecationWarning: start_recording_async() is deprecated in version 0.21.0 and will be removed in version 0.26.0. Use start_recording() method instead. await audio_rec.start_recording_async(path) Task exception was never retrieved future: <Task finished name='Task-12' coro=<__run_socket_server..on_event() done, defined at C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\mybilibili-S1CJaOEz-py3.12\Lib\site-packages\flet_runtime\app.py:217> exception=TimeoutError("Timeout waiting for invokeMethod start_recording({'outputPath': 'test-audio-file.wav'}) call")> Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\mybilibili-S1CJaOEz-py3.12\Lib\site-packages\flet_runtime\app.py", line 219, in on_event await conn.sessions[e.sessionID].on_event_async( File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\mybilibili-S1CJaOEz-py3.12\Lib\site-packages\flet_core\page.py", line 914, in on_event_async await handler(ce) File "C:\Users\Administrator\PycharmProjects\mybilibili\main.py", line 12, in handle_start_recording await audio_rec.start_recording_async(path) File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\mybilibili-S1CJaOEz-py3.12\Lib\site-packages\flet_core\audio_recorder.py", line 84, in start_recording_async return self.start_recording(output_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\mybilibili-S1CJaOEz-py3.12\Lib\site-packages\flet_core\audio_recorder.py", line 70, in start_recording started = self.invoke_method( ^^^^^^^^^^^^^^^^^^^ File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\mybilibili-S1CJaOEz-py3.12\Lib\site-packages\flet_core\control.py", line 339, in invoke_method return self.__page._invoke_method( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\mybilibili-S1CJaOEz-py3.12\Lib\site-packages\flet_core\page.py", line 1351, in _invoke_method raise TimeoutError( TimeoutError: Timeout waiting for invokeMethod start_recording({'outputPath': 'test-audio-file.wav'}) call {0: ({0.0.1.00000000}.{65393a88-adf1-43da-85fa-3775dac09f93}, 耳机 (2- Redmi AirDots S))}

Code

import flet as ft

async def main(page: ft.Page): page.theme_mode = "light" page.window_always_on_top = True page.horizontal_alignment = ft.CrossAxisAlignment.CENTER path = "test-audio-file.wav"

async def handle_start_recording(e):
    print(f"StartRecording: {path}")
    await audio_rec.start_recording_async(path)

async def handle_stop_recording(e):
    output_path = await audio_rec.stop_recording_async()
    print(f"StopRecording: {output_path}")
    if page.web and output_path is not None:
        await page.launch_url_async(output_path)

async def handle_list_devices(e):
    devices = await audio_rec.get_input_devices_async()
    print(devices)

async def handle_has_permission(e):
    try:
        print(f"HasPermission: {await audio_rec.has_permission_async()}")
    except Exception as e:
        print(e)

async def handle_pause(e):
    print(f"isRecording: {await audio_rec.is_recording_async()}")
    if await audio_rec.is_recording_async():
        await audio_rec.pause_recording_async()

async def handle_resume(e):
    print(f"isPaused: {await audio_rec.is_paused_async()}")
    if await audio_rec.is_paused_async():
        await audio_rec.resume_recording_async()

async def handle_audio_encoding_test(e):
    for i in list(ft.AudioEncoder):
        print(f"{i}: {await audio_rec.is_supported_encoder_async(i)}")

page.appbar = ft.AppBar(
    title=ft.Text("Audio Recorder"),
    adaptive=True,
    bgcolor=ft.colors.PRIMARY_CONTAINER,
)

audio_rec = ft.AudioRecorder(
    audio_encoder=ft.AudioEncoder.WAV,
)
page.overlay.append(audio_rec)
await page.update_async()

await page.add_async(
    ft.ElevatedButton(
        "Start Audio Recorder",
        on_click=handle_start_recording,
    ),
    ft.ElevatedButton(
        "Stop Audio Recorder",
        on_click=handle_stop_recording,
    ),
    ft.ElevatedButton(
        "List Devices",
        on_click=handle_list_devices,
    ),
    ft.ElevatedButton(
        "Pause Recording",
        on_click=handle_pause,
    ),
    ft.ElevatedButton(
        "Resume Recording",
        on_click=handle_resume,
    ),
    ft.ElevatedButton(
        "Test AudioEncodings",
        on_click=handle_audio_encoding_test,
    ),
    ft.ElevatedButton(
        "Has Permission",
        on_click=handle_has_permission,
    ),
)

ft.app(target=main)

To reproduce

error

Expected behavior

No response

Screenshots

No response

Operating System

Windows

Operating system details

win11

Flet version

23

Regression

I'm not sure / I don't know

Suggestions

No response

Additional details

No response

AndreWurl commented 1 week ago

Same problem here, the Audio-Recorder Sample Code does not work.