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: 8 additions & 0 deletions Sources/VocaMac/Models/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,14 @@ final class AppState: ObservableObject {
return
}

guard audioData.contains(where: { abs($0) >= 0.0001 }) else {
cursorOverlay.hide()
let message = "No microphone audio detected. If your MacBook lid is closed, select an external microphone in Settings → Audio."
VocaLogger.warning(.appState, message)
showTemporaryError(message)
return
}

appStatus = .processing

do {
Expand Down
6 changes: 1 addition & 5 deletions Sources/VocaMac/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ struct AudioSettingsTab: View {
Text("\(selectedAudioDeviceDisplayName) (Unavailable)").tag(appState.selectedAudioDeviceID)
}
ForEach(audioDevices) { device in
Text(audioDeviceLabel(for: device)).tag(device.id)
Text(device.name).tag(device.id)
}
}
.onChange(of: appState.selectedAudioDeviceID) { _ in
Expand Down Expand Up @@ -721,10 +721,6 @@ struct AudioSettingsTab: View {
return "VocaMac will follow macOS' system default input."
}

private func audioDeviceLabel(for device: AudioDevice) -> String {
device.isDefault ? "\(device.name) (System Default)" : device.name
}

private func refreshAudioDevices() {
audioDevices = AudioEngine.availableInputDevices()
syncSelectedAudioDeviceName()
Expand Down
14 changes: 14 additions & 0 deletions Tests/VocaMacTests/AppStateRecordingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ final class AppStateRecordingTests: XCTestCase {
"Should return to idle when audio data is empty")
}

func testStopRecordingWithSilentAudioShowsInputError() async {
let (appState, mocks) = AppState.makeTestState()
mocks.audioEngine.stopRecordingResult = Array(repeating: 0, count: 16_000)
appState.isRecording = true
appState.appStatus = .recording

await appState.stopRecordingAndTranscribe()

XCTAssertEqual(appState.appStatus, .error)
XCTAssertTrue(appState.errorMessage?.contains("external microphone") == true)
XCTAssertNil(mocks.whisperService.lastTranscribedAudioData)
XCTAssertEqual(mocks.textInjector.injectCallCount, 0)
}

func testSelectedModelSizeDefault() {
let (appState, _) = AppState.makeTestState()

Expand Down
Loading