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
|
nextBuffer = nil
|
||||||
} else {
|
} else {
|
||||||
do {
|
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)
|
buffer = Self.makePCMBuffer(from: samples)
|
||||||
} catch {
|
} catch {
|
||||||
currentSentenceIndex += 1
|
currentSentenceIndex += 1
|
||||||
@@ -146,7 +149,10 @@ public final class AudioEngine {
|
|||||||
guard nextIdx < sentences.count else { return nil }
|
guard nextIdx < sentences.count else { return nil }
|
||||||
let nextText = sentences[nextIdx].text
|
let nextText = sentences[nextIdx].text
|
||||||
return Task.detached { [synthesizer] in
|
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))
|
return SendableBuffer(buffer: Self.makePCMBuffer(from: samples))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
Reference in New Issue
Block a user