chua's picture
Add iOS ASR source and docs
64f7370 verified
Raw
History Blame Contribute Delete
2.32 kB
import Foundation
/// All errors thrown by SpeechKit. Every public API throws only this type.
public enum SpeechError: Error, LocalizedError, Equatable {
// Asset / model loading
case assetBundleNotFound(String)
case assetMissing(String)
case assetCorrupted(name: String, expectedSHA256: String, actualSHA256: String)
case assetSchemaUnsupported(found: Int, supported: ClosedRange<Int>)
case modelCompilationFailed(String)
case modelLoadFailed(String)
// Audio input
case audioTooShort(minimumSeconds: Double)
case audioFormatUnsupported(String)
case resamplingFailed(String)
// Inference
case inferenceFailed(stage: String, underlying: String)
case promptTooLong(tokens: Int, limit: Int)
case cancelled
public var errorDescription: String? {
switch self {
case .assetBundleNotFound(let path):
return "Model asset bundle not found at \(path)"
case .assetMissing(let name):
return "Required asset missing from bundle: \(name)"
case .assetCorrupted(let name, let expected, let actual):
return "Asset \(name) failed integrity check (expected \(expected.prefix(12))..., got \(actual.prefix(12))...)"
case .assetSchemaUnsupported(let found, let supported):
return "Asset schema v\(found) is outside supported range v\(supported.lowerBound)-v\(supported.upperBound); update SpeechKit or the model bundle"
case .modelCompilationFailed(let detail):
return "Core ML model compilation failed: \(detail)"
case .modelLoadFailed(let detail):
return "Model load failed: \(detail)"
case .audioTooShort(let min):
return "Audio shorter than the \(min)s minimum"
case .audioFormatUnsupported(let detail):
return "Unsupported audio format: \(detail)"
case .resamplingFailed(let detail):
return "Audio resampling failed: \(detail)"
case .inferenceFailed(let stage, let underlying):
return "Inference failed at \(stage): \(underlying)"
case .promptTooLong(let tokens, let limit):
return "Prompt of \(tokens) tokens exceeds the decoder limit of \(limit)"
case .cancelled:
return "Operation was cancelled"
}
}
}