Skip to content

Commit f7fe018

Browse files
committed
Attempt to fix negative count not allowed error
1 parent 34e7221 commit f7fe018

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/yap/Transcribe.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import Speech
5353
attributeOptions: outputFormat.needsAudioTimeRange ? [.audioTimeRange] : []
5454
)
5555
let modules: [any SpeechModule] = [transcriber]
56-
5756
let installed = await Set(SpeechTranscriber.installedLocales)
5857
if !installed.map({ $0.identifier(.bcp47) }).contains(locale.identifier(.bcp47)) {
5958
if let request = try await AssetInventory.assetInstallationRequest(supporting: modules) {
@@ -98,9 +97,10 @@ import Speech
9897
await MainActor.run {
9998
transcript += result.text
10099
}
101-
let progress = result.resultsFinalizationTime.seconds / audioFileDuration
100+
let progress = max(min(result.resultsFinalizationTime.seconds / audioFileDuration, 1), 0)
102101
var percent = progress.formatted(.percent.precision(.fractionLength(0)))
103-
percent = String(String(repeating: " ", count: 4 - percent.count)) + percent
102+
var oneHundredPercent = 1.0.formatted(.percent.precision(.fractionLength(0)))
103+
percent = String(String(repeating: " ", count: max(oneHundredPercent.count - percent.count, 0))) + percent
104104
let message = "[\(percent)] \(String(result.text.characters).trimmingCharacters(in: .whitespaces).prefix(terminalColumns - 9))"
105105
progressHandler(message)
106106
}

0 commit comments

Comments
 (0)