Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Sources/Fluid/Services/ASRService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ private actor ModelDownloadRegistry {
final class ASRService: ObservableObject {
@Published var isRunning: Bool = false
@Published var finalText: String = ""
@Published var partialTranscription: String = ""
// Not @Published: writes fire 1-5x/s during streaming ASR. Routing them through
// objectWillChange invalidates every ContentView subscriber of AppServices, even
// though ContentView never reads this value. MenuBarManager subscribes directly.
private let partialTranscriptionSubject = CurrentValueSubject<String, Never>("")
var partialTranscription: String { self.partialTranscriptionSubject.value }
var partialTranscriptionPublisher: AnyPublisher<String, Never> {
self.partialTranscriptionSubject.eraseToAnyPublisher()
}
@Published var wordBoostStatusText: String = "Word boost: off"
@Published var micStatus: AVAuthorizationStatus = .notDetermined
@Published var isAsrReady: Bool = false
Expand Down Expand Up @@ -749,7 +756,7 @@ final class ASRService: ObservableObject {
DebugLogger.shared.debug("🧹 Clearing buffers and state", source: "ASRService")
self.finalText.removeAll()
self.audioBuffer.clear(keepingCapacity: true) // specific optimization for restart
self.partialTranscription.removeAll()
self.partialTranscriptionSubject.send("")
self.previousFullTranscription.removeAll()
self.lastBoostHitTerm = nil
self.lastProcessedSampleCount = 0
Expand Down Expand Up @@ -1080,7 +1087,7 @@ final class ASRService: ObservableObject {

// NOW it's safe to clear the buffer
self.audioBuffer.clear()
self.partialTranscription.removeAll()
self.partialTranscriptionSubject.send("")
self.previousFullTranscription.removeAll()
self.lastBoostHitTerm = nil
self.lastProcessedSampleCount = 0
Expand Down Expand Up @@ -2478,7 +2485,7 @@ final class ASRService: ObservableObject {
if !newText.isEmpty {
// Smart diff: only show truly new words
let updatedText = self.smartDiffUpdate(previous: self.previousFullTranscription, current: newText)
self.partialTranscription = updatedText
self.partialTranscriptionSubject.send(updatedText)
self.previousFullTranscription = newText

DebugLogger.shared.debug("✅ Streaming: '\(updatedText)' (\(String(format: "%.2f", duration))s)", source: "ASRService")
Expand Down
2 changes: 1 addition & 1 deletion Sources/Fluid/Services/MenuBarManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class MenuBarManager: NSObject, ObservableObject, NSMenuDelegate {
.store(in: &self.cancellables)

// Subscribe to partial transcription updates for streaming preview
asrService.$partialTranscription
asrService.partialTranscriptionPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] newText in
guard self != nil else { return }
Expand Down
Loading