Skip to main content

TeXML Quickstart: Simple Text-to-Speech Demo

TeXML is an XML-based data structure you can use to control calls with Telnyx. TeXML is the quickest way to get started with Programmable Voice using a simple .xml file, allowing you to specify call instructions in your file using commands called verbs and nouns. TeXML Translator starts at the top of your TeXML file and executes your TeXML commands sequentially in the order they are arranged in the file.

In this guide, you'll learn how to write a simple text to speech TeXML application using Telnyx Programmable Voice in just five lines of code. Check out our video walkthrough of this tutorial.

Step 1: Setup a Telnyx account, phone number, and TeXML application

This quickstart assumes you've already set up your developer account and environment and you know how to send commands and receive webhooks using Voice API.

Step 2: Create an XML file containing TeXML call instructions

If you already have an XML call instruction file from another provider, skip to Step 3. TeXML Translator will seamlessly interpret your existing verbs and nouns.

Create an empty standard .xml file using your preferred editor.

TeXML files contain the following items:

  • <Response> element -- tag defining the body of the TeXML document
  • verb -- an XML tag denoting the action that you want Telnyx to take
  • noun -- the item for the action specified in the associated verb

Our TeXML Translator API documentation contains full details of currently supported commands.

In this example, we want to our application to answer incoming calls, play some speech to the caller and hangup so we only need <Say> and <Hangup>.

<?xml version="1.0" encoding="UTF-8"?>
<!-- XML file setup above-->
<!-- The Response element wraps the body and is required -->
<Response>
<!-- You don't need to issue an answer command, start with Say for text to speech -->
<Say>This is TeXML text to speech setup in seconds! The call will now hangup.</Say>
<!-- For this example, you want to hangup the call otherwise there will be silence -->
<Hangup />
</Response>

Note: After pasting the above content, Kindly check and remove any new line added

Step 3: Make your TeXML file accessible on the internet

You can upload created file to the TeXML bin storage, so that it is available for the TeXML application. In order to do that:

  1. Go to the TeXML Bin tab in the Programmable Voice section on the Mission Control Portal
  2. Select Create new button
  3. Add a name and the content of the file
  4. Save it. The TeXML instructions will be available under the link provide in the URL field.

Create a new TeXML File

Step 4: Configure your Application to point at your TeXML file

We want our application to read the contents of the TeXML file we just made accessible on the internet, and instruct Telnyx to execute the TeXML commands contained in this file when the number associated with the application receives an inbound call. Here's how to set all that up inside the Mission Control Portal.

In your Telnyx Mission Control Portal account created in Step 1:

  • Select Voice -> Programmable Voice on the left-hand side navigation menu and navigate to the TeXML Applications tab.
  • Edit the TeXML Application you created in Step 1 by clicking on the pencil ✎ icon next to it.
  • For this example, change the Voice Method to GET, as we want to read the contents of the TeXML file.
  • Configure the application to send a TeXML webhook to the URL of the XML file created in Step 3, by entering the URL of the file in the field marked Send a TeXML Webhook to the URL:.
  • Don't worry about the other settings in the TeXML application for now - they won't affect this example.
  • Save all changes.

Configuring a TeXML Application to point at a TeXML File URL

Step 5: Dial your Telnyx number

Using your favorite telephony client or your own device, dial the number you purchased in Step 1 which is connected to the TeXML Application we just configured. The call will answer automatically and you should hear your text to speech playing. It's that simple!

Where to next?

  • Now that you've successfully configured TeXML to handle an incoming call, check out our video guide showing you how to make an outbound call from your Telnyx number using Telnyx API, and play some text-to-speech when that call is answered using the same TeXML file from this example. Be sure you've set up an Outbound Voice Profile first.
  • If you'd prefer to start building with our RESTful API, check out our guide to setting up your development environment . After you're set up, you can learn how to send commands and receive webhooks .

On this page