Skip to main content

Voice Recording Methods

Add voice note functionality with a framework-friendly recorder you fully control. The SDK exposes logic only; you own the UI.

Getting Started (createRecorder)

import { VocaFuseSDK } from '@vocafuse/frontend-sdk'

const sdk = new VocaFuseSDK({ tokenEndpoint: '/api/token' })
await sdk.init()

const recorder = sdk.createRecorder({
maxDuration: 60,
onStateChange: s => console.log('state', s),
onRecordProgress: s => console.log('seconds', s),
onUploadProgress: p => console.log('upload %', p),
onComplete: r => console.log('uploaded', r.voicenote_id),
onError: e => console.error(e)
})

startBtn.onclick = () => recorder.start()
stopBtn.onclick = () => recorder.stop() // auto-uploads by default
cancelBtn.onclick = () => recorder.cancel() // discard and reset to idle

Simple Toggle UI

const btn = document.getElementById('record-btn')!
btn.onclick = async () => {
if (recorder.isRecording) {
await recorder.stop()
btn.textContent = 'Start Recording'
} else {
await recorder.start()
btn.textContent = 'Stop & Upload'
}
}

Cancel Recording

Call cancel() during recording to discard the current take and return to idle. This does not cancel an in-flight upload (after stop()).

cancelBtn.onclick = () => recorder.cancel()

Options and Callbacks

OptionTypeDefaultDescription
maxDurationnumber60Maximum recording duration in seconds
autoUploadbooleantrueIf true, stop() uploads automatically; if false, stop() returns the raw VoicenoteResult
CallbackParametersDescription
onStateChange`(state: 'idle''recording'
onRecordProgress(seconds: number)Elapsed recording time updates
onUploadProgress(percentage: number)Upload progress percentage (0-100)
onComplete(result: UploadResult)Called after successful upload
onCancel()Called when recording is canceled
onError(error: VocaFuseError)Called on errors