Improve recorder UI state and logic
This commit is contained in:
parent
c6d31a2e0a
commit
dbe1b913e0
@ -47,14 +47,26 @@ struct MiniRecorderView: View {
|
||||
.padding(.leading, 8)
|
||||
|
||||
Group {
|
||||
if whisperState.isProcessing {
|
||||
StaticVisualizer(color: .white)
|
||||
} else {
|
||||
if whisperState.isEnhancing {
|
||||
Text("Enhancing")
|
||||
.foregroundColor(.white)
|
||||
.font(.system(size: 10, weight: .medium, design: .default))
|
||||
.lineLimit(1)
|
||||
.minimumScaleFactor(0.5)
|
||||
} else if whisperState.isTranscribing {
|
||||
Text("Transcribing")
|
||||
.foregroundColor(.white)
|
||||
.font(.system(size: 10, weight: .medium, design: .default))
|
||||
.lineLimit(1)
|
||||
.minimumScaleFactor(0.5)
|
||||
} else if whisperState.isRecording {
|
||||
AudioVisualizer(
|
||||
audioMeter: recorder.audioMeter,
|
||||
color: .white,
|
||||
isActive: whisperState.isRecording
|
||||
)
|
||||
} else {
|
||||
StaticVisualizer(color: .white)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
@ -91,21 +91,34 @@ struct NotchRecorderView: View {
|
||||
Spacer()
|
||||
|
||||
Group {
|
||||
if whisperState.isProcessing {
|
||||
StaticVisualizer(color: .white)
|
||||
} else {
|
||||
if whisperState.isEnhancing {
|
||||
Text("Enhancing")
|
||||
.foregroundColor(.white)
|
||||
.font(.system(size: 10, weight: .medium, design: .default))
|
||||
.lineLimit(1)
|
||||
.minimumScaleFactor(0.5)
|
||||
} else if whisperState.isTranscribing {
|
||||
Text("Transcribing")
|
||||
.foregroundColor(.white)
|
||||
.font(.system(size: 10, weight: .medium, design: .default))
|
||||
.lineLimit(1)
|
||||
.minimumScaleFactor(0.5)
|
||||
} else if whisperState.isRecording {
|
||||
AudioVisualizer(
|
||||
audioMeter: recorder.audioMeter,
|
||||
color: .white,
|
||||
isActive: whisperState.isRecording
|
||||
)
|
||||
.scaleEffect(y: min(1.0, (menuBarHeight - 8) / 25), anchor: .center)
|
||||
} else {
|
||||
StaticVisualizer(color: .white)
|
||||
.scaleEffect(y: min(1.0, (menuBarHeight - 8) / 25), anchor: .center)
|
||||
}
|
||||
}
|
||||
.scaleEffect(y: min(1.0, (menuBarHeight - 8) / 25), anchor: .center)
|
||||
.frame(width: 30)
|
||||
.frame(width: 70)
|
||||
.padding(.trailing, 8)
|
||||
}
|
||||
.frame(width: 64)
|
||||
.frame(width: 84)
|
||||
.padding(.trailing, 16)
|
||||
}
|
||||
.frame(height: menuBarHeight)
|
||||
|
||||
@ -70,6 +70,7 @@ extension WhisperState {
|
||||
isRecording = false
|
||||
isVisualizerActive = false
|
||||
isProcessing = false
|
||||
isEnhancing = false
|
||||
isTranscribing = false
|
||||
canTranscribe = true
|
||||
isMiniRecorderVisible = false
|
||||
|
||||
@ -21,6 +21,7 @@ class WhisperState: NSObject, ObservableObject {
|
||||
@Published var isProcessing = false
|
||||
@Published var shouldCancelRecording = false
|
||||
@Published var isTranscribing = false
|
||||
@Published var isEnhancing = false
|
||||
@Published var isAutoCopyEnabled: Bool = UserDefaults.standard.object(forKey: "IsAutoCopyEnabled") as? Bool ?? true {
|
||||
didSet {
|
||||
UserDefaults.standard.set(isAutoCopyEnabled, forKey: "IsAutoCopyEnabled")
|
||||
@ -279,6 +280,8 @@ class WhisperState: NSObject, ObservableObject {
|
||||
var text = try await transcriptionService.transcribe(audioURL: url, model: model)
|
||||
let transcriptionDuration = Date().timeIntervalSince(transcriptionStart)
|
||||
|
||||
await MainActor.run { self.isTranscribing = false }
|
||||
|
||||
if await checkCancellationAndCleanup() { return }
|
||||
|
||||
text = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
@ -304,7 +307,13 @@ class WhisperState: NSObject, ObservableObject {
|
||||
do {
|
||||
if await checkCancellationAndCleanup() { return }
|
||||
|
||||
await MainActor.run { self.isEnhancing = true }
|
||||
let textForAI = promptDetectionResult?.processedText ?? text
|
||||
defer {
|
||||
Task { @MainActor in
|
||||
self.isEnhancing = false
|
||||
}
|
||||
}
|
||||
let (enhancedText, enhancementDuration) = try await enhancementService.enhance(textForAI)
|
||||
let newTranscription = Transcription(
|
||||
text: originalText,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user