Skip to content
Merged
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ In **Settings → General**, click the shortcut, then press your new key combina
3. Speak, then press the shortcut again. Keep the selected field and cursor unchanged while transcription runs.
4. If insertion cannot be verified or the destination changed, ClearFlow keeps the transcript on the clipboard for manual paste. Check the app’s status for details.

There is no elapsed-time cutoff: recording continues until you finish or cancel. After you finish, longer recordings are transcribed sequentially in parts of at most four minutes and combined into one result. Nothing is uploaded or inserted while you are recording. A word spanning a part boundary may be less accurate. Device interruptions or disk errors can still stop capture and are reported as errors; saved audio can be retried when available. Cancel with the overlay’s ×; pressing the shortcut while processing cancels delivery. Retry returns text for review and never pastes at an old cursor.
There is no elapsed-time cutoff: recording continues until you finish or cancel. After you finish, longer recordings are transcribed sequentially in parts of at most four minutes and combined into one result. Nothing is uploaded or inserted while you are recording. A word spanning a part boundary may be less accurate. Device interruptions or disk errors can still stop capture. A persistent warning appears and ClearFlow attempts to transcribe the available audio into Recent Dictations without pasting at a stale cursor. Low disk space triggers an advance warning; a sudden hardware failure cannot always be predicted. Quitting during capture or transcription asks for confirmation and retains audio.

Transcripts are saved locally **before insertion**, with history enabled by default. Under **Saved Recordings**, choose **Recover** for unfinished audio from an interruption, failed request or previous launch, or **Discard** to delete it. Recovery never automatically pastes. Cancel with the overlay’s × while recording to discard that recording; cancelling while transcribing pauses delivery and keeps the audio. Damaged or unfinalized audio after a crash may not be transcribable, but is retained for inspection or explicit discard.

[Full local setup, custom storage, startup at login, remote Mac and troubleshooting](local-stt/README.md).

Expand All @@ -78,9 +80,9 @@ Deploy the supplied Worker in **your own account**, generate your own secret, an

- The only bundled endpoint is loopback. Audio and vocabulary go only to the address you explicitly configure. No automatic provider fallback.
- Local Whisper holds request audio in memory and does not log audio or transcripts. Setup downloads dependencies/model weights; runtime uses the local model with Hugging Face offline mode.
- Recording uses temporary WAV files, deleted after successful transcription or cancellation. A crash can leave a temporary file. Failed requests retain the temporary recording file for retry until you cancel, start a new recording or quit.
- Audio is stored in ~/Library/Application Support/ClearFlow/Recordings with private file permissions. It is deleted after successful transcription (and history persistence when enabled) or explicit discard. Failed, interrupted or paused requests retain audio across new recordings and app restarts. Review or delete these files under Saved Recordings; no automatic expiry. Existing temporary files from older versions are not imported.
- Field content is read locally to guard insertion and is not uploaded. Known secure fields are rejected.
- History is memory-only by default. Opt-in saved history stores up to 50 transcripts on your Mac. Clipboard fallback leaves the transcript available until replaced.
- Transcript history is saved on this Mac by default, without automatic pruning, in ~/Library/Application Support/ClearFlow/history.json. Existing explicit history-off preferences are respected. Disable it in Settings → Data & privacy and save to remove stored history; ordinary completed dictations then stay in memory only. Interrupted audio remains recoverable until discarded. Clear recent history removes transcripts, not unfinished audio. Clipboard fallback leaves text available until replaced.
- Your endpoint is stored in macOS preferences; the token is stored in Keychain. Keep credentials, recordings, personal endpoints and runtime data out of Git.

## Development
Expand Down
39 changes: 32 additions & 7 deletions Sources/ClearFlow/AudioCapture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ extension AVAudioRecorder: AudioRecording {}

@MainActor final class AudioCapture: NSObject, AVAudioRecorderDelegate {
private var recorder: AudioRecording?
private let directory: URL
private let makeRecorder: (URL, [String: Any]) throws -> AudioRecording
init(makeRecorder: @escaping (URL, [String: Any]) throws -> AudioRecording = { try AVAudioRecorder(url: $0, settings: $1) }) {
init(directory: URL = RecordingStore.directory, makeRecorder: @escaping (URL, [String: Any]) throws -> AudioRecording = { try AVAudioRecorder(url: $0, settings: $1) }) {
self.directory = directory
self.makeRecorder = makeRecorder
super.init()
}
Expand All @@ -30,18 +32,23 @@ extension AVAudioRecorder: AudioRecording {}
return max(0, min(1, (Double(recorder.averagePower(forChannel: 0)) + 55) / 55))
}
func start() throws {
let directory = FileManager.default.temporaryDirectory.appendingPathComponent("ClearFlow", isDirectory: true)
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true,
attributes: [.posixPermissions: 0o700])
let url = directory.appendingPathComponent(UUID().uuidString).appendingPathExtension("wav")
let url = directory.appendingPathComponent(UUID().uuidString).appendingPathExtension("wav").standardizedFileURL
let settings: [String: Any] = [
AVFormatIDKey: kAudioFormatLinearPCM, AVSampleRateKey: 16000,
AVNumberOfChannelsKey: 1, AVLinearPCMBitDepthKey: 16,
AVLinearPCMIsBigEndianKey: false, AVLinearPCMIsFloatKey: false
]
let r = try makeRecorder(url, settings)
r.delegate = self; r.isMeteringEnabled = true
guard r.prepareToRecord(), r.record() else {
guard r.prepareToRecord() else {
try? FileManager.default.removeItem(at: url)
throw AppError.message("The microphone could not prepare. Check your input device.")
}
do { try FileManager.default.setAttributes([.posixPermissions: 0o600], ofItemAtPath: url.path) }
catch { try? FileManager.default.removeItem(at: url); throw error }
guard r.record() else {
try? FileManager.default.removeItem(at: url)
throw AppError.message("The microphone could not start. Check the selected input in System Settings.")
}
Expand Down Expand Up @@ -76,9 +83,27 @@ extension AVAudioRecorder: AudioRecording {}
}
}

/// Owns the temporary recording through transcription and retry; removes it on release.
/// Durable until explicitly discarded or a transcript has been saved successfully.
final class RecordedAudio {
let url: URL
init(url: URL) { self.url = url }
deinit { try? FileManager.default.removeItem(at: url) }
init(url: URL) { self.url = url.standardizedFileURL }
func discard() throws {
if FileManager.default.fileExists(atPath: url.path) { try FileManager.default.removeItem(at: url) }
}
}

enum RecordingStore {
static var directory: URL {
FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
.appendingPathComponent("ClearFlow/Recordings", isDirectory: true)
}
static func recordings(in directory: URL = directory) throws -> [URL] {
guard FileManager.default.fileExists(atPath: directory.path) else { return [] }
return try FileManager.default.contentsOfDirectory(at: directory,
includingPropertiesForKeys: [.creationDateKey, .isRegularFileKey])
.filter { $0.pathExtension == "wav" && (try? $0.resourceValues(forKeys: [.isRegularFileKey]).isRegularFile) == true }
.map { $0.standardizedFileURL }
.sorted { ((try? $0.resourceValues(forKeys: [.creationDateKey]).creationDate) ?? .distantPast)
> ((try? $1.resourceValues(forKeys: [.creationDateKey]).creationDate) ?? .distantPast) }
}
}
17 changes: 14 additions & 3 deletions Sources/ClearFlow/ClearFlowApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import ClearFlowCore
guard let self else { return false }
return self.shortcut.register(value)
}
subscription = model.$mode.combineLatest(model.$status, model.$shortcut).sink { [weak self] _, _, _ in
subscription = model.$mode.combineLatest(model.$status, model.$shortcut, model.$recordingNotice).sink { [weak self] _, _, _, _ in
DispatchQueue.main.async { self?.refresh() }
}
refresh()
Expand All @@ -96,7 +96,9 @@ import ClearFlowCore
startItem.title = action + " " + model.shortcut.display
statusItem.button?.image = NSImage(systemSymbolName: model.mode == .recording ? "mic.fill" : model.mode == .transcribing ? "hourglass" : "waveform",
accessibilityDescription: "ClearFlow")
if model.busy {
if model.busy || !model.recordingNotice.isEmpty {
let fitting = overlay.contentView?.fittingSize ?? NSSize(width: 118, height: 46)
overlay.setContentSize(fitting)
let screen = NSScreen.screens.first { NSMouseInRect(NSEvent.mouseLocation, $0.frame, false) } ?? NSScreen.main
if let screen {
overlay.setFrameOrigin(NSPoint(x: screen.visibleFrame.midX - overlay.frame.width / 2, y: screen.visibleFrame.minY + 34))
Expand Down Expand Up @@ -147,7 +149,16 @@ import ClearFlowCore
window?.makeKeyAndOrderFront(nil)
}
@objc func quit() { NSApp.terminate(nil) }
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
guard model.busy else { return .terminateNow }
let alert = NSAlert()
alert.messageText = model.mode == .recording ? "Recording will end if you quit." : "Transcription is still running."
alert.informativeText = "Your audio will stay saved on this Mac. Reopen ClearFlow and choose Recover to finish the transcript."
alert.addButton(withTitle: "Keep ClearFlow open")
alert.addButton(withTitle: "Quit and keep audio")
return alert.runModal() == .alertSecondButtonReturn ? .terminateNow : .terminateCancel
}
func applicationWillTerminate(_ notification: Notification) {
model.cancel(); shortcut.unregister()
model.prepareForQuit(); shortcut.unregister()
}
}
Loading
Loading