Twilio developer evangelist here.
There's no way to know how long a message will take, but I have another idea.
If you set up your <Say>
message with a <Redirect>
after it, then the user will have heard all the message if the <Redirect>
url receives a request.
<Response>
<Say>This is an important message.</Say>
<Redirect method="POST">https://example.com/results/success</Redirect>
</Response>
Let me know if that helps at all.
Update
So, the above didn't exactly work as Twilio seems to read ahead and load the <Redirect>
URL before the <Say>
has completed. However, we can still use this to help.
In the response to the <Redirect>
URL, we can make Twilio call to another URL somehow. For example, the following TwiML will call out to a URL to fetch a file to <Play>
to the user. Rather than call directly to an mp3 file you can make this call to a server that notes the call got this far and then returns a short, maybe silent, mp3 file. Then we can hangup because we've done what we needed to do.
<Response>
<Play>https://example.com/record_call_complete_and_return_mp3</Play>
<Hangup/>
</Response>
This is a bit of a hack, but it seems to work as the <Play>
URL is only requested when Twilio starts the response to the <Redirect>
.