Skip to content
Last updated

You can quickly see how the Voice API works by calling yourself using the API and the Node.js SDK.

Note

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

Step 1. Set up your Node.js application

To quickly get started setting up a simple client application using the Node SDK:

  1. If you haven't already, clone the sinch-sdk-node-quickstart repository.

  2. Navigate to the templates/client folder.

  3. Open a command prompt or terminal and run the following command to install the necessary dependencies:

    npm install
  4. Open the .env file. Using the Voice app credentials from your Sinch Build Dashboard, populate the following fields with your values:

FieldDescription
SINCH_APPLICATION_KEYThe unique ID of your application.
SINCH_APPLICATION_SECRETThe secret for your application.
  1. Save the file.
snippet.js
// Use this code to make a phone call using the Voice API and the Node SDK. 
// eslint-disable-next-line no-unused-vars
import { Voice, VoiceService } from '@sinch/sdk-core';

/** @param {VoiceService} voiceService */
export const execute = async (voiceService) => {

  const recipientPhoneNumber = 'the_phone_number_to_call';
  const callingNumber = 'the_calling_number';

  /** @type {Voice.TtsCalloutRequestData} */
  const requestData = {
    ttsCalloutRequestBody: {
      method: 'ttsCallout',
      ttsCallout: {
        destination: {
          type: 'number',
          endpoint: recipientPhoneNumber,
        },
        cli: callingNumber,
        locale: 'en-US/male',
        text: 'Hello, this is a call from Sinch.',
      },
    },
  };

  const response = await voiceService.callouts.tts(requestData);

  console.log(`Callout response: \n${JSON.stringify(response, null, 2)}`);
};

Modify your application

The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.

Set your Destination number parameter

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

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

node index.js

You should receive a phone call to the number you called with the message "This is a phone call from Sinch."

Next steps

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

Additional resources