Skip to content

Commit

Permalink
chore: Merge branch 'v5'
Browse files Browse the repository at this point in the history
# Conflicts:
#	record_web/lib/audio_context.dart
#	record_web/lib/record_web.dart
#	record_web/pubspec.lock
#	record_web/pubspec.yaml
  • Loading branch information
llfbandit committed Jun 5, 2023
2 parents dff3573 + aa4b2d9 commit f7d03a7
Show file tree
Hide file tree
Showing 242 changed files with 6,636 additions and 6,407 deletions.
1 change: 1 addition & 0 deletions README.md
29 changes: 29 additions & 0 deletions record/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
## 5.0.0-dev1
**Testers needed to reach release !**
***

* Chore:
* Massively reworked platform implementations.
* Android now uses MediaCodec. Package is now written with kotlin (well...).
* iOS, macOS code now shares almost the same codebase. Unified under record_darwin package.
* Windows now uses MediaFoundation shipped with all 10 & 11 versions (no more fmedia executable, yeah! Even if do appreciate the work of stsaz).

* Features:
* feat: Add multiple instance support.
* feat: Add PCM streaming feature & AAC on Android only (for now).
* feat: Add auto gain control, noise suppressor and echo cancellation where available.
* feat: Add amplitude on web.
* feat: Add best effort to adjust sample and bit rates to supported values (Android, iOS, macOS).
* feat: Add cancel() to stop and remove the file if any.

* Fix:
* iOS: Should pause/resume recording when interrupted by the system.

* Breaking changes:
* BREAK: `Record` has been renamed to `AudioRecorder` to avoid confusion with dart v3.
* BREAK: path is now required on all IO platforms. Set an empty String on web platform.
There no more temp file generation.
* BREAK: `start` and `startStream` method parameters are now wrapped in `RecordConfig` object.
* BREAK: `samplingRate` has been renamed to `sampleRate`.
* BREAK: vorbis support has been removed. Too few underlying support.

## 4.4.4
* chore: Update linter rules.
* chore: Update dependencies.
Expand Down
172 changes: 79 additions & 93 deletions record/README.md
Original file line number Diff line number Diff line change
@@ -1,125 +1,111 @@
Audio recorder from microphone to a given file path.
Audio recorder from microphone to a given file path or stream.

No external dependencies:

- On Android, MediaRecorder is used.
- On iOS, AVAudioRecorder is used.
- On macOS, AVCaptureSession is used.
- On web, well... your browser!
- On Android, AudioRecord is used.
- On iOS and macOS, AVCaptureSession is used.
- On Windows, MediaFoundation is used.
- On web, well... your browser! (and its underlying platform).

External dependencies:
- On Windows and linux, encoding is provided by [fmedia](https://stsaz.github.io/fmedia/).
- On linux, fmedia must be installed separately.
- On linux, encoding is provided by [fmedia](https://stsaz.github.io/fmedia/). It **must** be installed separately.

## Options
- bit rate (where applicable)
- sampling rate
- encoder
- Number of channels
- Input device selection
## Platform feature parity matrix
| Feature | Android | iOS | web | Windows | macOS | linux
|------------------|---------------|-----------------|---------|------------|-------|-----------
| pause/resume | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
| amplitude(dBFS) | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| permission check | ✔️ | ✔️ | ✔️ | | ✔️ |
| num of channels | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
| device selection | (auto BT/mic) | (auto BT/mic) | ✔️ | ✔️ | ✔️ | ✔️
| auto gain | ✔️ |(always active?)| ✔️ | | |
| echo suppresion | ✔️ | | ✔️ | | |
| noise suppresion | ✔️ | | ✔️ | | |

## File
| Encoder | Android | iOS | web | Windows | macOS | linux
|-----------------|----------------|---------|---------|---------|---------|---------
| aacLc | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
| aacEld | ✔️ | ✔️ | ? | | ✔️ |
| aacHe | ✔️ | ✔️ | ? | | ✔️ | ✔️
| amrNb | ✔️ | ✔️ | ? | ✔️ | ✔️ |
| amrWb | ✔️ | ✔️ | ? | | ✔️ |
| opus | ✔️ | ✔️ | ? | | ✔️ | ✔️
| wav | ✔️ | | ? | ✔️ | | ✔️
| flac | ✔️ | ✔️ | ? | ✔️ | ✔️ | ✔️
| pcm8bit | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| pcm16bit | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |

## Stream
| Encoder | Android | iOS | web | Windows | macOS | linux
|-----------------|------------|---------|---------|---------|---------|---------
| aacLc * | ✔️ | | | | |
| aacEld * | ✔️ | | | | |
| aacHe * | ✔️ | | | | |
| pcm8bit | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| pcm16bit | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |

\* AAC is streamed with raw AAC with ADTS headers, so it's directly readable through a file.

For every encoder, you should be really careful with given sample/bit rates.
For example, Opus can't be recorded at 44100Hz.

## Usage
```dart
import 'package:record/record.dart';
final record = AudioRecorder();
## Platforms
// Check and request permission if needed
if (await record.hasPermission()) {
// Start recording to file
await record.start(const RecordConfig(), path: 'aFullPath/myFile.m4a');
// Start recording to stream
final stream = await record.startStream(const RecordConfig());
}
// Get the state of the recorder
bool isRecording = await record.isRecording();
// Stop recording...
final path = await record.stop();
// ... or cancel it (and implicitly remove file/blob).
await record.cancel();
record.dispose(); // As always, don't forget this one.
```

## Others

### Android
```xml
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- Optional, you'll have to check this permission by yourself. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
```
- min SDK: 19 (maybe higher => encoder dependent)
* [Audio formats sample rate hints](https://developer.android.com/guide/topics/media/media-formats#audio-formats)

- min SDK: 19 (may be higher depending of the chosen encoder)

### iOS
```xml
<key>NSMicrophoneUsageDescription</key>
<string>We need to access to the microphone to record audio file</string>
<string>Some message to make Apple AppStore rule makers happy</string>
```
- min SDK: 11.0

### macOS
```xml
<key>NSMicrophoneUsageDescription</key>
<string>We need to access to the microphone to record audio file</string>
<string>Some message to make Apple AppStore rule makers happy</string>
```

- In capabilities, activate "Audio input" in debug AND release schemes

- min SDK: 10.15

## Platform feature parity matrix
| Feature | Android | iOS | web | Windows | macOS | linux
|------------------|----------------|-----------------|---------|------------|-------|-----------
| pause/resume | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
| amplitude(dBFS) | ✔️ | ✔️ | | | ✔️ |
| permission check | ✔️ | ✔️ | ✔️ | | ✔️ |
| num of channels | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
| device selection | | (auto BT/mic) | ✔️ | ✔️ | ✔️ | ✔️


| Encoder | Android | iOS | web | Windows | macOS | linux
|-----------------|----------------|---------|---------|---------|---------|---------
| aacLc | ✔️ | ✔️ | ? | ✔️ | ✔️ | ✔️
| aacEld | ✔️ | ✔️ | ? | | ✔️ |
| aacHe | ✔️ | ✔️ | ? | ✔️ | ✔️ | ✔️
| amrNb | ✔️ | ✔️ | ? | | ✔️ |
| amrWb | ✔️ | ✔️ | ? | | ✔️ |
| opus | ✔️ | ✔️ | ? | ✔️ | ✔️ | ✔️
| vorbisOgg | ?(optional) | | ? | ✔️ | | ✔️
| wav | ✔️ | | ? | ✔️ | | ✔️
| flac | | ✔️ | ? | ✔️ | ✔️ | ✔️
| pcm8bit | ✔️ | ✔️ | ? | | ✔️ |
| pcm16bit | ✔️ | ✔️ | ? | | ✔️ |

For every encoder, you should be really careful with given sampling rates.
For example, opus could or could not be recorded at 44100Hz.

If a given encoder is not supported when starting recording on platform, the fallbacks are:

| Platform | encoder
|-------------|--------------------------------------------------------------
| Android | AAC LC
| iOS | AAC LC
| web | OPUS OGG (not guaranteed => choice is made by the browser)
| Windows | AAC LC
| macOS | AAC LC
| linux | AAC LC

## Encoding API levels documentation
### Android
* [MediaRecorder encoding constants](https://developer.android.com/reference/android/media/MediaRecorder.AudioEncoder)
* [Audio formats sample rate hints](https://developer.android.com/guide/topics/media/media-formats#audio-formats)

### iOS
* [AVAudioRecorder encoding constants](https://developer.apple.com/documentation/coreaudiotypes/coreaudiotype_constants/1572096-audio_data_format_identifiers)

## Usage
```dart
// Import package
import 'package:record/record.dart';
final record = Record();
// Check and request permission
if (await record.hasPermission()) {
// Start recording
await record.start(
path: 'aFullPath/myFile.m4a',
encoder: AudioEncoder.aacLc, // by default
bitRate: 128000, // by default
sampleRate: 44100, // by default
);
}
// Get the state of the recorder
bool isRecording = await record.isRecording();
// Stop recording
await record.stop();
```

## Warnings
Be sure to check supported values from the given links above.

## Roadmap
- Allow to choose the capture device.
- Format vs. container accuracy.
- Gain value in config.
- More support of PCM/WAV format.
- AAC / ADTS streaming on more platforms.
- Bug fixes.
Loading

0 comments on commit f7d03a7

Please sign in to comment.