feat: migrate on-device Qwen3 ASR to CoreML for background Flow dictation
Replace MLX GPU inference with CoreML bundles so transcription continues while the host app is backgrounded. Adds model download and warm-up, vendored Qwen3Speech, and updates onboarding, settings, and copy for the ~1.6 GB CoreML package (iOS 18+).
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// UtteranceStreamChunkerTests.swift
|
||||
// OSGKeyboardTests
|
||||
|
||||
import XCTest
|
||||
@testable import OSGKeyboardShared
|
||||
|
||||
final class UtteranceStreamChunkerTests: XCTestCase {
|
||||
|
||||
private let config = FlowUtteranceChunkConfig(
|
||||
maxChunkDurationSeconds: 1,
|
||||
overlapDurationSeconds: 0.1,
|
||||
pauseExtensionMaxSeconds: 0.2,
|
||||
pauseRMSThreshold: 0.02,
|
||||
sampleRate: 1_000
|
||||
)
|
||||
|
||||
func testPauseAwareSplitPrefersSilenceNearWindowEnd() {
|
||||
var buffer = [Float](repeating: 0.2, count: 900)
|
||||
buffer.append(contentsOf: [Float](repeating: 0.001, count: 50))
|
||||
buffer.append(contentsOf: [Float](repeating: 0.2, count: 100))
|
||||
|
||||
let split = UtteranceStreamChunker.pauseAwareSplitIndex(in: buffer, config: config)
|
||||
XCTAssertGreaterThanOrEqual(split, config.maxChunkSamples)
|
||||
XCTAssertLessThanOrEqual(split, config.maxChunkSamples + config.pauseExtensionSamples)
|
||||
}
|
||||
|
||||
func testChunksEmitMultipleSegmentsForLongStream() async {
|
||||
let sampleCount = config.maxChunkSamples * 2 + 100
|
||||
let samples = [Float](repeating: 0.05, count: sampleCount)
|
||||
let (stream, continuation) = AsyncStream<AudioBufferSnapshot>.makeStream()
|
||||
continuation.yield(AudioBufferSnapshot(samples: samples, sampleRate: Double(config.sampleRate)))
|
||||
continuation.finish()
|
||||
|
||||
var received: [UtteranceAudioChunk] = []
|
||||
for await chunk in UtteranceStreamChunker.chunks(from: stream, config: config) {
|
||||
received.append(chunk)
|
||||
}
|
||||
|
||||
XCTAssertGreaterThanOrEqual(received.count, 2)
|
||||
XCTAssertTrue(received.last?.isLast == true)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user