Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: AutoGain filter #12

Merged
merged 30 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
184ef59
filters structure
alnitak Nov 21, 2024
af6b08c
added filter management in Dart
alnitak Nov 22, 2024
66aada1
test autoGain
alnitak Nov 26, 2024
ccd2be5
autoGainFilter doc
alnitak Nov 26, 2024
d3107e0
++
alnitak Nov 26, 2024
ec31a02
added c++17 for mac and iOS
alnitak Nov 27, 2024
8c229ed
fix compilation for macand iOS
alnitak Nov 27, 2024
a1c8a1a
mac and iOS compilation fix
alnitak Nov 27, 2024
4136e33
web wip
alnitak Dec 11, 2024
092ee8b
++
alnitak Dec 12, 2024
df007a5
WASM JS Module renamed
alnitak Dec 13, 2024
2e18d0d
WASM JS Module renamed
alnitak Dec 13, 2024
412f75f
just a log when init recorder when already initialized
alnitak Dec 13, 2024
c31a251
added `uint8ListStream` note
alnitak Dec 13, 2024
5decc28
added `uint8ListStream` note
alnitak Dec 13, 2024
dc38b6c
update README
alnitak Dec 13, 2024
802d126
update README
alnitak Dec 13, 2024
68dedc7
fix the call to native function before init
alnitak Dec 13, 2024
6da1d78
chore
alnitak Dec 13, 2024
63309a4
renamed `FilterType` to `RecorderFilterType`
alnitak Dec 16, 2024
db935dd
added js to load RecorderModule at start
alnitak Dec 16, 2024
f260651
chore
alnitak Dec 17, 2024
b7bf260
chore
alnitak Dec 17, 2024
6d7f12a
chore
alnitak Dec 17, 2024
8bd7523
update REAME
alnitak Dec 21, 2024
183a6f5
added experimental to `Filters` class
alnitak Dec 21, 2024
edee74d
update CHANGELOG
alnitak Dec 21, 2024
cb81113
bump version
alnitak Dec 21, 2024
c5029f1
added analyzer
alnitak Dec 21, 2024
e92b158
fix example pubspec
alnitak Dec 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/analyze.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Flutter Analyze

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build:
name: Analyze code and requirements
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'

- name: Verify Flutter installation
run: flutter doctor

- name: Check pub dependencies
run: flutter pub get

- name: "Run Dart Analyze"
uses: invertase/github-action-dart-analyzer@v3
with:
fatal-infos: true
fatal-warnings: true
annotate: true
working-directory: lib/

- name: Check Code formatting
run: dart format -o none --set-exit-if-changed .

- name: Check pub.dev requirements
run: flutter pub publish --dry-run

- name: Block merge if checks fail
if: ${{ failure() }}
run: echo "Checks failed, cannot merge." && exit 1
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "example debug",
"request": "launch",
"type": "dart",
"program": "lib/main.dart",
"program": "lib/loopback.dart",
"cwd": "${workspaceFolder}/example"
},
{
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"bitset": "cpp"
"bitset": "cpp",
"cfenv": "cpp",
"unordered_set": "cpp"
}
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"label": "compile linux debug",
"command": "cd ${workspaceFolder}/example; flutter build linux -t lib/main.dart --debug",
"command": "cd ${workspaceFolder}/example; flutter build linux -t lib/loopback.dart --debug",
"type": "shell"
},
{
Expand Down
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
## 0.9.3
- added `autoGain` filter
- breaking changes:
- the `init` method is now async
- `FilterType` renamed to `RecorderFilterType`
- an [additional script](https://github.com/alnitak/flutter_recorder#web) must be added for the web platform. Now it looks like:
```
<script src="assets/packages/flutter_recorder/web/libflutter_recorder_plugin.js" defer></script>
<script src="assets/packages/flutter_recorder/web/init_recorder_module.dart.js" defer></script>
```

## 0.9.2
* fix: the stop was instead einit the device
* fix: removed dialog when stopping stream in the example
- fix: the stop was instead einit the device
- fix: removed dialog when stopping stream in the example

## 0.9.1
* breaking change:
- breaking changes:
- renamed `startListen` to `start`
- renamed `stopListen` to `stop`
- renamed `isDeviceStartedListen` to `isDeviceStarted`
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ A low-level audio recorder plugin that uses miniaudio as the backend and support
- 📊 **Customizable Silence Threshold**: Define what’s considered “silence” for your recordings.
- ⏱️ **Adjustable Pause Timing**: Set how long silence lasts before pausing, and how soon to resume recording.
- 🔊 **Real-time Audio Metrics**: Access volume, audio wave, and FFT data in real-time.
- 🎚️ **Auto Gain**: Experimental Auto Gain filter.
- 🌐 **Cross Platform**: Supports all platforms with WASM support for the web.

[A web example compiled in WASM.](https://marcobavagnoli.com/flutter_recorder/)

## 🚀 Setup Permissions
After setting up permission for you Android, MacOS or iOS, in your app, you will need to ask for permission to use the microphonem maybe using [permission_handler](https://pub.dev/packages/permission_handler) plugin.
## 🚀 Setup
After setting up permission for you Android, MacOS or iOS, in your app, you will need to ask for permission to use the microphone maybe using [permission_handler](https://pub.dev/packages/permission_handler) plugin.
https://pub.dev/packages/permission_handler

#### Android
Expand All @@ -43,7 +45,16 @@ Add the permission in `Runner/Info.plist`.
Add this in `web/index.html` under the `<head>` tag.
```
<script src="assets/packages/flutter_recorder/web/libflutter_recorder_plugin.js" defer></script>
<script src="assets/packages/flutter_recorder/web/init_recorder_module.dart.js" defer></script>
```
The plugin is **WASM** compatible and your app can be compiled and run locally with something like:
```
flutter run -d chrome --web-renderer canvaskit --web-browser-flag '--disable-web-security' -t lib/main.dart --release
```

#### Linux
- [`GStreamer`](https://gstreamer.freedesktop.org/documentation/installing/index.html?gi-language=c) is installed by default on most distributions, but if not, please [install it](https://gstreamer.freedesktop.org/documentation/installing/on-linux.html?gi-language=c) through your distribution's package manager.
- Installing Flutter using `snap` could cause compilation problems with native plugins. The only solution is to uninstall it with `sudo snap remove flutter` and install it the [official way](https://flutter-ko.dev/get-started/install/linux).

## 🛠️ Usage Example
```dart
Expand Down Expand Up @@ -136,4 +147,28 @@ Recorder.instance.uint8ListStream.listen((data) {
Recorder.instance.startStreamingData();
/// Stop streaming:
Recorder.instance.stopStreamingData();
```
```
> [!CAUTION]
> Audio data must be processed as it is received. To optimize performance, the same memory is used to store data for all incoming streams, meaning the data will be overwritten. Therefore, you must copy the data if you need to populate a buffer while it arrives.
> For example, when using **RxDart.bufferTime**, it will fill a **List** of `AudioDataContainer` objects, but when you attempt to read them, you will find that all the items contain the same data.

### 🎚️ Auto Gain Filter

> [!WARNING]
> This is an experimental feature, may change in the future.

```
final Recorder recorder = Recorder.instance;
// Please look at the [Recorder.instance.autoGainFilter] doc to have a parameters overview.
final AutoGain autoGain = recorder.filters.autoGainFilter;

// You can now query or set parameters:
// For example with [autoGain.queryTargetRms] you can query the "human" name, `min`, `max` and `def` values.

// Set a new parameter value:
autoGain.targetRms.value = newValue;

// Get a new parameter value:
final value = autoGain.targetRms.value;
```
Available parameters: `targetRMS`, `attackTime`, `releaseTime`, `gainSmoothing`, `maxGain`, `minGain`.
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'
platform :ios, '13.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
47 changes: 47 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
PODS:
- Flutter (1.0.0)
- flutter_recorder (0.0.1):
- Flutter
- flutter_soloud (0.0.1):
- Flutter
- open_filex (0.0.2):
- Flutter
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- permission_handler_apple (9.3.0):
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_recorder (from `.symlinks/plugins/flutter_recorder/ios`)
- flutter_soloud (from `.symlinks/plugins/flutter_soloud/ios`)
- open_filex (from `.symlinks/plugins/open_filex/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
flutter_recorder:
:path: ".symlinks/plugins/flutter_recorder/ios"
flutter_soloud:
:path: ".symlinks/plugins/flutter_soloud/ios"
open_filex:
:path: ".symlinks/plugins/open_filex/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
permission_handler_apple:
:path: ".symlinks/plugins/permission_handler_apple/ios"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_recorder: 35999d791bb08147db8b8b8167f8a5e561f68237
flutter_soloud: 12a37f5fb426c94671d762cbb059bbeb1b46ad97
open_filex: 6e26e659846ec990262224a12ef1c528bb4edbe4
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2

PODFILE CHECKSUM: a57f30d18f102dd3ce366b1d62a55ecbef2158e5

COCOAPODS: 1.15.2
Loading
Loading