Play audio URL
Play an audio file on the call. If multiple play audio commands are issued consecutively, the audio files will be placed in a queue awaiting playback.
Notes:
- When
overlayis enabled,target_legsis limited toself. - A customer cannot Play Audio with
overlay=trueunless there is a Play Audio withoverlay=falseactively playing.
Expected Webhooks:
call.playback.startedcall.playback.ended
POST
/
calls
/
{call_control_id}
/
actions
/
playback_start
JavaScript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.calls.actions.startPlayback('call_control_id');
console.log(response.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.calls.actions.start_playback(
call_control_id="call_control_id",
)
print(response.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.Calls.Actions.StartPlayback(
context.TODO(),
"call_control_id",
telnyx.CallActionStartPlaybackParams{},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.calls.actions.ActionStartPlaybackParams;
import com.telnyx.sdk.models.calls.actions.ActionStartPlaybackResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
ActionStartPlaybackResponse response = client.calls().actions().startPlayback("call_control_id");
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.calls.actions.start_playback("call_control_id")
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->calls->actions->startPlayback(
'call_control_id',
audioType: 'wav',
audioURL: 'http://www.example.com/sounds/greeting.wav',
cacheAudio: true,
clientState: 'aGF2ZSBhIG5pY2UgZGF5ID1d',
commandID: '891510ac-f3e4-11e8-af5b-de00688a4901',
loop: 'infinity',
mediaName: 'my_media_uploaded_to_media_storage_api',
overlay: true,
playbackContent: 'SUQzAwAAAAADf1...',
stop: 'current',
targetLegs: 'self',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx calls:actions start-playback \
--api-key 'My API Key' \
--call-control-id call_control_idcurl --request POST \
--url https://api.telnyx.com/v2/calls/{call_control_id}/actions/playback_start \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"audio_url": "http://www.example.com/sounds/greeting.wav",
"loop": "infinity",
"overlay": true,
"stop": "current",
"target_legs": "self",
"client_state": "aGF2ZSBhIG5pY2UgZGF5ID1d",
"command_id": "891510ac-f3e4-11e8-af5b-de00688a4901"
}
'{
"data": {
"result": "ok"
}
}Authorizations
Body
application/json
Play audio URL request
Was this page helpful?
JavaScript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.calls.actions.startPlayback('call_control_id');
console.log(response.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.calls.actions.start_playback(
call_control_id="call_control_id",
)
print(response.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.Calls.Actions.StartPlayback(
context.TODO(),
"call_control_id",
telnyx.CallActionStartPlaybackParams{},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.calls.actions.ActionStartPlaybackParams;
import com.telnyx.sdk.models.calls.actions.ActionStartPlaybackResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
ActionStartPlaybackResponse response = client.calls().actions().startPlayback("call_control_id");
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.calls.actions.start_playback("call_control_id")
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->calls->actions->startPlayback(
'call_control_id',
audioType: 'wav',
audioURL: 'http://www.example.com/sounds/greeting.wav',
cacheAudio: true,
clientState: 'aGF2ZSBhIG5pY2UgZGF5ID1d',
commandID: '891510ac-f3e4-11e8-af5b-de00688a4901',
loop: 'infinity',
mediaName: 'my_media_uploaded_to_media_storage_api',
overlay: true,
playbackContent: 'SUQzAwAAAAADf1...',
stop: 'current',
targetLegs: 'self',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx calls:actions start-playback \
--api-key 'My API Key' \
--call-control-id call_control_idcurl --request POST \
--url https://api.telnyx.com/v2/calls/{call_control_id}/actions/playback_start \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"audio_url": "http://www.example.com/sounds/greeting.wav",
"loop": "infinity",
"overlay": true,
"stop": "current",
"target_legs": "self",
"client_state": "aGF2ZSBhIG5pY2UgZGF5ID1d",
"command_id": "891510ac-f3e4-11e8-af5b-de00688a4901"
}
'{
"data": {
"result": "ok"
}
}