Files
Compass/web/lib/util/blob.ts
MartinBraquet 4c76b643e3 Add voice recording, transcription, and audio player components
- Implemented `AudioPlayer` for custom audio playback controls.
- Added `useAudioRecorder` hook for managing microphone audio recording with visual feedback.
- Introduced audio transcription API integration using OpenAI Whisper.
- Created `blobToBase64` utility to encode recorded blobs for API consumption.
- Added IndexedDB-based `recording-store` for saving in-progress recordings.
- Developed `VoiceAutofillSection` for guided recording, playback, transcription, and editing.
2026-07-25 18:01:58 +02:00

23 lines
794 B
TypeScript

/**
* Base64-encodes a Blob, without the `data:...;base64,` prefix.
*
* FileReader rather than `Buffer`/`btoa`: it streams, so a multi-megabyte audio recording does not
* have to be materialised as a JS string of char codes first.
*/
export function blobToBase64(blob: Blob): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onerror = () => reject(reader.error ?? new Error('Failed to read blob'))
reader.onload = () => {
const result = reader.result
if (typeof result !== 'string') {
reject(new Error('Unexpected FileReader result'))
return
}
const comma = result.indexOf(',')
resolve(comma === -1 ? result : result.slice(comma + 1))
}
reader.readAsDataURL(blob)
})
}