Skip to content

Commit 10c9108

Browse files
authored
v1: Remove _async suffix from all methods, remove fire-n-forget counterparts, code improvements (#7)
* configs * remove fire-and-forget methods | remove _async in methods name * updates
1 parent 5bdaa07 commit 10c9108

File tree

14 files changed

+151
-162
lines changed

14 files changed

+151
-162
lines changed

.ci/patch_pubspec_version.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# /// script
2+
# dependencies = ["pyyaml"]
3+
# ///
4+
15
import os
26
import pathlib
37
import sys
@@ -17,7 +21,7 @@
1721
"flet",
1822
]
1923

20-
with open(pubspec_path, "r") as f:
24+
with open(pubspec_path) as f:
2125
data = yaml.safe_load(f)
2226

2327
# patch version

.ci/patch_toml_version.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# /// script
2+
# dependencies = ["tomlkit"]
3+
# ///
4+
15
import os
26
import pathlib
37
import sys
@@ -14,7 +18,7 @@
1418
print(f"Patching TOML file {toml_path} to {ver}")
1519

1620
# read
17-
with open(toml_path, "r") as f:
21+
with open(toml_path) as f:
1822
t = tomlkit.parse(f.read())
1923

2024
# patch version

.docstr.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
paths: src/flet_audio_recorder
2+
badge: ./docs/assets/badges/docs-coverage.svg
3+
skip_file_doc: True
4+
skip_private: False
5+
ignore_patterns: # Dict with key/value pairs of file-pattern/node-pattern
6+
.*: __post_init__ # Ignore __post_init__ in all files
7+
fail_under: 50

.github/workflows/docs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- main
7-
- dev
87
paths:
98
- 'LICENSE'
109
- 'CHANGELOG.md'

CHANGELOG.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3030
- Recording configuration properties (`audio_encoder`, `suppress_noise`, `cancel_echo`, `auto_gain`, `channels_num`, `sample_rate`, `bit_rate`) are now grouped under `configuration: AudioRecorderConfiguration`
3131
- Event `on_state_changed` renamed to `on_state_change`
3232
- In all methods, parameter `wait_timeout` was renamed to `timeout`.
33-
- The following sync methods were removed from `AudioRecorder` (use corresponding async methods instead):
34-
- `is_recording``is_recording_async`
35-
- `stop_recording``stop_recording_async`
36-
- `cancel_recording``cancel_recording_async`
37-
- `resume_recording``resume_recording_async`
38-
- `pause_recording``pause_recording_async`
39-
- `is_paused``is_paused_async`
40-
- `is_supported_encoder``is_supported_encoder_async`
41-
- `get_input_devices``get_input_devices_async`
42-
- `has_permission``has_permission_async`
33+
- The following `AudioRecorder` sync methods were made [`async`](https://docs.python.org/3/library/asyncio.html):
34+
- `is_recording`
35+
- `stop_recording`
36+
- `cancel_recording`
37+
- `resume_recording`
38+
- `pause_recording`
39+
- `is_paused`
40+
- `is_supported_encoder`
41+
- `get_input_devices`
42+
- `has_permission`
4343

4444
## [0.1.0] - 2025-01-15
4545

4646
Initial release.
4747

4848

4949
[0.2.0]: https://github.com/flet-dev/flet-audio-recorder/compare/0.1.0...0.2.0
50-
[0.1.0]: https://github.com/flet-dev/flet-audio-recorder/releases/tag/0.1.0
50+
[0.1.0]: https://github.com/flet-dev/flet-audio-recorder/releases/tag/0.1.0

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ This package supports the following platforms:
2525
| Android ||
2626
| Web ||
2727

28-
## Installation
28+
## Usage
29+
30+
### Installation
2931

3032
To install the `flet-audio-recorder` package and add it to your project dependencies:
3133

@@ -48,6 +50,6 @@ To install the `flet-audio-recorder` package and add it to your project dependen
4850
> [!NOTE]
4951
> On Linux, encoding is provided by [fmedia](https://stsaz.github.io/fmedia/) which must be installed separately.
5052

51-
## Examples
53+
### Examples
5254

53-
For examples, see [this](./examples)
55+
For examples, see [these](./examples).

appveyor.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,20 @@ image: ubuntu
33
version: '0.1.{build}'
44

55
environment:
6+
PYTHON_VERSION: 3.12
67
UV_PUBLISH_TOKEN:
78
secure: 174ncAbF5IjSIkmioPt62jeSnzmTlRNchUkE4QdjDWH8xK1olYtySXLJpo2q95HcP7lWJky1hv4APESiRRHnBWoY0XRFafzM/mbCDMzG1tZXiXZmpP1qzHAtRP2QSCIg18xh1TMktraUdTi7sbJnjjRhqzgbW1k0kLBxKw79MPFBhYQ/TiGcmaYWZbWVZNY3HCUCb6Dt7bG1OE2Ul9rD1gvs55xwO9Oq9FOVA1VnMYw=
89

9-
stack:
10-
- python 3.12
11-
1210
install:
1311
- source .ci/update_build_version.sh
14-
- python --version
15-
- python -m ensurepip --upgrade
16-
- pip3 install --upgrade tomlkit pyyaml
1712
- curl -LsSf https://astral.sh/uv/install.sh | sh
18-
- export PATH=$HOME/.local/bin:$PATH
13+
- export PATH="$HOME/.local/bin:$PATH"
14+
- uv python install $PYTHON_VERSION
15+
- uv python pin $PYTHON_VERSION
1916

2017
build_script:
21-
- python .ci/patch_toml_version.py pyproject.toml $PYPI_VER
22-
- python .ci/patch_pubspec_version.py src/flutter/flet_*/pubspec.yaml $PKG_VER
18+
- uv run .ci/patch_toml_version.py pyproject.toml $PYPI_VER
19+
- uv run .ci/patch_pubspec_version.py src/flutter/flet_*/pubspec.yaml $PKG_VER
2320
- (cd src/flutter/* && dart pub get && dart analyze && cd -)
2421
- uv build
2522

@@ -32,4 +29,4 @@ deploy_script:
3229
artifacts:
3330
- path: dist/*.whl
3431

35-
test: off
32+
test: off

docs/audio_recorder.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
::: flet_audio_recorder.audio_recorder.AudioRecorder
1+
## Examples
2+
3+
### Example 1
4+
5+
```python title="example_1.py"
6+
--8<-- "examples/audio_recorder_example/src/example_1.py"
7+
```
8+
9+
::: flet_audio_recorder.audio_recorder.AudioRecorder

docs/index.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ To install the `flet-audio-recorder` package and add it to your project dependen
3636
```bash
3737
pip install flet-audio-recorder # (1)!
3838
```
39-
39+
4040
1. After this, you will have to manually add this package to your `requirements.txt` or `pyproject.toml`.
4141

4242
=== "poetry"
@@ -47,9 +47,6 @@ To install the `flet-audio-recorder` package and add it to your project dependen
4747
???+ note
4848
On Linux, encoding is provided by [fmedia](https://stsaz.github.io/fmedia/) which must be installed separately.
4949

50+
### Examples
5051

51-
## Example
52-
53-
```python title="main.py"
54-
--8<-- "examples/audio_recorder_example/src/main.py"
55-
```
52+
See [these](audio_recorder.md#examples).
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import flet as ft
2+
3+
import flet_audio_recorder as far
4+
5+
6+
def main(page: ft.Page):
7+
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
8+
page.appbar = ft.AppBar(title=ft.Text("Audio Recorder"), center_title=True)
9+
10+
path = "test-audio-file.wav"
11+
12+
def show_snackbar(message):
13+
page.show_dialog(ft.SnackBar(ft.Text(message)))
14+
15+
async def handle_recording_start(e: ft.Event[ft.Button]):
16+
show_snackbar("Starting recording...")
17+
await recorder.start_recording(output_path=path)
18+
19+
async def handle_recording_stop(e: ft.Event[ft.Button]):
20+
output_path = await recorder.stop_recording()
21+
show_snackbar(f"Stopped recording. Output Path: {output_path}")
22+
if page.web and output_path is not None:
23+
await page.launch_url(output_path)
24+
25+
async def handle_list_devices(e: ft.Event[ft.Button]):
26+
o = await recorder.get_input_devices()
27+
show_snackbar(f"Input Devices: {', '.join([d.label for d in o])}")
28+
29+
async def handle_has_permission(e: ft.Event[ft.Button]):
30+
try:
31+
status = await recorder.has_permission()
32+
show_snackbar(f"Audio Recording Permission status: {status}")
33+
except Exception as e:
34+
show_snackbar(f"Error checking permission: {e}")
35+
36+
async def handle_pause(e: ft.Event[ft.Button]):
37+
print(f"isRecording: {await recorder.is_recording()}")
38+
if await recorder.is_recording():
39+
await recorder.pause_recording()
40+
41+
async def handle_resume(e: ft.Event[ft.Button]):
42+
print(f"isPaused: {await recorder.is_paused()}")
43+
if await recorder.is_paused():
44+
await recorder.resume_recording()
45+
46+
async def handle_audio_encoder_test(e: ft.Event[ft.Button]):
47+
print(await recorder.is_supported_encoder(far.AudioEncoder.WAV))
48+
49+
recorder = far.AudioRecorder(
50+
configuration=far.AudioRecorderConfiguration(encoder=far.AudioEncoder.WAV),
51+
on_state_change=lambda e: print(f"State Changed: {e.data}"),
52+
)
53+
page.services.append(recorder)
54+
55+
page.add(
56+
ft.Button(content="Start Audio Recorder", on_click=handle_recording_start),
57+
ft.Button(content="Stop Audio Recorder", on_click=handle_recording_stop),
58+
ft.Button(content="List Devices", on_click=handle_list_devices),
59+
ft.Button(content="Pause Recording", on_click=handle_pause),
60+
ft.Button(content="Resume Recording", on_click=handle_resume),
61+
ft.Button(content="WAV Encoder Support", on_click=handle_audio_encoder_test),
62+
ft.Button(
63+
content="Get Audio Recording Permission Status",
64+
on_click=handle_has_permission,
65+
),
66+
)
67+
68+
69+
ft.run(main)

0 commit comments

Comments
 (0)