MCPcopy Create free account
hub / github.com/TanStack/ai / finalize

Method finalize

packages/ai-client/src/audio-recorder.ts:251–280  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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()

Callers 2

startMethod · 0.95
stopMethod · 0.95

Calls 6

releaseStreamMethod · 0.95
setStateMethod · 0.95
handleErrorMethod · 0.95
arrayBufferToBase64Function · 0.90
nowMethod · 0.80
arrayBufferMethod · 0.80

Tested by

no test coverage detected