Reputation: 147
I am trying to call HTTP request in Voximplant Platform but i am not able to play the audio coming as a response from the API call
below is the code for the reference
Upvotes: 0
Views: 87
Reputation: 151
Do you receive a link to the audio file in the HTTP request's response?
If yes, then you can use the createURLPlayer method to play the audio file. Check the documentation link.
Shortly, to use this method, you need to prepare parameters and create the player, like this:
const urlPlayerRequest = {
url: 'https://your_secret_url.com/12345',
};
let player = VoxEngine.createURLPlayer(urlPlayerRequest);
player.sendMediaTo(call);
This works for GET requests. If you need to make a POST request, then the parameters for the player are different:
const urlPlayerRequest = {
method: URLPlayerRequestMethod.POST,
url: 'https://your_secret_url.com/12345',
headers: [
{ name: 'accept', value: 'audio/mpeg' },
{ name: 'content-type', value: 'application/json' },
{ name: 'xi-api-key', value: `your_super_secret_api_key` },
],
body: {
text: JSON.stringify({ firstParameter: 'first', secondParameter: 2 }),
},
};
let player = VoxEngine.createURLPlayer(urlPlayerRequest);
player.sendMediaTo(call);
This should play the link to an audio file to the call.
Upvotes: 0