telnyx-voice-streaming-python
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
Telnyx Voice Streaming - Python
Telnyx 通话流式传输 - Python
Installation
安装
bash
pip install telnyxbash
pip install telnyxSetup
初始化
python
import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)All examples below assume is already initialized as shown above.
clientpython
import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # 这是默认配置,可省略
)以下所有示例均假设已按上述方式初始化。
clientForking start
启动媒体分流
Call forking allows you to stream the media from a call to a specific target in realtime.
POST /calls/{call_control_id}/actions/fork_startOptional: (string), (string), (string), (enum), (string)
client_statecommand_idrxstream_typetxpython
response = client.calls.actions.start_forking(
call_control_id="call_control_id",
)
print(response.data)媒体分流功能可让你将通话中的媒体实时流式传输至指定目标。
POST /calls/{call_control_id}/actions/fork_start可选参数:(字符串)、(字符串)、(字符串)、(枚举)、(字符串)
client_statecommand_idrxstream_typetxpython
response = client.calls.actions.start_forking(
call_control_id="call_control_id",
)
print(response.data)Forking stop
停止媒体分流
Stop forking a call.
POST /calls/{call_control_id}/actions/fork_stopOptional: (string), (string), (enum)
client_statecommand_idstream_typepython
response = client.calls.actions.stop_forking(
call_control_id="call_control_id",
)
print(response.data)停止通话的媒体分流。
POST /calls/{call_control_id}/actions/fork_stop可选参数:(字符串)、(字符串)、(枚举)
client_statecommand_idstream_typepython
response = client.calls.actions.stop_forking(
call_control_id="call_control_id",
)
print(response.data)Streaming start
启动流式传输
Start streaming the media from a call to a specific WebSocket address or Dialogflow connection in near-realtime.
POST /calls/{call_control_id}/actions/streaming_startOptional: (string), (string), (array[object]), (object), (boolean), (string), (enum), (enum), (enum), (enum), (enum), (enum), (string)
client_statecommand_idcustom_parametersdialogflow_configenable_dialogflowstream_auth_tokenstream_bidirectional_codecstream_bidirectional_modestream_bidirectional_sampling_ratestream_bidirectional_target_legsstream_codecstream_trackstream_urlpython
response = client.calls.actions.start_streaming(
call_control_id="call_control_id",
)
print(response.data)启动将通话媒体近实时流式传输至指定WebSocket地址或Dialogflow连接。
POST /calls/{call_control_id}/actions/streaming_start可选参数:(字符串)、(字符串)、(对象数组)、(对象)、(布尔值)、(字符串)、(枚举)、(枚举)、(枚举)、(枚举)、(枚举)、(枚举)、(字符串)
client_statecommand_idcustom_parametersdialogflow_configenable_dialogflowstream_auth_tokenstream_bidirectional_codecstream_bidirectional_modestream_bidirectional_sampling_ratestream_bidirectional_target_legsstream_codecstream_trackstream_urlpython
response = client.calls.actions.start_streaming(
call_control_id="call_control_id",
)
print(response.data)Streaming stop
停止流式传输
Stop streaming a call to a WebSocket.
POST /calls/{call_control_id}/actions/streaming_stopOptional: (string), (string), (uuid)
client_statecommand_idstream_idpython
response = client.calls.actions.stop_streaming(
call_control_id="call_control_id",
)
print(response.data)停止向WebSocket传输通话媒体。
POST /calls/{call_control_id}/actions/streaming_stop可选参数:(字符串)、(字符串)、(uuid)
client_statecommand_idstream_idpython
response = client.calls.actions.stop_streaming(
call_control_id="call_control_id",
)
print(response.data)Transcription start
启动实时转写
Start real-time transcription.
POST /calls/{call_control_id}/actions/transcription_startOptional: (string), (string), (enum), (object), (string)
client_statecommand_idtranscription_enginetranscription_engine_configtranscription_trackspython
response = client.calls.actions.start_transcription(
call_control_id="call_control_id",
)
print(response.data)启动实时语音转写。
POST /calls/{call_control_id}/actions/transcription_start可选参数:(字符串)、(字符串)、(枚举)、(对象)、(字符串)
client_statecommand_idtranscription_enginetranscription_engine_configtranscription_trackspython
response = client.calls.actions.start_transcription(
call_control_id="call_control_id",
)
print(response.data)Transcription stop
停止实时转写
Stop real-time transcription.
POST /calls/{call_control_id}/actions/transcription_stopOptional: (string), (string)
client_statecommand_idpython
response = client.calls.actions.stop_transcription(
call_control_id="call_control_id",
)
print(response.data)停止实时语音转写。
POST /calls/{call_control_id}/actions/transcription_stop可选参数:(字符串)、(字符串)
client_statecommand_idpython
response = client.calls.actions.stop_transcription(
call_control_id="call_control_id",
)
print(response.data)Webhooks
Webhooks
The following webhook events are sent to your configured webhook URL.
All webhooks include and headers for verification (Standard Webhooks compatible).
telnyx-timestamptelnyx-signature-ed25519| Event | Description |
|---|---|
| Call Fork Started |
| Call Fork Stopped |
| Call Streaming Started |
| Call Streaming Stopped |
| Call Streaming Failed |
| Transcription |
以下Webhook事件将发送至你配置的Webhook URL。
所有Webhook均包含和头信息用于验证(兼容标准Webhooks)。
telnyx-timestamptelnyx-signature-ed25519| 事件 | 描述 |
|---|---|
| 通话分流已启动 |
| 通话分流已停止 |
| 通话流式传输已启动 |
| 通话流式传输已停止 |
| 通话流式传输失败 |
| 转写结果 |
Webhook payload fields
Webhook 负载字段
callForkStarted| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call Control App ID (formerly Telnyx connection ID) used in the call. |
| string | Unique ID for controlling the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| enum | Type of media streamed. |
callForkStopped| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call Control App ID (formerly Telnyx connection ID) used in the call. |
| string | Unique ID for controlling the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| enum | Type of media streamed. |
callStreamingStarted| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call ID used to issue commands via Call Control API. |
| string | Call Control App ID (formerly Telnyx connection ID) used in the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| string | Destination WebSocket address where the stream is going to be delivered. |
callStreamingStopped| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call ID used to issue commands via Call Control API. |
| string | Call Control App ID (formerly Telnyx connection ID) used in the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| string | Destination WebSocket address where the stream is going to be delivered. |
callStreamingFailed| Field | Type | Description |
|---|---|---|
| enum | Identifies the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call ID used to issue commands via Call Control API. |
| string | Call Control App ID (formerly Telnyx connection ID) used in the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| string | A short description explaning why the media streaming failed. |
| uuid | Identifies the streaming. |
| enum | The type of stream connection the stream is performing. |
transcription| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Unique identifier and token for controlling the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | Use this field to add state to every subsequent webhook. |
| string | Call Control App ID (formerly Telnyx connection ID) used in the call. |
callForkStarted| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举 | 标识资源类型 |
| 枚举 | 标识所推送的事件类型 |
| uuid | 标识资源ID |
| 日期时间 | 事件发生的ISO 8601格式时间戳 |
| 字符串 | 通话中使用的Call Control App ID(原Telnyx连接ID) |
| 字符串 | 用于控制通话的唯一ID |
| 字符串 | 通话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从命令中接收的状态信息 |
| 枚举 | 流式传输的媒体类型 |
callForkStopped| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举 | 标识资源类型 |
| 枚举 | 标识所推送的事件类型 |
| uuid | 标识资源ID |
| 日期时间 | 事件发生的ISO 8601格式时间戳 |
| 字符串 | 通话中使用的Call Control App ID(原Telnyx连接ID) |
| 字符串 | 用于控制通话的唯一ID |
| 字符串 | 通话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从命令中接收的状态信息 |
| 枚举 | 流式传输的媒体类型 |
callStreamingStarted| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举 | 标识资源类型 |
| 枚举 | 标识所推送的事件类型 |
| uuid | 标识资源ID |
| 日期时间 | 事件发生的ISO 8601格式时间戳 |
| 字符串 | 用于通过Call Control API发送命令的通话ID |
| 字符串 | 通话中使用的Call Control App ID(原Telnyx连接ID) |
| 字符串 | 通话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从命令中接收的状态信息 |
| 字符串 | 流式传输的目标WebSocket地址 |
callStreamingStopped| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举 | 标识资源类型 |
| 枚举 | 标识所推送的事件类型 |
| uuid | 标识资源ID |
| 日期时间 | 事件发生的ISO 8601格式时间戳 |
| 字符串 | 用于通过Call Control API发送命令的通话ID |
| 字符串 | 通话中使用的Call Control App ID(原Telnyx连接ID) |
| 字符串 | 通话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从命令中接收的状态信息 |
| 字符串 | 流式传输的目标WebSocket地址 |
callStreamingFailed| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举 | 标识资源类型 |
| 枚举 | 标识所推送的事件类型 |
| uuid | 标识资源ID |
| 日期时间 | 事件发生的ISO 8601格式时间戳 |
| 字符串 | 用于通过Call Control API发送命令的通话ID |
| 字符串 | 通话中使用的Call Control App ID(原Telnyx连接ID) |
| 字符串 | 通话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从命令中接收的状态信息 |
| 字符串 | 媒体流式传输失败的简短原因说明 |
| uuid | 标识流式传输任务ID |
| 枚举 | 流式传输的连接类型 |
transcription| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举 | 标识资源类型 |
| 枚举 | 标识所推送的事件类型 |
| uuid | 标识资源ID |
| 日期时间 | 事件发生的ISO 8601格式时间戳 |
| 字符串 | 用于控制通话的唯一标识和令牌 |
| 字符串 | 通话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话的唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 可使用此字段为后续所有Webhook添加状态信息 |
| 字符串 | 通话中使用的Call Control App ID(原Telnyx连接ID) |