Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
capacitor-voice-recorder
Advanced tools
tchvu3/capacitor-voice-recorder
Capacitor plugin for simple voice recording (For Capacitor 4)
Maintainer | GitHub |
---|---|
Avihu Harush | tchvu3 |
npm install --save capacitor-voice-recorder
npx cap sync
Make sure to include the NSMicrophoneUsageDescription
key, and a corresponding purpose string in your app's Info.plist
No configuration required for this plugin.
Name | Android | iOS | Web |
---|---|---|---|
canDeviceVoiceRecord | ✅ | ✅ | ✅ |
requestAudioRecordingPermission | ✅ | ✅ | ✅ |
hasAudioRecordingPermission | ✅ | ✅ | ✅ |
startRecording | ✅ | ✅ | ✅ |
stopRecording | ✅ | ✅ | ✅ |
pauseRecording | ✅ | ✅ | ✅ |
resumeRecording | ✅ | ✅ | ✅ |
getCurrentStatus | ✅ | ✅ | ✅ |
{ value: true }
,
while in a browser it will be resolved to { value: true }
/ { value: false }
based on the browser's ability to record.
note that this method does not take into account the permission status,
only if the browser itself is capable of recording at all.{ value: true }
,
otherwise the promise will resolve to { value: true }
/ { value: false }
based on the answer of the user to the request.{ value: true }
/ { value: false }
based on the status of the permission.
please note that the web implementation of this plugin uses the Permissions API under the hood which is not widespread as of now.
as a result, if the status of the permission cannot be checked the promise will reject with COULD_NOT_QUERY_PERMISSION_STATUS
.
in that case you have no choice but to use the requestAudioRecordingPermission
function straight away or startRecording
and capture any exception that is thrown.MISSING_PERMISSION
.
if the current device cannot voice record at all (for example, due to old browser) then the promise will reject with DEVICE_CANNOT_VOICE_RECORD
.
if there's a recording already running then the promise will reject with ALREADY_RECORDING
,
and if other apps are using the microphone then the promise will reject
with MICROPHONE_BEING_USED
. in a case of unknown error the promise will reject with FAILED_TO_RECORD
.startRecording
has not been called beforehand
the promise will reject with RECORDING_HAS_NOT_STARTED
.
if the recording has been stopped immediately after it has been started the promise will reject with EMPTY_RECORDING
.
in a case of unknown error the promise will reject with FAILED_TO_FETCH_RECORDING
.
in case of success, you will get the recording in base-64, the duration of the
recording in milliseconds, and the mime type.RECORDING_HAS_NOT_STARTED
. in case of success the promise will resolve to { value: true }
if the pause
was successful or { value: false }
if the recording is already paused.
note that on certain mobile os versions this function is not supported.
in these cases the function will reject with NOT_SUPPORTED_OS_VERSION
and your only viable options is to stop the recording instead.RECORDING_HAS_NOT_STARTED
. in case of success the promise will resolve to { value: true }
if the resume
was successful or { value: false }
if the recording is already running.
note that on certain mobile os versions this function is not supported.
in these cases the function will reject with NOT_SUPPORTED_OS_VERSION
and your only viable options is to stop the recording instead{ status: "NONE" }
if the plugin is idle and waiting to start a new recording.
{ status: "RECORDING" }
if the plugin is in the middle of recording and { status: "PAUSED" }
if the recording is paused right now.
// only 'VoiceRecorder' is mandatory, the rest is for typing
import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder';
// will print true / false based on the ability of the current device (or web browser) to record audio
VoiceRecorder.canDeviceVoiceRecord().then((result: GenericResponse) => console.log(result.value))
/**
* will prompt the user to give the required permission, after that
* the function will print true / false based on the user response
*/
VoiceRecorder.requestAudioRecordingPermission().then((result: GenericResponse) => console.log(result.value))
/**
* will print true / false based on the status of the recording permission.
* the promise will reject with "COULD_NOT_QUERY_PERMISSION_STATUS"
* if the current device cannot query the current status of the recording permission
*/
VoiceRecorder.hasAudioRecordingPermission.then((result: GenericResponse) => console.log(result.value))
/**
* In case of success the promise will resolve to { value: true }
* in case of an error the promise will reject with one of the following messages:
* "MISSING_PERMISSION", "ALREADY_RECORDING", "MICROPHONE_BEING_USED", "DEVICE_CANNOT_VOICE_RECORD", or "FAILED_TO_RECORD"
*/
VoiceRecorder.startRecording()
.then((result: GenericResponse) => console.log(result.value))
.catch(error => console.log(error))
/**
* In case of success the promise will resolve to:
* {"value": { recordDataBase64: string, msDuration: number, mimeType: string }},
* the file will be in one of several possible formats (more on that later).
* in case of an error the promise will reject with one of the following messages:
* "RECORDING_HAS_NOT_STARTED" or "FAILED_TO_FETCH_RECORDING"
*/
VoiceRecorder.stopRecording()
.then((result: RecordingData) => console.log(result.value))
.catch(error => console.log(error))
/**
* will pause an ongoing recording. note that if the recording has not started yet the promise
* will reject with `RECORDING_HAS_NOT_STARTED`. in case of success the promise will resolve to `{ value: true }` if the pause
* was successful or `{ value: false }` if the recording is already paused.
* if the current mobile os does not support this method the promise will reject with `NOT_SUPPORTED_OS_VERSION`
*/
VoiceRecorder.pauseRecording()
.then((result: GenericResponse) => console.log(result.value))
.catch(error => console.log(error))
/**
* will resume a paused recording. note that if the recording has not started yet the promise
* will reject with `RECORDING_HAS_NOT_STARTED`. in case of success the promise will resolve to `{ value: true }` if the resume
* was successful or `{ value: false }` if the recording is already running.
* if the current mobile os does not support this method the promise will reject with `NOT_SUPPORTED_OS_VERSION`
*/
VoiceRecorder.resumeRecording()
.then((result: GenericResponse) => console.log(result.value))
.catch(error => console.log(error))
/**
* Will return the current status of the plugin.
* in this example one of these possible values will be printed: "NONE" / "RECORDING" / "PAUSED"
*/
VoiceRecorder.getCurrentStatus()
.then((result: CurrentRecordingStatus) => console.log(result.status))
.catch(error => console.log(error))
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 3 browsers has 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 not all support the same set of audio formats. it is recommended to convert the recordings to a format that all your target devices supports. as this plugin focuses on the recording aspect, it does not provide any conversion between formats.
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()
If you enjoy my work and find it useful, feel free to invite me to a cup of coffee :)
FAQs
Capacitor plugin for voice recording
We found that capacitor-voice-recorder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.