I am implementing AVSpeechSynthesizer with this UI in my app:
How can I get the progress from the AVSpeechSynthesizer utterance? I see that there is no delegate method or an API to get the current progress, but is there a workaround to getting the progress?
There are two ways to go here. Both start with setting a delegate
for your AVSpeechSynthesizer
instance.
If you're providing text to the synthesizer by creating and enqueueing several utterances, you can keep track of the utterances you've given it to speak, and implement speechSynthesizer:didFinishSpeechUtterance:
in your delegate to be notified when they're complete. Depending on how long your spoken text is and how many utterances you've broken it into, measuring the number of completed utterances against the total number to be spoken ma provide a decent coarse-grained indication of speech progress.
If you're providing text all in one utterance, or if you're using multiple utterances and want a more fine-grained measure of progress, implement speechSynthesizer:willSpeakRangeOfSpeechString:utterance:
in your delegate. You can observe progress by comparing the range currently being spoken against the length of the speech string.