Services

AudioRecorder

AudioRecorder service

Create or retrieve this service with page.audio_recorder(**properties). Ruflet reuses the registered service unless you supply a different id.

Example

status = text(value: "Recorder ready")
page.add(status)
recorder = page.audio_recorder(
  on_state_change: ->(event) { page.update(status, value: event.data.to_s) }
)
recorder.has_permission(on_result: ->(allowed, error) {
  if error
    page.update(status, value: error.to_s)
  elsif allowed
    recorder.start_recording(
      output_path: "voice-note.m4a",
      configuration: { encoder: "aac_lc" },
      on_result: ->(_result, start_error) {
        page.update(status, value: start_error ? start_error.to_s : "Recording")
      }
    )
  end
})

Page accessor

  • page.audio_recorder(**props)

Properties

  • configuration — Sets the configuration property.
  • data — Arbitrary value you can attach to the control and read back in handlers.
  • key — Stable identity used to preserve state across rebuilds.

Events

  • on_state_change — Fired when the control's state changes.
  • on_stream — Fired on stream.
  • on_upload — Fired on upload.

Service methods

  • cancel_recording(timeout: ..., on_result: ...)
  • get_input_devices(timeout: ..., on_result: ...)
  • has_permission(timeout: ..., on_result: ...)
  • is_paused(timeout: ..., on_result: ...)
  • is_recording(timeout: ..., on_result: ...)
  • is_supported_encoder(encoder, timeout: ..., on_result: ...)
  • pause_recording(timeout: ..., on_result: ...)
  • resume_recording(timeout: ..., on_result: ...)
  • start_recording(output_path: ..., configuration: ..., upload: ..., timeout: ..., on_result: ...)
  • stop_recording(timeout: ..., on_result: ...)

Result and error handling

Client calls are asynchronous. When a method accepts on_result:, handle both callback values: |result, error|. Availability and returned data can vary by platform.

Common service API

The service also supports the common Ruflet control API: attach_handler(event_name, handler), children, emit(event_name, event), has_handler?(event_name), id, merge_props(values = ...), on(event_name, &block), props, runtime_page, runtime_page=, to_patch, type, wire_id, wire_id=.

Use the named methods above for application code; common control methods mainly support event registration, updates, and runtime integration.

Wire reference

  • Service helper: audio_recorder
  • Wire type: audiorecorder
  • Aliases: audiorecorder

Client extension setup

This service is implemented by the flet_audio_recorder Flet extension. Enable it in ruflet.yaml, then rebuild the client:

extensions:
  - audio_recorder

Application code uses page.audio_recorder; do not add the package directly to your app's Flutter dependencies.

Declare protected access in services.yaml:

services:
  - microphone:
      description: Explain why your app needs microphone access.