c07cf4db9f
Rolls back the v0.2.0 Qwen3 CoreML on-device ASR stack and replaces the
'local engine' UX with iOS 26 SpeechAnalyzer + DictationTranscriber only.
The 'Cloud polish after ASR' toggle (ProviderConfig.localModeCloudPolishEnabled)
lets users opt into a post-ASR DeepSeek round-trip from the local engine.
Defaults to off so the local engine stays genuinely local. New PolishError.missingAPIError
surfaces an inline 'fill in your key' warning when the toggle is on but the
Keychain is empty. DeepSeek preset default model bumped to deepseek-v4-flash.
Deleted:
- OSGKeyboard/ThirdParty/Qwen3Speech/ (74 files, ~16k LoC)
- OSGKeyboard/Services/ModelManager.swift (492)
- OSGKeyboard/Services/OnDeviceModelWarmup.swift (197)
- OSGKeyboard/Services/Qwen3ASRService.swift (257)
- OSGKeyboard/Services/ModelDownloadSourcePicker.swift (126)
- OSGKeyboard/Views/OnDeviceModelsView.swift (184)
- OSGKeyboard/Views/DownloadConfirmSheet.swift (96)
- OSGKeyboardShared/Models/OnDeviceModel.swift (140)
- OSGKeyboardShared/Services/OnDeviceModelStatus.swift (104)
- Qwen3ASRServiceProvider registration in OSGKeyboardApp
- Qwen3Speech package declaration in project.yml
- 5 .qwen3ASR enum / branch reference sites in HomeView, OnboardingView,
LocalEngineSettingsRows, FlowSessionManager, ASRService, EngineServiceLabel
- Two pre-existing Swift 6 strict-concurrency errors in
LiveDictationController + FlowSessionManager (the weak [weak self] in
detached-task MainActor.run blocks) that were blocking clean builds
Added:
- LocalModelsGroup: 'Built-in iOS SpeechAnalyzer' badge + 'Cloud polish
after ASR' Switch toggle
- PolishingService: honour localModeCloudPolishEnabled; new .missingAPIKey
error case with localised warning
- AppGroupStore.localModeCloudPolishEnabled (mirrored into App Group
so the keyboard extension honours the toggle during live dictation)
- SettingsView: show provider/api sections when local-mode cloud polish
is on so the user can paste a DeepSeek key
- FlowSessionManager: route through PolishingService for local + polish-on
flow; translate missingAPIKey into a polished warning
- KeyboardViewController: handle PolishingService.PolishError.missingAPIKey
in the keyboard-side live polish path
- CHANGELOG v0.2.1: documents the rollback + new toggle
- README.md / README.zh.md: engine matrix section, data flow note
Verified: xcodebuild -scheme OSGKeyboard -destination 'generic/platform=iOS Simulator'
build succeeds under SWIFT_STRICT_CONCURRENCY=complete.
116 lines
3.7 KiB
Swift
116 lines
3.7 KiB
Swift
// ChunkedUtterancePipelineTests.swift
|
|
// OSGKeyboardTests
|
|
|
|
import XCTest
|
|
import os
|
|
@testable import OSGKeyboardShared
|
|
|
|
private struct StubChunkASR: ASRService, @unchecked Sendable {
|
|
let labels: @Sendable ([Float]) -> String
|
|
|
|
func transcribe(
|
|
stream: AsyncStream<AudioBufferSnapshot>,
|
|
locale: Locale
|
|
) -> AsyncStream<ASREvent> {
|
|
AsyncStream { $0.finish() }
|
|
}
|
|
|
|
func cancel() {}
|
|
|
|
func transcribeChunk(samples: [Float], locale: Locale) async -> ASRChunkResult {
|
|
_ = locale
|
|
return .success(labels(samples))
|
|
}
|
|
}
|
|
|
|
final class ChunkedUtterancePipelineTests: XCTestCase {
|
|
|
|
func testPipelineStitchesQueuedChunks() async {
|
|
let config = FlowUtteranceChunkConfig(
|
|
maxChunkDurationSeconds: 0.05,
|
|
overlapDurationSeconds: 0,
|
|
pauseExtensionMaxSeconds: 0,
|
|
pauseRMSThreshold: 0.02,
|
|
sampleRate: 1_000
|
|
)
|
|
let asr = StubChunkASR { samples in
|
|
samples.isEmpty ? "" : "seg\(samples.count)"
|
|
}
|
|
let pipeline = ChunkedUtterancePipeline(
|
|
asr: asr,
|
|
locale: Locale(identifier: "zh-Hans"),
|
|
config: config
|
|
)
|
|
|
|
let (stream, continuation) = AsyncStream<AudioBufferSnapshot>.makeStream()
|
|
continuation.yield(AudioBufferSnapshot(samples: [Float](repeating: 0.1, count: 80), sampleRate: 1_000))
|
|
continuation.yield(AudioBufferSnapshot(samples: [Float](repeating: 0.1, count: 80), sampleRate: 1_000))
|
|
continuation.finish()
|
|
|
|
var partials: [String] = []
|
|
let outcome = await pipeline.transcribe(stream: stream) { partial in
|
|
partials.append(partial)
|
|
}
|
|
|
|
guard case .success(let success) = outcome else {
|
|
return XCTFail("expected success, got \(outcome)")
|
|
}
|
|
XCTAssertTrue(success.text.contains("seg"))
|
|
XCTAssertFalse(partials.isEmpty)
|
|
}
|
|
|
|
func testPipelineDeliversPartialSuccessWhenOneChunkFails() async {
|
|
let config = FlowUtteranceChunkConfig(
|
|
maxChunkDurationSeconds: 0.05,
|
|
overlapDurationSeconds: 0,
|
|
pauseExtensionMaxSeconds: 0,
|
|
pauseRMSThreshold: 0.02,
|
|
sampleRate: 1_000
|
|
)
|
|
let pipeline = ChunkedUtterancePipeline(
|
|
asr: FailingSecondChunkASR(),
|
|
locale: Locale(identifier: "zh-Hans"),
|
|
config: config
|
|
)
|
|
|
|
let (stream, continuation) = AsyncStream<AudioBufferSnapshot>.makeStream()
|
|
continuation.yield(AudioBufferSnapshot(samples: [Float](repeating: 0.1, count: 80), sampleRate: 1_000))
|
|
continuation.yield(AudioBufferSnapshot(samples: [Float](repeating: 0.1, count: 80), sampleRate: 1_000))
|
|
continuation.finish()
|
|
|
|
let outcome = await pipeline.transcribe(stream: stream) { _ in }
|
|
|
|
guard case .success(let success) = outcome else {
|
|
return XCTFail("expected partial success, got \(outcome)")
|
|
}
|
|
XCTAssertFalse(success.text.isEmpty)
|
|
XCTAssertEqual(success.chunkWarnings.count, 1)
|
|
}
|
|
}
|
|
|
|
private struct FailingSecondChunkASR: ASRService, @unchecked Sendable {
|
|
private let lock = OSAllocatedUnfairLock()
|
|
private var index = 0
|
|
|
|
func transcribe(
|
|
stream: AsyncStream<AudioBufferSnapshot>,
|
|
locale: Locale
|
|
) -> AsyncStream<ASREvent> {
|
|
AsyncStream { $0.finish() }
|
|
}
|
|
|
|
func cancel() {}
|
|
|
|
func transcribeChunk(samples: [Float], locale: Locale) async -> ASRChunkResult {
|
|
_ = locale
|
|
let current = lock.withLock {
|
|
defer { index += 1 }
|
|
return index
|
|
}
|
|
if current == 1 {
|
|
return .failure("simulated chunk error")
|
|
}
|
|
return .success("seg\(samples.count)")
|
|
}
|
|
}
|