@deep-foundation/capacitor-voice-recorder

npm Gitpod Discord

Provides links&functions based on capacitor-voice-recorder.

Documentation

List of links

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

  1. Import the library into your TypeScript project:
import Recorder, { createContainer } from "@deep-foundation/capacitor-voice-recorder";
  1. 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.

  1. Getting permissions:

Call getAudioRecordingPermissions method of the Recorder to get audio recording and microphone usage permissions for your app.

const permissionSatus = await Recorder.getAudioRecordingPermissions(); 
  1. 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
});
  1. 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

  1. Import VoiceRecorder react component or hooks:
import { WithVoiceRecorder, VoiceRecorder, useContainer, useRecordingCycle, useRecordingStatus } from "@deep-foundation/capacitor-voice-recorder";
  1. 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>
  1. 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.