feat(asr): [PKG-ASR-09] add explicit capture ownership and cancel stale restarts

This commit is contained in:
Harvey Zhao committed 2026-09-13 16:19:49 +08:00
1 parent 5ab7da6e1f
commit 146b78d576
27 files changed
+12951 -64

No files matched your search

+6 -3
View File
@@ -34,8 +34,11 @@ export class Capture {
restart() {
const active = this.running || Boolean(this.starting)
this.pause()
if (this.graph && !this.graph.ownsMediaConnection)
return this.stop().then(() => active ? this.start() : undefined)
if (this.graph && !this.graph.ownsMediaConnection) {
const stopping = this.stop()
const epoch = this.epoch
return stopping.then(() => active && !this.terminal && this.epoch === epoch ? this.start() : undefined)
}
return active ? this.start() : Promise.resolve()
}
@@ -54,7 +57,7 @@ export class Capture {
const count = Math.floor(sampleRate * interval / 1000)
if (!Number.isSafeInteger(count) || count < 1 || !Number.isFinite(interval) || interval <= 0)
throw new Error('Audio chunk length must be positive and finite')
const graph = this.graph ??= new AudioGraph(this.video, sampleRate)
const graph = this.graph ??= new AudioGraph(this.video, sampleRate, this.options.captureOnly)
await graph.prepare()
if (!current()) {
if (!this.running && this.graph === graph)