Reputation: 4281
Goal:
Initiate a call and read a dynamic message via text-to-speech.
Problem:
The documentation says:
TwiML is a set of instructions you can use to tell Twilio what to do when you receive an incoming call or SMS.
Is there a solution to do text-to-speech but with me initiating the call?
Thanks!
Upvotes: 3
Views: 1369
Reputation: 64756
If you know the text at the time you trigger an outbound API call, you can set the URL to be an Echo Twimlet, that will say text. This URL:
http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EThis%20is%20an%20example.%3C%2FSay%3E%3C%2FResponse%3E
will result in this TwiML:
<Response>
<Say>This is an example</Say>
</Response>
when fetched by Twilio. In your case you would url-escape the message you wanted to say and insert it in the URL.
If you don't know at the time you make the call, I assume you have the text stored in a database or similar. Then when Twilio makes the request to your server, you retrieve the text from the database and insert it into an XML string. Here is an example in PHP:
<?php
$text = fetch_text_from_db();
header('Content-Type: text/xml');
?>
<Response>
<Say><?php echo htmlentities($text); ?></Say>
</Response>
Upvotes: 1