Fix Force unwrapping serviceRegistry! is risky
This commit is contained in:
parent
5ca848af91
commit
b227fa4b0d
@ -16,7 +16,6 @@ class AudioTranscriptionManager: ObservableObject {
|
|||||||
private var currentTask: Task<Void, Error>?
|
private var currentTask: Task<Void, Error>?
|
||||||
private let audioProcessor = AudioProcessor()
|
private let audioProcessor = AudioProcessor()
|
||||||
private let logger = Logger(subsystem: "com.prakashjoshipax.voiceink", category: "AudioTranscriptionManager")
|
private let logger = Logger(subsystem: "com.prakashjoshipax.voiceink", category: "AudioTranscriptionManager")
|
||||||
private var serviceRegistry: TranscriptionServiceRegistry?
|
|
||||||
|
|
||||||
enum ProcessingPhase {
|
enum ProcessingPhase {
|
||||||
case idle
|
case idle
|
||||||
@ -60,7 +59,7 @@ class AudioTranscriptionManager: ObservableObject {
|
|||||||
throw TranscriptionError.noModelSelected
|
throw TranscriptionError.noModelSelected
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceRegistry = TranscriptionServiceRegistry(whisperState: whisperState, modelsDirectory: whisperState.modelsDirectory)
|
let serviceRegistry = TranscriptionServiceRegistry(whisperState: whisperState, modelsDirectory: whisperState.modelsDirectory)
|
||||||
|
|
||||||
processingPhase = .processingAudio
|
processingPhase = .processingAudio
|
||||||
let samples = try await audioProcessor.processAudioToSamples(url)
|
let samples = try await audioProcessor.processAudioToSamples(url)
|
||||||
@ -80,7 +79,7 @@ class AudioTranscriptionManager: ObservableObject {
|
|||||||
|
|
||||||
processingPhase = .transcribing
|
processingPhase = .transcribing
|
||||||
let transcriptionStart = Date()
|
let transcriptionStart = Date()
|
||||||
var text = try await serviceRegistry!.transcribe(audioURL: permanentURL, model: currentModel)
|
var text = try await serviceRegistry.transcribe(audioURL: permanentURL, model: currentModel)
|
||||||
let transcriptionDuration = Date().timeIntervalSince(transcriptionStart)
|
let transcriptionDuration = Date().timeIntervalSince(transcriptionStart)
|
||||||
text = TranscriptionOutputFilter.filter(text)
|
text = TranscriptionOutputFilter.filter(text)
|
||||||
text = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
text = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user