1. Vonage Learn
  2. Blog
  3. 2017
  4. 07
  5. 28
  6. Text to Speech Phone Call Dr
How to Make a Text-to-Speech Phone Call in ASP.NET

< Tutorial />

How to Make a Text-to-Speech Phone Call in ASP.NET

This is the first tutorial on how to use Voice APIs with ASP.NET series.

Building high quality voice applications is now made easy with The Nexmo Voice API. It allows you to make and receive phone calls with your ASP.NET applications among other things.

In this tutorial, we will see how to make a Text-to-Speech phone call with ASP.NET.

View on GitHub

The Nexmo Voice API makes it so easy to make a call. You send an authenticated call request to the API. Once it’s accepted, Nexmo makes a GET request to retrieve an NCCO (Nexmo Call Control Objects)and executes the actions within that NCCO.

Flow of an outbound call


  • Visual Studio 2017
  • A project set up for this tutorial series which you can find on Github
  • Optional: Nexmo CLI


In order to be able to use The Nexmo Voice API, you'll have to create a voice application.

Before diving into the code, you need to follow the configuration steps details in the “Nexmo Voice API with ASP.NET: Before you start” post.

Once the configuration is done successfully, you are ready to make a Text-to-Speech phone call with The Nexmo Voice API!

Making a Text-to-Speech call with The Nexmo voice API

Congratulations! You made it so far which means you managed to configure your voice application and you created an ASP.NET project.

In appsettings.json file, make sure to initialize Nexmo with your API credentials as well as the app ID and private key you just created.

  "Nexmo.UserAgent": "NEXMOQUICKSTART/1.0",
  "Nexmo.Url.Rest": "https://rest.nexmo.com",
  "Nexmo.Url.Api": "https://api.nexmo.com",
  "Nexmo.api_key": "NEXMO-API-KEY",
  "Nexmo.api_secret": "NEXMO-API-SECRET",
  "Nexmo.Application.Id": "NEXMO-APP-ID",
  "Nexmo.Application.Key": "PATH:\TO\private.key"

Then create a new controller called VoiceController.cs in which create an action method called MakeCall.

Above the method, add a HttpGetAttribute to allow the user to navigate to the corresponding view.

public ActionResult MakeCall()
   Return View();

Afterwards, click on the Views folder and add a new folder called Voice. Within this folder, create a new view (`MakeCall.cshtml’). Then, add a form to the view with an input tag (type = “text”) for the destination number. Lastly, add an input tag (type = “submit”) to submit the form. Back to the VoiceController, add the following using statement to the top of the file.

using Nexmo.Api

Add another action method named MakeCall with a string parameter: to.

Within this method, you will make a call using the parameter as the to. The from number is your Nexmo virtual number (retrieved from the appsettings.json), the answer_url is the NCCO ( Nexmo Call Control Object) which is a JSON array used to control the flow of your call.

You can use one of the Nexmo’s community NCCO examples or create your own and host it somewhere reachable by The Nexmo Voice API. An easy hosting solution is GitHub Gist.

Since we are trying to make a Text-to-Speech call in this demo, the action required for the NCCO is Talk , you also need to provide the text to be synthesised into speech in the call and the last thing to provide is a voice name. Nexmo provides a list a voiceNames in different languages and accents for both genders.

In my NCCO below, I chose the voiceName to be “Amy” which is a female British-english voice.

    "action": "talk",
    "voiceName": "Amy",
    "text": "Hi, this is Amy. You are listening to a Call made with the Nexmo Voice API"

Now back to MakeCall method, make sure NEXMO_CALL_ANSWER_URL points to your NCCO json file.

public ActionResult MakeCall(string to)
    var NEXMO_FROM_NUMBER =    Configuration.Instance.Settings["appsettings:NEXMO_FROM_NUMBER"];
    var NEXMO_TO_NUMBER = to;
    var NEXMO_CALL_ANSWER_URL = "https://nexmo-community.github.io/ncco-examples/first_call_talk.json";

    var results = Call.Do(new Call.CallCommand
        to = new[]
                    new Call.Endpoint {
                        type = "phone",
                        number = NEXMO_TO_NUMBER
        from = new Call.Endpoint
            type = "phone",
            number = NEXMO_FROM_NUMBER
        answer_url = new[]
    var result = new HttpStatusCodeResult(200);

    return RedirectToAction("Index", "Voice");

Now, let's run the app and make a Text-to-Speech phone call.

When it is successful, it retrieves the NCCO from your webhook, executes the actions, and terminates the call.

You may observe some delay before your phone rings depending on your phone carrier.

Learn more

API References and Tools

Nexmo Getting Started Guide for ASP.NET

Comments currently disabled.