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'
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.recording_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
| Option | Type | Default | Description |
|---|---|---|---|
maxDuration | number | 60 | Maximum recording duration in seconds |
autoUpload | boolean | true | If true, stop() uploads automatically; if false, stop() returns the raw RecordingResult |
| Callback | Parameters | Description |
|---|---|---|
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 |