//native
type Telnyx = {
apiKey: string
}
/**
* Speak text
* Convert text to speech and play it back on the call. If multiple speak text commands are issued consecutively, the audio files will be placed in a queue awaiting playback.
**Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/speak-call#callbacks) below):**
- `call.speak.started`
- `call.speak.ended`
*/
export async function main(
auth: Telnyx,
call_control_id: string,
body: {
payload: string
payload_type?: 'text' | 'ssml'
service_level?: 'basic' | 'premium'
stop?: string
voice: string
voice_settings?: { api_key_ref?: string }
language?:
| 'arb'
| 'cmn-CN'
| 'cy-GB'
| 'da-DK'
| 'de-DE'
| 'en-AU'
| 'en-GB'
| 'en-GB-WLS'
| 'en-IN'
| 'en-US'
| 'es-ES'
| 'es-MX'
| 'es-US'
| 'fr-CA'
| 'fr-FR'
| 'hi-IN'
| 'is-IS'
| 'it-IT'
| 'ja-JP'
| 'ko-KR'
| 'nb-NO'
| 'nl-NL'
| 'pl-PL'
| 'pt-BR'
| 'pt-PT'
| 'ro-RO'
| 'ru-RU'
| 'sv-SE'
| 'tr-TR'
client_state?: string
command_id?: string
}
) {
const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/speak`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.apiKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 428 days ago