npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

capacitor-voice-recorder

v6.0.3

Published

Capacitor plugin for voice recording

Downloads

31,276

Readme

Maintainers

| Maintainer | GitHub | |--------------|-------------------------------------| | Avihu Harush | tchvu3 |

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

| Name | Android | iOS | Web | |:--------------------------------|:--------|:----|:----| | 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 Value | Description | |--------------------|----------------------------------------------------------------------------------------| | { 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 Value | Description | |--------------------|---------------------| | { 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 Value | Description | |-------------------------------------|------------------------------------| | { value: true } | Permission granted. | | { value: false } | Permission denied. | | Error Code | Description | | COULD_NOT_QUERY_PERMISSION_STATUS | Failed 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 Value | Description | |-------------------|---------------------------------| | { value: true } | Recording started successfully. |

| Error Code | Description | |------------------------------|------------------------------------------| | MISSING_PERMISSION | Required permission is missing. | | DEVICE_CANNOT_VOICE_RECORD | Device/browser cannot record audio. | | ALREADY_RECORDING | A recording is already in progress. | | MICROPHONE_BEING_USED | Microphone is being used by another app. | | FAILED_TO_RECORD | Unknown 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 Value | Description | |--------------------|------------------------------------------------| | recordDataBase64 | The recorded audio data in Base64 format. | | msDuration | The duration of the recording in milliseconds. | | mimeType | The MIME type of the recorded audio. |

| Error Code | Description | |-----------------------------|------------------------------------------------------| | RECORDING_HAS_NOT_STARTED | No recording in progress. | | EMPTY_RECORDING | Recording stopped immediately after starting. | | FAILED_TO_FETCH_RECORDING | Unknown 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 Value | Description | |--------------------|--------------------------------| | { value: true } | Recording paused successfully. | | { value: false } | Recording is already paused. |

| Error Code | Description | |-----------------------------|----------------------------------------------------| | RECORDING_HAS_NOT_STARTED | No recording in progress. | | NOT_SUPPORTED_OS_VERSION | Operation 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 Value | Description | |--------------------|---------------------------------| | { value: true } | Recording resumed successfully. | | { value: false } | Recording is already running. |

| Error Code | Description | |-----------------------------|----------------------------------------------------| | RECORDING_HAS_NOT_STARTED | No recording in progress. | | NOT_SUPPORTED_OS_VERSION | Operation 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 Code | Description | |-------------|------------------------------------------------------| | NONE | Plugin is idle and waiting to start a new recording. | | RECORDING | Plugin is currently recording. | | PAUSED | Recording 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 Version | Capacitor Version | Branch | |----------------|-------------------|--------| | 5.* | 5 | v5 | | 6.* | 6 | master |

Donation

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

"Buy Me A Coffee"

Credit

Thanks to independo-gmbh for the readme update.