@capawesome-team/capacitor-audio-recorder¶
Capacitor plugin for seamless audio recording using the device's microphone. Supports Android, iOS, and Web with advanced features and high performance.
Features¶
We are proud to offer one of the most complete and feature-rich Capacitor plugins for audio recording. Here are some of the key features:
- 🖥️ Cross-platform: Supports Android, iOS and Web.
- ⏯️ Full Control: Start, pause, resume, cancel and stop recording.
- 🚀 Performance: Record long audio sessions without any performance issues.
- 🔑 Permissions: Check and request microphone permissions.
- 🔊 Events: Listen for events like
recordingError
,recordingPaused
orrecordingStopped
. - 🤝 Compatibility: Compatible with the Speech Recognition, Speech Synthesis and Native Audio plugin.
- 📦 SPM: Supports Swift Package Manager for iOS.
- 🔁 Up-to-date: Always supports the latest Capacitor version.
- ⭐️ Support: Priority support from the Capawesome Team.
Missing a feature? Just open an issue and we'll take a look!
Compatibility¶
Plugin Version | Capacitor Version | Status |
---|---|---|
7.x.x | >=7.x.x | Active support |
Installation¶
This plugin is only available to Capawesome Insiders. First, make sure you have the Capawesome npm registry set up. You can do this by running the following commands:
npm config set @capawesome-team:registry https://npm.registry.capawesome.io
npm config set //npm.registry.capawesome.io/:_authToken <YOUR_LICENSE_KEY>
Attention: Replace <YOUR_LICENSE_KEY>
with the license key you received from Polar. If you don't have a license key yet, you can get one by becoming a Capawesome Insider.
Next, install the package:
Android¶
Proguard¶
If you are using Proguard, you need to add the following rules to your proguard-rules.pro
file:
iOS¶
Privacy Descriptions¶
Add the NSMicrophoneUsageDescription
key to the ios/App/App/Info.plist
file, which tells the user why your app needs access to the user's contacts:
<key>NSMicrophoneUsageDescription</key>
<string>We need access to your microphone to record audio.</string>
Configuration¶
No configuration required for this plugin.
Usage¶
import { AudioRecorder } from '@capawesome-team/capacitor-audio-recorder';
import { NativeAudio } from '@capacitor-community/native-audio';
const cancelRecording = async () => {
await AudioRecorder.cancelRecording();
};
const getRecordingStatus = async () => {
const { status } = await AudioRecorder.getRecordingStatus();
console.log('Recording status:', status);
};
const pauseRecording = async () => {
await AudioRecorder.pauseRecording();
};
const resumeRecording = async () => {
await AudioRecorder.resumeRecording();
};
const startRecording = async () => {
await AudioRecorder.startRecording();
};
const stopRecording = async () => {
// Stop recording and get the audio blob or URI
const { blob, uri } = await AudioRecorder.stopRecording();
// Play the audio
if (blob) {
// Only available on Web
const audio = new Audio();
audio.src = URL.createObjectURL(blob);
audio.play();
} else if (uri) {
// Only available on Android and iOS
await NativeAudio.preload({
assetId: 'recording',
assetPath: uri,
isUrl: true,
});
await NativeAudio.play({ assetId: 'recording' });
}
};
const checkPermissions = async () => {
const { recordAudio } = await AudioRecorder.checkPermissions();
console.log('Record audio permission:', recordAudio);
};
const requestPermissions = async () => {
const { recordAudio } = await AudioRecorder.requestPermissions();
console.log('Record audio permission:', recordAudio);
};
const addRecordingErrorListener = async () => {
await AudioRecorder.addListener('recordingError', (event) => {
console.error('Recording error:', event.message);
});
};
const addRecordingPausedListener = async () => {
await AudioRecorder.addListener('recordingPaused', () => {
console.log('Recording paused');
});
};
const addRecordingStoppedListener = async () => {
await AudioRecorder.addListener('recordingStopped', (event) => {
console.log('Recording stopped:', event.uri);
});
};
API¶
cancelRecording()
getRecordingStatus()
pauseRecording()
resumeRecording()
startRecording(...)
stopRecording()
checkPermissions()
requestPermissions()
addListener('recordingError', ...)
addListener('recordingPaused', ...)
addListener('recordingStopped', ...)
- Interfaces
- Type Aliases
- Enums
cancelRecording()¶
Cancel the recording.
Since: 7.0.0
getRecordingStatus()¶
Check if the device supports audio recording.
Returns: Promise<GetRecordingStatusResult>
Since: 7.0.0
pauseRecording()¶
Pause the recording.
This method is only available on Android (SDK 24+), iOS and Web.
Since: 7.0.0
resumeRecording()¶
Resume the recording.
This method is only available on Android (SDK 24+), iOS and Web.
Since: 7.0.0
startRecording(...)¶
Start recording audio in AAC format.
Param | Type |
---|---|
options |
StartRecordingOptions |
Since: 7.0.0
stopRecording()¶
Stop recording audio.
Returns: Promise<StopRecordingResult>
Since: 7.0.0
checkPermissions()¶
Check permissions for audio recording.
Returns: Promise<PermissionStatus>
Since: 7.0.0
requestPermissions()¶
Request permissions for audio recording.
Returns: Promise<PermissionStatus>
Since: 7.0.0
addListener('recordingError', ...)¶
addListener(eventName: 'recordingError', listenerFunc: (event: RecordingErrorEvent) => void) => Promise<PluginListenerHandle>
Called when an error occurs during recording. The recording will be cancelled.
Only available on iOS.
Param | Type |
---|---|
eventName |
'recordingError' |
listenerFunc |
(event: RecordingErrorEvent) => void |
Returns: Promise<PluginListenerHandle>
Since: 7.0.0
addListener('recordingPaused', ...)¶
addListener(eventName: 'recordingPaused', listenerFunc: () => void) => Promise<PluginListenerHandle>
Called when the recording is paused (e.g. when the recording is interrupted by a phone call).
Param | Type |
---|---|
eventName |
'recordingPaused' |
listenerFunc |
() => void |
Returns: Promise<PluginListenerHandle>
Since: 7.1.0
addListener('recordingStopped', ...)¶
addListener(eventName: 'recordingStopped', listenerFunc: (event: RecordingStoppedEvent) => void) => Promise<PluginListenerHandle>
Called when the recording is stopped.
Note: This will not be called if the recording is cancelled or paused or if an error occurs.
Param | Type |
---|---|
eventName |
'recordingStopped' |
listenerFunc |
(event: RecordingStoppedEvent) => void |
Returns: Promise<PluginListenerHandle>
Since: 6.0.0
Interfaces¶
GetRecordingStatusResult¶
Prop | Type | Description | Default | Since |
---|---|---|---|---|
status |
RecordingStatus |
The current recording status. | RecordingStatus.Inactive |
7.0.0 |
StartRecordingOptions¶
Prop | Type | Description | Default | Since |
---|---|---|---|---|
bitRate |
number |
The audio bitrate in bytes per second. This option is only available on Android and iOS. | 192000 |
7.2.0 |
sampleRate |
number |
The audio sample rate in Hz. This option is only available on Android and iOS. | 44100 |
7.1.0 |
StopRecordingResult¶
Prop | Type | Description | Since |
---|---|---|---|
blob |
Blob |
The recorded audio as a Blob. Only available on Web. | 7.0.0 |
duration |
number |
The duration of the recorded audio in milliseconds. | 7.1.0 |
uri |
string |
The URI of the recorded audio. Only available on Android and iOS. | 7.0.0 |
PermissionStatus¶
Prop | Type | Description | Since |
---|---|---|---|
recordAudio |
PermissionState |
The permission state for audio recording. | 7.0.0 |
PluginListenerHandle¶
Prop | Type |
---|---|
remove |
() => Promise<void> |
RecordingErrorEvent¶
Prop | Type | Description | Since |
---|---|---|---|
message |
string |
The error message. | 7.0.0 |
RecordingStoppedEvent¶
Prop | Type | Description | Since |
---|---|---|---|
blob |
Blob |
The recorded audio as a Blob. Only available on Web. | 7.0.0 |
duration |
number |
The duration of the recorded audio in milliseconds. | 7.1.0 |
uri |
string |
The URI of the recorded audio. Only available on Android and iOS. | 7.0.0 |
Type Aliases¶
PermissionState¶
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
Enums¶
RecordingStatus¶
Members | Value | Description | Since |
---|---|---|---|
Inactive |
'INACTIVE' |
The recording is inactive. | 7.0.0 |
Recording |
'RECORDING' |
The recording is active. | 7.0.0 |
Paused |
'PAUSED' |
The recording is paused. | 7.0.0 |
Changelog¶
See CHANGELOG.md.
Breaking Changes¶
See BREAKING.md.
License¶
See LICENSE.