()
| 249 | } |
| 250 | |
| 251 | private async finalize(): Promise<void> { |
| 252 | const mimeType = this.recorder?.mimeType || 'audio/webm' |
| 253 | const durationMs = Date.now() - this.startedAt |
| 254 | try { |
| 255 | const blob = new Blob(this.chunks, { type: mimeType }) |
| 256 | const base64 = arrayBufferToBase64(await blob.arrayBuffer()) |
| 257 | const recording: AudioRecording = { |
| 258 | blob, |
| 259 | base64, |
| 260 | mimeType, |
| 261 | durationMs, |
| 262 | part: { |
| 263 | type: 'audio', |
| 264 | source: { type: 'data', value: base64, mimeType }, |
| 265 | }, |
| 266 | } |
| 267 | this.releaseStream() |
| 268 | this.recorder = null |
| 269 | this.chunks = [] |
| 270 | const resolve = this.stopResolve |
| 271 | this.stopResolve = null |
| 272 | this.stopReject = null |
| 273 | this.setState('idle') |
| 274 | resolve?.(recording) |
| 275 | } catch (err) { |
| 276 | this.handleError( |
| 277 | err instanceof Error ? err : new Error('Failed to finalize recording'), |
| 278 | ) |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | private handleError(error: Error): void { |
| 283 | this.releaseStream() |
no test coverage detected