58 lines
1.8 KiB
Swift
58 lines
1.8 KiB
Swift
import Foundation
|
|
|
|
struct AssetVerifier {
|
|
struct Result {
|
|
let ok: Bool
|
|
let message: String
|
|
}
|
|
|
|
static func verify() -> Result {
|
|
let bundleRoot = Bundle.main.resourceURL?.path ?? "(unknown)"
|
|
let modelCandidates = [
|
|
"kokoro_duration.mlmodelc",
|
|
"kokoro_decoder_only_3s.mlmodelc",
|
|
"kokoro_duration.mlpackage",
|
|
"kokoro_decoder_only_3s.mlpackage"
|
|
]
|
|
|
|
let voiceName = "am_michael.pt"
|
|
let configName = "config.json"
|
|
|
|
var missing: [String] = []
|
|
|
|
let modelFound = modelCandidates.filter { name in
|
|
Bundle.main.url(forResource: name, withExtension: nil, subdirectory: "Models") != nil ||
|
|
Bundle.main.url(forResource: name, withExtension: nil, subdirectory: nil) != nil
|
|
}
|
|
|
|
if modelFound.isEmpty {
|
|
missing.append("Models or root: kokoro_duration + kokoro_decoder_only_3s")
|
|
}
|
|
|
|
if Bundle.main.url(forResource: voiceName, withExtension: nil, subdirectory: "Voices") == nil,
|
|
Bundle.main.url(forResource: voiceName, withExtension: nil, subdirectory: nil) == nil {
|
|
missing.append("Voices or root: \(voiceName)")
|
|
}
|
|
|
|
if Bundle.main.url(forResource: configName, withExtension: nil, subdirectory: "Config") == nil,
|
|
Bundle.main.url(forResource: configName, withExtension: nil, subdirectory: nil) == nil {
|
|
missing.append("Config or root: \(configName)")
|
|
}
|
|
|
|
if missing.isEmpty {
|
|
return Result(ok: true, message: "All bundled assets found at:\n\(bundleRoot)")
|
|
}
|
|
|
|
return Result(
|
|
ok: false,
|
|
message: """
|
|
Missing assets:
|
|
- \(missing.joined(separator: "\n- "))
|
|
|
|
Bundle resources path:
|
|
\(bundleRoot)
|
|
"""
|
|
)
|
|
}
|
|
}
|