Skip to content

Commit 2a578dd

Browse files
ZhaoChaoqunclaude
andcommitted
fix: address code review feedback from PR #13 and #15
- Add thread-safety doc comments to AudioEngineManager callbacks (onSamples/onAudioLevel must be set before start()) - Remove unused termNormalizer field from ASREngineFactory.Result - Remove dead destDir assignment in ModelDownloader delegate method Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 77c70ad commit 2a578dd

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

Sources/ASREngineFactory.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ private let logger = Logger(subsystem: "com.typeless.app", category: "ASREngineF
1414
/// no other code touches them during initialization (FSM is in `.initializing` state).
1515
enum ASREngineFactory {
1616

17-
/// Result of engine creation, containing the engine and a TermNormalizer.
17+
/// Result of engine creation.
1818
struct Result {
1919
let engine: (any ASREngine)?
20-
let termNormalizer: TermNormalizer?
2120
}
2221

2322
/// Creates an ASR engine for the given model type, also loading supporting models
@@ -27,7 +26,7 @@ enum ASREngineFactory {
2726
/// - modelType: Which ASR model to load.
2827
/// - pipeline: The post-processing pipeline to configure with supporting models.
2928
/// - recognitionQueue: The serial queue used by the ASR engine for decoding.
30-
/// - Returns: The created ASR engine (nil on failure) and TermNormalizer.
29+
/// - Returns: The created ASR engine (nil on failure).
3130
static func createEngine(
3231
for modelType: ASRModelType,
3332
pipeline: PostProcessingPipeline,
@@ -58,7 +57,7 @@ enum ASREngineFactory {
5857
}
5958
pipeline.termNormalizer = termNormalizer
6059

61-
return Result(engine: engine, termNormalizer: termNormalizer)
60+
return Result(engine: engine)
6261
}
6362

6463
// MARK: - Streaming Paraformer

Sources/AudioEngineManager.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ final class AudioEngineManager {
1414

1515
/// Callback invoked with 16kHz Float32 mono samples from the microphone.
1616
/// Called on a Core Audio thread — callers must dispatch to appropriate queues.
17+
///
18+
/// Must be set before `start()` is called. Do not mutate while the engine is running.
19+
/// Read from the Core Audio tap thread; writes must happen before the engine starts.
1720
var onSamples: (([Float]) -> Void)?
1821

1922
/// Callback invoked with normalized audio level (0.0–1.0).
2023
/// Called on the main queue.
24+
///
25+
/// Must be set before `start()` is called. Do not mutate while the engine is running.
26+
/// Read from the Core Audio tap thread; writes must happen before the engine starts.
2127
var onAudioLevel: ((Float) -> Void)?
2228

2329
private var audioEngine: AVAudioEngine?

Sources/ModelDownloader.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,10 @@ extension ModelDownloader: URLSessionDownloadDelegate {
465465
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
466466
progressCallback?("正在解压模型...")
467467

468-
let destDir = (extractionHandler != nil) ? location : location // location is temp file
469468
// Use the extraction handler injected by SherpaOnnxManager
470469
if let handler = extractionHandler {
471-
// We need the modelsDirectory — get it via the manager's pathResolver
472-
// The handler closure captures the destination directory
470+
// The second parameter is unused — the handler closure captures its
471+
// destination directory, so we pass an empty URL for API compatibility.
473472
let result = handler(location, URL(fileURLWithPath: ""))
474473
if result {
475474
completionCallback?(true, nil)

0 commit comments

Comments
 (0)