On IOS, Apple's AVSpeechSynthesizer offer's a write function, as an alternative to the speak() function, which gives you the speech as data (presumably to write the speech output to a file) instead of feeding it to audio.
It doesn't actually write the file itself, but provides a callback that gives you a series of buffers -- segments of the total audio data. These buffers arrive as "AVAudioBuffer" instances. These are (presumably due to no authoritative reference) an abstract type with an unpredictable "actual?" type... and of non-standardized/arbitrary/unpredictable length and format...
... like this:
[your AVSpeechSynthesizer instance].write(utterance) { buffer in
// buffers are repeatedly sent to this callback rapidly >>> in segments, not as a whole <<<
}
Let's say we want to write an async/await function with a signature like this:
func writeSpeech(fromText text: String, toURL url:URL) async throws { ... }
We need to know when the synthesis is finished in order to call continuation.resume() to let the caller know when it's ok to proceed!
How can we determine when AVSpeechSynthesizer's write function is finished -- when the audio buffers have been sent in completion?
There is an explanation in this related question that gives a seemingly current approach... but it is only the latest work-around/guess.
There is also this didFinish AVSpeechSynthesizerDelegate callback that seems to work, but in the documentation is only seemingly intended for use with the speak() function and not the write() function... so it seems simply lucky that it works and that there is no guarantee it will always work.
So, when using AVSpeechSynthesizer.write(), what is the "proper" (hopefully Apple endorsed via documentation) way to detect when the write() process is finished?