0

Transcription start

by
Published Apr 8, 2025

Start real-time transcription. Transcription will stop on call hang-up, or can be initiated via the Transcription stop command. **Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/start-call-transcription#callbacks) below):** - `call.transcription`

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Transcription start
7
 * Start real-time transcription. Transcription will stop on call hang-up, or can be initiated via the Transcription stop command.
8

9
**Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/start-call-transcription#callbacks) below):**
10

11
- `call.transcription`
12

13
 */
14
export async function main(
15
	auth: Telnyx,
16
	call_control_id: string,
17
	body: {
18
		transcription_engine?: 'A' | 'B'
19
		language?:
20
			| 'af'
21
			| 'sq'
22
			| 'am'
23
			| 'ar'
24
			| 'hy'
25
			| 'az'
26
			| 'eu'
27
			| 'bn'
28
			| 'bs'
29
			| 'bg'
30
			| 'my'
31
			| 'ca'
32
			| 'yue'
33
			| 'zh'
34
			| 'hr'
35
			| 'cs'
36
			| 'da'
37
			| 'nl'
38
			| 'en'
39
			| 'et'
40
			| 'fil'
41
			| 'fi'
42
			| 'fr'
43
			| 'gl'
44
			| 'ka'
45
			| 'de'
46
			| 'el'
47
			| 'gu'
48
			| 'iw'
49
			| 'hi'
50
			| 'hu'
51
			| 'is'
52
			| 'id'
53
			| 'it'
54
			| 'ja'
55
			| 'jv'
56
			| 'kn'
57
			| 'kk'
58
			| 'km'
59
			| 'ko'
60
			| 'lo'
61
			| 'lv'
62
			| 'lt'
63
			| 'mk'
64
			| 'ms'
65
			| 'ml'
66
			| 'mr'
67
			| 'mn'
68
			| 'ne'
69
			| 'no'
70
			| 'fa'
71
			| 'pl'
72
			| 'pt'
73
			| 'pa'
74
			| 'ro'
75
			| 'ru'
76
			| 'rw'
77
			| 'sr'
78
			| 'si'
79
			| 'sk'
80
			| 'sl'
81
			| 'ss'
82
			| 'st'
83
			| 'es'
84
			| 'su'
85
			| 'sw'
86
			| 'sv'
87
			| 'ta'
88
			| 'te'
89
			| 'th'
90
			| 'tn'
91
			| 'tr'
92
			| 'ts'
93
			| 'uk'
94
			| 'ur'
95
			| 'uz'
96
			| 've'
97
			| 'vi'
98
			| 'xh'
99
			| 'zu'
100
			| 'he'
101
			| 'la'
102
			| 'mi'
103
			| 'cy'
104
			| 'br'
105
			| 'sn'
106
			| 'yo'
107
			| 'so'
108
			| 'oc'
109
			| 'be'
110
			| 'tg'
111
			| 'sd'
112
			| 'yi'
113
			| 'fo'
114
			| 'ht'
115
			| 'ps'
116
			| 'tk'
117
			| 'nn'
118
			| 'mt'
119
			| 'sa'
120
			| 'lb'
121
			| 'bo'
122
			| 'tl'
123
			| 'mg'
124
			| 'as'
125
			| 'tt'
126
			| 'haw'
127
			| 'ln'
128
			| 'ha'
129
			| 'ba'
130
			| 'jw'
131
			| 'auto_detect'
132
		interim_results?: false | true
133
		enable_speaker_diarization?: false | true
134
		min_speaker_count?: number
135
		max_speaker_count?: number
136
		client_state?: string
137
		transcription_tracks?: string
138
		command_id?: string
139
	}
140
) {
141
	const url = new URL(
142
		`https://api.telnyx.com/v2/calls/${call_control_id}/actions/transcription_start`
143
	)
144

145
	const response = await fetch(url, {
146
		method: 'POST',
147
		headers: {
148
			'Content-Type': 'application/json',
149
			Authorization: 'Bearer ' + auth.apiKey
150
		},
151
		body: JSON.stringify(body)
152
	})
153
	if (!response.ok) {
154
		const text = await response.text()
155
		throw new Error(`${response.status} ${text}`)
156
	}
157
	return await response.json()
158
}
159