wrap synthesis in autoreleasepool, clear MLX cache after each sentence
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -131,7 +131,10 @@ public final class AudioEngine {
|
||||
nextBuffer = nil
|
||||
} else {
|
||||
do {
|
||||
let samples = try synthesizer.synthesize(text: sentence.text)
|
||||
let samples: [Float] = try autoreleasepool {
|
||||
try synthesizer.synthesize(text: sentence.text)
|
||||
}
|
||||
synthesizer.clearCache()
|
||||
buffer = Self.makePCMBuffer(from: samples)
|
||||
} catch {
|
||||
currentSentenceIndex += 1
|
||||
@@ -146,7 +149,10 @@ public final class AudioEngine {
|
||||
guard nextIdx < sentences.count else { return nil }
|
||||
let nextText = sentences[nextIdx].text
|
||||
return Task.detached { [synthesizer] in
|
||||
guard let samples = try? synthesizer.synthesize(text: nextText) else { return nil }
|
||||
guard let samples: [Float] = try? autoreleasepool(invoking: {
|
||||
try synthesizer.synthesize(text: nextText)
|
||||
}) else { return nil }
|
||||
synthesizer.clearCache()
|
||||
return SendableBuffer(buffer: Self.makePCMBuffer(from: samples))
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user