mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-07-31 10:19:38 -04:00
- 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.
23 lines
794 B
TypeScript
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)
|
|
})
|
|
}
|