Skip to content
Last updated

You can quickly see how the Voice API works by calling yourself using the Python SDK for Voice API.

Note:

Before you can get started, you need the following already set up:

Step 1. Set up your Python application

Create a new project folder.

The easiest way to install the SDK is using pip:

  1. Open a command prompt or terminal to the local repository folder.
  2. Execute the following command:
    pip install sinch

Modify your application

In your project folder, create a new filed named "app.py" and paste the provided "app.py" code into the file.

app.py
# Use this code to make a phone call using the Voice API and Python SDK. 
from sinch import SinchClient

sinch_client = SinchClient(
    application_key="YOUR_application_key",
    application_secret="YOUR_application_secret"
)

response = sinch_client.voice.callouts.text_to_speech(
    destination={
        "type":"number",
        "endpoint":"YOUR_phone_number"
    }, 
    text="Hello, this is a call from Sinch. Congratulations! You made your first call.")

print(response)

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 SDK, you need to initialize the main client class with your credentials from your Sinch dashboard and additionally add your Voice app credentials.

from sinch import SinchClient

sinch_client = SinchClient(
    application_key="YOUR_application_key",
    application_secret="YOUR_application_secret"
)
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, as in the following example:

import os
from sinch import SinchClient

sinch_client = SinchClient(
    application_key=os.getenv("APPLICATION_KEY"),
    application_secret=os.getenv("APPLICATION_SECRET")
)

Set your Destination parameter

In this example you want to call a phone number. Change the value of the endpoint 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.

Step 2. Make your first call

Now you can execute the code and make your text-to-speech call. Run the following command:

python app.py

You should receive a phone call to the number you called with the message "Hello, this is a call from Sinch. Congratulations! You made your first call."

Next steps

Now that you know how to make a call, learn how to handle an incoming call.

Additional resources