Back to Flet

AudioRecorder

website/docs/services/audiorecorder/index.md

0.85.0.dev25.3 KB
Original Source

import TabItem from '@theme/TabItem'; import Tabs from '@theme/Tabs'; import {ClassAll, CodeExample} from '@site/src/components/crocodocs';

Audio Recorder

Allows recording audio in Flet apps.

It is based on the record Flutter package.

Platform Support

PlatformWindowsmacOSLinuxiOSAndroidWeb
Supported

Usage

To use AudioRecorder service add flet-audio-recorder package to your project dependencies:

<Tabs groupId="uv--pip"> <TabItem value="uv" label="uv"> ```bash uv add flet-audio-recorder ``` </TabItem> <TabItem value="pip" label="pip"> ```bash pip install flet-audio-recorder # (1)! ```
  1. After this, you will have to manually add this package to your requirements.txt or pyproject.toml. </TabItem>
</Tabs> ## Requirements

The below sections show the required configurations for each platform.

Android

Configuration to be made to access the microphone:

<Tabs groupId="flet-build--pyproject-toml"> <TabItem value="flet-build" label="flet build"> ```bash flet build apk \ --android-permissions android.permission.RECORD_AUDIO=true \ --android-permissions android.permission.WRITE_EXTERNAL_STORAGE=true \ --android-permissions android.permission.MODIFY_AUDIO_SETTINGS=true ``` </TabItem> <TabItem value="pyproject-toml" label="pyproject.toml"> ```toml [tool.flet.android.permission] "android.permission.RECORD_AUDIO" = true "android.permission.WRITE_EXTERNAL_STORAGE" = true "android.permission.MODIFY_AUDIO_SETTINGS" = true ``` </TabItem> </Tabs> See also:

iOS

Configuration to be made to access the microphone:

<Tabs groupId="flet-build--pyproject-toml"> <TabItem value="flet-build" label="flet build"> ```bash flet build ipa \ --info-plist NSMicrophoneUsageDescription="Some message to describe why you need this permission..." ``` </TabItem> <TabItem value="pyproject-toml" label="pyproject.toml"> ```toml [tool.flet.ios.info] NSMicrophoneUsageDescription = "Some message to describe why you need this permission..." ``` </TabItem> </Tabs> See also:

macOS

Configuration to be made to access the microphone:

<Tabs groupId="flet-build--pyproject-toml"> <TabItem value="flet-build" label="flet build"> ```bash flet build macos \ --info-plist NSMicrophoneUsageDescription="Some message to describe why you need this permission..." \ --macos-entitlements com.apple.security.device.audio-input=true ``` </TabItem> <TabItem value="pyproject-toml" label="pyproject.toml"> ```toml [tool.flet.macos.info] NSMicrophoneUsageDescription = "Some message to describe why you need this permission..."

[tool.flet.macos.entitlement] "com.apple.security.device.audio-input" = true

</TabItem>
</Tabs>
See also:

- [setting macOS permissions](../../publish/macos.md#permissions)
- [setting macOS entitlements](../../publish/macos.md#entitlements)

### Linux

The following dependencies are required (and widely available on your system):

- `parecord`: Used for audio input.
- `pactl`: Used for utility methods like getting available devices.
- [`ffmpeg`](https://ffmpeg.org): Used for encoding and output.

On Ubuntu 24.04.3 LTS, you can install them using:
```bash
sudo apt install pulseaudio-utils ffmpeg

Cross-platform

Additionally/alternatively, you can make use of our predefined cross-platform microphone permission bundle:

<Tabs groupId="flet-build--pyproject-toml"> <TabItem value="flet-build" label="flet build"> ```bash flet build <target_platform> --permissions microphone ``` </TabItem> <TabItem value="pyproject-toml" label="pyproject.toml"> ```toml [tool.flet] permissions = ["microphone"] ``` </TabItem> </Tabs> ## Example

<CodeExample path={frontMatter.examples + '/example_1/main.py'} language="python" />

Description

<ClassAll name={frontMatter.class_name} />