You can quickly see how the Voice API works by calling yourself using the API and the Node.js SDK.
Before you can get started, you need the following already set up:
- Set all Voice API configuration settings.
- Node.js and a familiarity with how to create a new app.
To quickly get started setting up a simple client application using the Node SDK:
If you haven't already, clone the sinch-sdk-node-quickstart repository.
Navigate to the
templates/client
folder.Open a command prompt or terminal and run the following command to install the necessary dependencies:
npm install
Open the
.env
file. Using the Voice app credentials from your Sinch Build Dashboard, populate the following fields with your values:
Field | Description |
---|---|
SINCH_APPLICATION_KEY | The unique ID of your application. |
SINCH_APPLICATION_SECRET | The secret for your application. |
- Save the file.
// 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)}`);
};
The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.
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.
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.
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."
Now that you know how to make a call, learn how to handle an incoming call.