Make a call with .NET SDK
This guide shows how to make a Text-to-speech phone call in a .NET application using the Voice API and .NET SDK.
In this guide you will learn:
- How to set up your your ASP.NET Core app
- How to make a TTS phone call
What you need to know before you start
Before you can get started, you need the following already set up:
- Set all Voice API configuration settings.
- ASP.NET Core 7.0 or later SDK and ASP.NET Core Runtime and a familiarity with how to create an app.
- A mobile handset that can receive phone calls.
Set up your ASP.NET Core application
Create a new project folder and open a command prompt. Execute the following command to create a new ASP.NET Core console application:
dotnet new console
This creates a new console application and project.
The easiest way to install the SDK is using the dotnet
CLI:
- Open a command prompt or terminal to the local repository folder.
- Execute the following command:
dotnet add package Sinch --prerelease
Note:
--prerelease
option to install it.Modify your application
In your project folder, open theProgram.cs
file and paste the provided "Program.cs" code into the file, replacing all the existing content.The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.
Initialize the client
To start using the Voice API with the SDK, you need to initialize the main client class with your credentials from your Sinch dashboard and additionally create a Voice client object that uses your Voice app credentials.
Note:
For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials.
using Sinch;
var sinch = new SinchClient("YOUR_access_key",
"YOUR_access_secret",
"YOUR_project_id");
var voice = sinch.Voice("YOUR_application_key", "YOUR_application_secret");
Or, if you only need to use Voice API:
using Sinch;
var sinch = new SinchClient(default, default, default);
var voice = sinch.Voice("YOUR_application_key", "YOUR_application_secret");
Destination number
In this example you want to call a phone number. Change the value of theYOUR_phone_number
parameter to the phone number you verified in your dashboard in E.164 format.Note:
When your account is in trial mode, you can only call your verified numbers. If you want to call any number, you need to upgrade your account!
Save the file.
Make your phone call
- Now you can execute the code and make your phone call. Run the following command:
dotnet run
You should receive a phone call to your mobile handset with a voice speaking the words in the request. You should also see the JSON response in the console.
Next steps
Now that you know how to make a call, learn how to handle an incoming call.