Skip to content

Commit 0af6b45

Browse files
committed
fix 3 gb ram spike issue
1 parent 657a8e0 commit 0af6b45

1 file changed

Lines changed: 11 additions & 20 deletions

File tree

Sources/FluidAudio/TextToSpeech/Kokoro/Assets/Lexicon/EspeakG2P.swift

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,19 @@ final class EspeakG2P {
6969
}
7070

7171
private static func frameworkBundledDataPath() -> URL? {
72-
// ESpeakNG.xcframework has espeak-ng-data.bundle embedded
73-
guard let frameworkBundle = Bundle(identifier: "com.fluidaudio.ESpeakNG") else {
74-
return nil
75-
}
76-
77-
guard
78-
let bundleURL = frameworkBundle.url(
79-
forResource: "espeak-ng-data",
80-
withExtension: "bundle"
81-
)
82-
else {
83-
return nil
84-
}
85-
86-
let dataDir = bundleURL.appendingPathComponent("espeak-ng-data")
87-
let voicesPath = dataDir.appendingPathComponent("voices")
88-
89-
guard FileManager.default.fileExists(atPath: voicesPath.path) else {
90-
return nil
72+
// Try to find espeak-ng-data.bundle in all loaded bundles
73+
for bundle in Bundle.allBundles {
74+
if let bundleURL = bundle.url(forResource: "espeak-ng-data", withExtension: "bundle") {
75+
let dataDir = bundleURL.appendingPathComponent("espeak-ng-data")
76+
let voicesPath = dataDir.appendingPathComponent("voices")
77+
78+
if FileManager.default.fileExists(atPath: voicesPath.path) {
79+
return dataDir
80+
}
81+
}
9182
}
9283

93-
return dataDir
84+
return nil
9485
}
9586

9687
static func isDataAvailable() -> Bool {

0 commit comments

Comments
 (0)