6.5.6 • Published 4 months ago

fpmk-capacitor-voice-recorder v6.5.6

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Maintainers

MaintainerGitHub
Avihu Harushtchvu3

Installation

npm install --save capacitor-voice-recorder
npx cap sync

Configuration

Using with iOS

Add the following to your Info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>This app uses the microphone to record audio.</string>

Supported methods

NameAndroidiOSWeb
canDeviceVoiceRecord
requestAudioRecordingPermission
hasAudioRecordingPermission
startRecording
stopRecording
pauseRecording
resumeRecording
getCurrentStatus

Overview

The capacitor-voice-recorder plugin allows you to record audio on Android, iOS, and Web platforms. Below is a summary of the key methods and how to use them.

Checking Device Capabilities and Permissions

canDeviceVoiceRecord

Check if the device/browser can record audio.

VoiceRecorder.canDeviceVoiceRecord().then((result: GenericResponse) => console.log(result.value));
Return ValueDescription
{ value: true }The device/browser can record audio.
{ value: false }The browser cannot record audio. Note: On mobile, it always returns { value: true }.

requestAudioRecordingPermission

Request audio recording permission from the user.

VoiceRecorder.requestAudioRecordingPermission().then((result: GenericResponse) => console.log(result.value));
Return ValueDescription
{ value: true }Permission granted.
{ value: false }Permission denied.

hasAudioRecordingPermission

Check if the audio recording permission has been granted.

VoiceRecorder.hasAudioRecordingPermission().then((result: GenericResponse) => console.log(result.value));
Return ValueDescription
{ value: true }Permission granted.
{ value: false }Permission denied.
Error CodeDescription
COULD_NOT_QUERY_PERMISSION_STATUSFailed to query permission status.

Managing Recording

startRecording

Start the audio recording.

VoiceRecorder.startRecording()
    .then((result: GenericResponse) => console.log(result.value))
    .catch(error => console.log(error));
Return ValueDescription
{ value: true }Recording started successfully.
Error CodeDescription
MISSING_PERMISSIONRequired permission is missing.
DEVICE_CANNOT_VOICE_RECORDDevice/browser cannot record audio.
ALREADY_RECORDINGA recording is already in progress.
MICROPHONE_BEING_USEDMicrophone is being used by another app.
FAILED_TO_RECORDUnknown error occurred during recording.

stopRecording

Stops the audio recording and returns the recording data.

VoiceRecorder.stopRecording()
    .then((result: RecordingData) => console.log(result.value))
    .catch(error => console.log(error));
Return ValueDescription
recordDataBase64The recorded audio data in Base64 format.
msDurationThe duration of the recording in milliseconds.
mimeTypeThe MIME type of the recorded audio.
Error CodeDescription
RECORDING_HAS_NOT_STARTEDNo recording in progress.
EMPTY_RECORDINGRecording stopped immediately after starting.
FAILED_TO_FETCH_RECORDINGUnknown error occurred while fetching the recording.

pauseRecording

Pause the ongoing audio recording.

VoiceRecorder.pauseRecording()
    .then((result: GenericResponse) => console.log(result.value))
    .catch(error => console.log(error));
Return ValueDescription
{ value: true }Recording paused successfully.
{ value: false }Recording is already paused.
Error CodeDescription
RECORDING_HAS_NOT_STARTEDNo recording in progress.
NOT_SUPPORTED_OS_VERSIONOperation not supported on the current OS version.

resumeRecording

Resumes a paused audio recording.

VoiceRecorder.resumeRecording()
    .then((result: GenericResponse) => console.log(result.value))
    .catch(error => console.log(error));
Return ValueDescription
{ value: true }Recording resumed successfully.
{ value: false }Recording is already running.
Error CodeDescription
RECORDING_HAS_NOT_STARTEDNo recording in progress.
NOT_SUPPORTED_OS_VERSIONOperation not supported on the current OS version.

getCurrentStatus

Retrieves the current status of the recorder.

VoiceRecorder.getCurrentStatus()
    .then((result: CurrentRecordingStatus) => console.log(result.status))
    .catch(error => console.log(error));
Status CodeDescription
NONEPlugin is idle and waiting to start a new recording.
RECORDINGPlugin is currently recording.
PAUSEDRecording is paused.

Format and Mime type

The plugin will return the recording in one of several possible formats. The format is dependent on the os / web browser that the user uses. On android and ios the mime type will be audio/aac, while on chrome and firefox it will be audio/webm;codecs=opus and on safari it will be audio/mp4. Note that these three browsers have been tested on. The plugin should still work on other browsers, as there is a list of mime types that the plugin checks against the user's browser.

Note that this fact might cause unexpected behavior in case you'll try to play recordings between several devices or browsers—as they do not all support the same set of audio formats. It is recommended to convert the recordings to a format that all your target devices support. As this plugin focuses on the recording aspect, it does not provide any conversion between formats.

Playback

To play the recorded file, you can use plain JavaScript:

const base64Sound = '...' // from plugin
const mimeType = '...'  // from plugin
const audioRef = new Audio(`data:${mimeType};base64,${base64Sound}`)
audioRef.oncanplaythrough = () => audioRef.play()
audioRef.load()

Compatibility

Versioning follows Capacitor versioning. Major versions of the plugin are compatible with major versions of Capacitor. You can find each version in its own dedicated branch.

Plugin VersionCapacitor VersionBranch
5.*5v5
6.*6master

Donation

If you enjoy my work and find it useful, feel free to invite me to a cup of coffee :)

"Buy Me A Coffee"

License

This project is licensed under the MIT License - see the LICENSE file for details.

Credit

Thanks to independo-gmbh for the readme update.

6.5.6

4 months ago

6.5.0

5 months ago

6.4.5

5 months ago

6.4.4

5 months ago

6.4.7

5 months ago

6.4.6

5 months ago

6.4.9

5 months ago

6.4.8

5 months ago

6.5.2

5 months ago

6.5.1

5 months ago

6.5.4

5 months ago

6.5.3

5 months ago

6.5.5

5 months ago

6.4.3

5 months ago

6.3.0

6 months ago

6.4.1

6 months ago

6.3.2

6 months ago

6.4.0

6 months ago

6.3.1

6 months ago

6.3.4

6 months ago

6.4.2

6 months ago

6.3.3

6 months ago

6.3.6

6 months ago

6.3.5

6 months ago

6.3.8

6 months ago

6.2.9

6 months ago

6.3.7

6 months ago

6.2.8

6 months ago

6.3.9

6 months ago

6.2.7

6 months ago

6.2.6

6 months ago

6.2.5

6 months ago

6.2.4

6 months ago

6.2.3

6 months ago

6.2.2

6 months ago

6.2.1

6 months ago

6.2.0

6 months ago

6.1.9

6 months ago

6.1.8

6 months ago

6.1.7

6 months ago

6.1.6

6 months ago

6.1.5

6 months ago

6.1.4

6 months ago

6.1.3

6 months ago

6.1.2

6 months ago

6.1.1

6 months ago

6.1.0

6 months ago

6.0.9

6 months ago

6.0.8

6 months ago

6.0.7

6 months ago

6.0.6

6 months ago

6.0.4

6 months ago