@deep-foundation/capacitor-voice-recorder
v1.2.7-dev.28
Published
[![npm](https://img.shields.io/npm/v/@deep-foundation/capacitor-voice-recorder.svg)](https://www.npmjs.com/package/@deep-foundation/capacitor-voice-recorder) [![Gitpod](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod
Downloads
28
Readme
Provides links&functions based on capacitor-voice-recorder
.
AudioRecords
The AudioRecords
link serves as a container for link structures representing records inside deep.
Sound
The Sound
link represents recorded data as base64 string.
All links of type Sound can be played with left click.
capacitor-voice-recorder provides only MIME/type as audio prop and it gets stored as link.
All new links of type Sound will be parced with async handler inside Sound package using music-metadata npm library. Useful data will be stored as a prop links inside Sound link. Make sure to give permissions to Sound package with Join link.
Prerequisitions
- Install this package in your deep by using npm-packager
- Provide permissions to this package and its dependencies.
Usage
- Import the library into your TypeScript project:
import Recorder, { createContainer } from "@deep-foundation/capacitor-voice-recorder";
- Create container link of type "AudioRecords" to store Recorder data:
const containerLinkId = await createContainer(deep);
You can also create it manually inside your deepcase client. Open Insert menu, search for and then insert "AudioRecords" type link.
- Getting permissions:
Call getAudioRecordingPermissions method of the Recorder to get audio recording and microphone usage permissions for your app.
const permissionSatus = await Recorder.getAudioRecordingPermissions();
- Recording Audio:
Start recording audio and return the playback status.
const isrecording = await Recorder.startRecording();
Pause the ongoing recording and return the playback status.
const ispaused = await Recorder.pauseRecording();;
Resume the ongoing recording and return the playback status.
const isresumed = await Recorder.resumeRecording();
Stop the ongoing recording, upload the recorded sound, and return the recorded sound with info.
const { recordDataBase64, msDuration, mimeType } = await Recorder.stopRecording({
deep, // The DeepClient object
containerLinkId, // The ID of the container link
});
- Download records from deep database:
Download all existing records made by this recorder as array of IRecord
records.
const records = Recorder.downloadRecords(deep);
React Usage
- Import VoiceRecorder react component or hooks:
import { WithVoiceRecorder, VoiceRecorder, useContainer, useRecordingCycle, useRecordingStatus } from "@deep-foundation/capacitor-voice-recorder";
- Create VoiceRecorder component instance inside your deep app and pass a DeepClient instance.
<VoiceRecorder deep={deep} />
You will see basic ui with all package functionality.
Alternatively you can use WithVoiceRecorder Component like that:
<WithVoiceRecorder deep={yourDeepInstance} containerLinkId={yourContainerLinkId}>
<VoiceRecorder />
</WithVoiceRecorder>
- Custom hooks can be used anywhere in your deep app:
useContainer hook to get existing or create a new container link ID.
const containerLinkId = useContainer(deep);
useRecordingStatus hook to get audio recording status every second (by default).
const audioRecordingStatus = useRecordingStatus({intervalInMs?});
useRecordingCycle hook to fire the recording cycle. Recording cycle records audiochunks of a given duration and uploads them as a links structure inside deep database.
const sounds = useRecordingCycle({ deep, recording, containerLinkId, duration: 5000 });
Contribution
Feel free to contribute. Please fork the repository and submit a pull request for any bugs, improvements, or features.