Skip to content

Commit

Permalink
updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tchvu3 committed Nov 13, 2020
1 parent 0228617 commit c7f65fd
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 41 deletions.
113 changes: 73 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,97 @@
# capacitor-voice-recorder
<p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p>
<h3 align="center">Capacitor Voice Recorder</h3>
<p align="center"><strong><code>tchvu3/capacitor-voice-recorder</code></strong></p>
<p align="center">
Capacitor plugin for simple voice recording
</p>

Capacitor plugin for simple voice recording
<p align="center">
<img src="https://img.shields.io/maintenance/yes/2020?style=flat-square" />
<!-- <a href="https://github.com/tchvu3/capacitor-voice-recorder/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/tchvu3/capacitor-voice-recorder/CI?style=flat-square" /></a> -->
<a href="https://www.npmjs.com/package/capacitor-voice-recorder"><img src="https://img.shields.io/npm/l/capacitor-voice-recorder?style=flat-square" /></a>
<br>
<a href="https://www.npmjs.com/package/capacitor-voice-recorder"><img src="https://img.shields.io/npm/dw/capacitor-voice-recorder?style=flat-square" /></a>
<a href="https://www.npmjs.com/package/capacitor-voice-recorder"><img src="https://img.shields.io/npm/v/capacitor-voice-recorder?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-0-orange?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
</p>


## Maintainers

| Maintainer | GitHub | Social |
| -----------| -------| -------|
| Avihu Harush | [tchvu3](https://github.com/tchvu3) | [@tchvu3](https://twitter.com/tchvu3) |


## Installation

## Install
```
npm install --save capacitor-voice-recorder
npx cap sync
```

#### ios note
Make sure to include the ```NSMicrophoneUsageDescription```
key, and a corresponding purpose string in your app's Info.plist

#### android note
Make sure to add the plugin to your MainActivity.java like so:
```
import com.tchvu3.capvoicerecorder.VoiceRecorder;
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
add(VoiceRecorder.class); // Add this line
}});
}
```

## API

| Method | Info | Platform |
| ----------------------------------|:--------------------------------------------------:|:-----------:|
| canDeviceVoiceRecord() | test if the phone can voice record | ios/android |
| requestAudioRecordingPermission() | request the user for permission | ios/android |
| hasAudioRecordingPermission() | test if the user already gave permission to record | ios/android |
| startRecording() | start the recording | ios/android |
| stopRecording() | end the recording | ios/android |
## Configuration

No configuration required for this plugin.

## Deep dive
#### Each function returns Promise

* canDeviceVoiceRecord - return promise that resolves to {"value": true} / {"value": false} based
on the phones ability to record voice (will never throw exception)
## Supported methods

| Name | Android | iOS | Web |
| :------------------------------ | :------ | :-- | :-- |
| canDeviceVoiceRecord ||||
| requestAudioRecordingPermission ||||
| hasAudioRecordingPermission ||||
| startRecording ||||
| stopRecording ||||


## Explanation

* canDeviceVoiceRecord - return promise that resolves to {"value": true} / {"value": false}
based on the phone's ability to record voice.
---
* requestAudioRecordingPermission - if the permission has already been provided
then the promise will resolve with {"value": true}, otherwise the promise will resolve
to {"value": true} / {"value": false} based on the answer of the user to the request
to {"value": true} / {"value": false} based on the answer of the user to the request.
---
* hasAudioRecordingPermission - will resolve to {"value": true} / {"value": false} based on the
status of the permission
status of the permission.
---
* startRecording - if the app lacks the required permission then
the promise will reject with the message "MISSING_PERMISSION".
if the phone is unable to record then the promise will reject
with the message "CANNOT_VOICE_RECORD_ON_THIS_PHONE".
if there's a recording already running then the promise will reject with "ALREADY_RECORDING",
and if the microphone is being used by other app then the promise will reject with "MICROPHONE_BEING_USED".
NOTE: in case of unknown error the promise will reject with "FAILED_TO_RECORD"
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".
---
* stopRecording - will stop the recording that previously started. if the function startRecording()
has not been called beforehand then the promise will reject with: "RECORDING_HAS_NOT_STARTED".
* stopRecording - will stop the recording that has been previously started.
if the function startRecording() has not been called beforehand
the promise will reject with: "RECORDING_HAS_NOT_STARTED".
in case of success, you will get the recording in base-64,
the duration of the recording in milliseconds and the mime type
the duration of the recording in milliseconds, and the mime type.


## Usage

Expand All @@ -52,7 +102,6 @@ import { Plugins } from "@capacitor/core"
// not mandatory, only for code completion
import { RecordingData, GenericResponse } from 'capacitor-voice-recorder'
// without types
const { VoiceRecorder } = Plugins
// will print true / false based on the device ability to record
Expand Down Expand Up @@ -90,6 +139,7 @@ VoiceRecorder.stopRecording()
```

## Playback

To play the recorded file you can use plain
javascript:

Expand All @@ -99,20 +149,3 @@ const audioRef = new Audio(`data:audio/aac;base64,${base64Sound}`)
audioRef.oncanplaythrough = () => audioRef.play()
audioRef.load()
```

## ios note
Make sure to include the NSMicrophoneUsageDescription key
and a corresponding purpose string in your app's Info.plist

## android note
Please make sure to add the plugin in your MainActivity.java like so:
```
import com.tchvu3.capvoicerecorder.VoiceRecorder;
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
add(VoiceRecorder.class); // Add this line
}});
}
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capacitor-voice-recorder",
"version": "0.1.3",
"version": "0.1.4",
"description": "Capacitor plugin for voice recording",
"main": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
Expand Down

0 comments on commit c7f65fd

Please sign in to comment.