From 60fef9c75b44ab3a1bebb7577ef83d99737f74d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20F=C3=B6rtsch?= Date: Sat, 14 Mar 2026 05:24:40 +0100 Subject: [PATCH] wrap synthesis in autoreleasepool, clear MLX cache after each sentence Co-Authored-By: Claude Sonnet 4.6 --- VorleserKit/Sources/AudioEngine/AudioEngine.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/VorleserKit/Sources/AudioEngine/AudioEngine.swift b/VorleserKit/Sources/AudioEngine/AudioEngine.swift index ae84a4a..889934b 100644 --- a/VorleserKit/Sources/AudioEngine/AudioEngine.swift +++ b/VorleserKit/Sources/AudioEngine/AudioEngine.swift @@ -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)) } }()