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 repository.
Navigate to the
examples/getting-started/voice/make-a-callfolder.Open a command prompt or terminal and run the following command to install the necessary dependencies:
npm installRename the
.env.examplefile to.envand open it. Using the 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.
Navigate to
examples/getting-started/voice/make-a-call/src/voice/voiceSample.js.
// Use this code to make a phone call using the Voice API and the Node SDK.
/**
* Class to place a demo Voice call using the Sinch Node.js SDK.
*/
export class VoiceSample {
/**
* @param { import('@sinch/sdk-core').VoiceService } voiceService - the VoiceService instance from the Sinch SDK containing the API methods.
*/
constructor(voiceService) {
this.voiceService = voiceService;
}
async start() {
const caller = 'CALLER_NUMBER';
const recipient = 'RECIPIENT_PHONE_NUMBER';
const response = await this.voiceService.callouts.tts({
ttsCalloutRequestBody: {
method: 'ttsCallout',
ttsCallout: {
destination: {
type: 'number',
endpoint: recipient,
},
cli: caller,
text: 'Hello, this is a call from Sinch. Congratulations! You just made your first call.',
},
},
});
console.log('Call ID:', response.callId);
}
}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 src/app.jsYou 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.