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 telnyx
bash
pip install telnyx

Setup

初始化

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
client
is already initialized as shown above.
python
import os
from telnyx import Telnyx

client = Telnyx(
    api_key=os.environ.get("TELNYX_API_KEY"),  # 这是默认配置,可省略
)
以下所有示例均假设已按上述方式初始化
client

Forking 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_start
Optional:
client_state
(string),
command_id
(string),
rx
(string),
stream_type
(enum),
tx
(string)
python
response = client.calls.actions.start_forking(
    call_control_id="call_control_id",
)
print(response.data)
媒体分流功能可让你将通话中的媒体实时流式传输至指定目标。
POST /calls/{call_control_id}/actions/fork_start
可选参数:
client_state
(字符串)、
command_id
(字符串)、
rx
(字符串)、
stream_type
(枚举)、
tx
(字符串)
python
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_stop
Optional:
client_state
(string),
command_id
(string),
stream_type
(enum)
python
response = client.calls.actions.stop_forking(
    call_control_id="call_control_id",
)
print(response.data)
停止通话的媒体分流。
POST /calls/{call_control_id}/actions/fork_stop
可选参数:
client_state
(字符串)、
command_id
(字符串)、
stream_type
(枚举)
python
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_start
Optional:
client_state
(string),
command_id
(string),
custom_parameters
(array[object]),
dialogflow_config
(object),
enable_dialogflow
(boolean),
stream_auth_token
(string),
stream_bidirectional_codec
(enum),
stream_bidirectional_mode
(enum),
stream_bidirectional_sampling_rate
(enum),
stream_bidirectional_target_legs
(enum),
stream_codec
(enum),
stream_track
(enum),
stream_url
(string)
python
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_state
(字符串)、
command_id
(字符串)、
custom_parameters
(对象数组)、
dialogflow_config
(对象)、
enable_dialogflow
(布尔值)、
stream_auth_token
(字符串)、
stream_bidirectional_codec
(枚举)、
stream_bidirectional_mode
(枚举)、
stream_bidirectional_sampling_rate
(枚举)、
stream_bidirectional_target_legs
(枚举)、
stream_codec
(枚举)、
stream_track
(枚举)、
stream_url
(字符串)
python
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_stop
Optional:
client_state
(string),
command_id
(string),
stream_id
(uuid)
python
response = client.calls.actions.stop_streaming(
    call_control_id="call_control_id",
)
print(response.data)
停止向WebSocket传输通话媒体。
POST /calls/{call_control_id}/actions/streaming_stop
可选参数:
client_state
(字符串)、
command_id
(字符串)、
stream_id
(uuid)
python
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_start
Optional:
client_state
(string),
command_id
(string),
transcription_engine
(enum),
transcription_engine_config
(object),
transcription_tracks
(string)
python
response = client.calls.actions.start_transcription(
    call_control_id="call_control_id",
)
print(response.data)
启动实时语音转写。
POST /calls/{call_control_id}/actions/transcription_start
可选参数:
client_state
(字符串)、
command_id
(字符串)、
transcription_engine
(枚举)、
transcription_engine_config
(对象)、
transcription_tracks
(字符串)
python
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_stop
Optional:
client_state
(string),
command_id
(string)
python
response = client.calls.actions.stop_transcription(
    call_control_id="call_control_id",
)
print(response.data)

停止实时语音转写。
POST /calls/{call_control_id}/actions/transcription_stop
可选参数:
client_state
(字符串)、
command_id
(字符串)
python
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
telnyx-timestamp
and
telnyx-signature-ed25519
headers for verification (Standard Webhooks compatible).
EventDescription
callForkStarted
Call Fork Started
callForkStopped
Call Fork Stopped
callStreamingStarted
Call Streaming Started
callStreamingStopped
Call Streaming Stopped
callStreamingFailed
Call Streaming Failed
transcription
Transcription
以下Webhook事件将发送至你配置的Webhook URL。 所有Webhook均包含
telnyx-timestamp
telnyx-signature-ed25519
头信息用于验证(兼容标准Webhooks)。
事件描述
callForkStarted
通话分流已启动
callForkStopped
通话分流已停止
callStreamingStarted
通话流式传输已启动
callStreamingStopped
通话流式传输已停止
callStreamingFailed
通话流式传输失败
transcription
转写结果

Webhook payload fields

Webhook 负载字段

callForkStarted
FieldTypeDescription
data.record_type
enumIdentifies the type of the resource.
data.event_type
enumThe type of event being delivered.
data.id
uuidIdentifies the type of resource.
data.occurred_at
date-timeISO 8601 datetime of when the event occurred.
data.payload.connection_id
stringCall Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_control_id
stringUnique ID for controlling the call.
data.payload.call_leg_id
stringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id
stringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state
stringState received from a command.
data.payload.stream_type
enumType of media streamed.
callForkStopped
FieldTypeDescription
data.record_type
enumIdentifies the type of the resource.
data.event_type
enumThe type of event being delivered.
data.id
uuidIdentifies the type of resource.
data.occurred_at
date-timeISO 8601 datetime of when the event occurred.
data.payload.connection_id
stringCall Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_control_id
stringUnique ID for controlling the call.
data.payload.call_leg_id
stringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id
stringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state
stringState received from a command.
data.payload.stream_type
enumType of media streamed.
callStreamingStarted
FieldTypeDescription
data.record_type
enumIdentifies the type of the resource.
data.event_type
enumThe type of event being delivered.
data.id
uuidIdentifies the type of resource.
data.occurred_at
date-timeISO 8601 datetime of when the event occurred.
data.payload.call_control_id
stringCall ID used to issue commands via Call Control API.
data.payload.connection_id
stringCall Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_leg_id
stringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id
stringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state
stringState received from a command.
data.payload.stream_url
stringDestination WebSocket address where the stream is going to be delivered.
callStreamingStopped
FieldTypeDescription
data.record_type
enumIdentifies the type of the resource.
data.event_type
enumThe type of event being delivered.
data.id
uuidIdentifies the type of resource.
data.occurred_at
date-timeISO 8601 datetime of when the event occurred.
data.payload.call_control_id
stringCall ID used to issue commands via Call Control API.
data.payload.connection_id
stringCall Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_leg_id
stringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id
stringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state
stringState received from a command.
data.payload.stream_url
stringDestination WebSocket address where the stream is going to be delivered.
callStreamingFailed
FieldTypeDescription
data.record_type
enumIdentifies the resource.
data.event_type
enumThe type of event being delivered.
data.id
uuidIdentifies the type of resource.
data.occurred_at
date-timeISO 8601 datetime of when the event occurred.
data.payload.call_control_id
stringCall ID used to issue commands via Call Control API.
data.payload.connection_id
stringCall Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_leg_id
stringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id
stringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state
stringState received from a command.
data.payload.failure_reason
stringA short description explaning why the media streaming failed.
data.payload.stream_id
uuidIdentifies the streaming.
data.payload.stream_type
enumThe type of stream connection the stream is performing.
transcription
FieldTypeDescription
data.record_type
enumIdentifies the type of the resource.
data.event_type
enumThe type of event being delivered.
data.id
uuidIdentifies the type of resource.
data.occurred_at
date-timeISO 8601 datetime of when the event occurred.
data.payload.call_control_id
stringUnique identifier and token for controlling the call.
data.payload.call_leg_id
stringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id
stringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state
stringUse this field to add state to every subsequent webhook.
data.payload.connection_id
stringCall Control App ID (formerly Telnyx connection ID) used in the call.
callForkStarted
字段类型描述
data.record_type
枚举标识资源类型
data.event_type
枚举标识所推送的事件类型
data.id
uuid标识资源ID
data.occurred_at
日期时间事件发生的ISO 8601格式时间戳
data.payload.connection_id
字符串通话中使用的Call Control App ID(原Telnyx连接ID)
data.payload.call_control_id
字符串用于控制通话的唯一ID
data.payload.call_leg_id
字符串通话的唯一标识ID,可用于关联Webhook事件
data.payload.call_session_id
字符串通话会话的唯一标识ID,可用于关联Webhook事件
data.payload.client_state
字符串从命令中接收的状态信息
data.payload.stream_type
枚举流式传输的媒体类型
callForkStopped
字段类型描述
data.record_type
枚举标识资源类型
data.event_type
枚举标识所推送的事件类型
data.id
uuid标识资源ID
data.occurred_at
日期时间事件发生的ISO 8601格式时间戳
data.payload.connection_id
字符串通话中使用的Call Control App ID(原Telnyx连接ID)
data.payload.call_control_id
字符串用于控制通话的唯一ID
data.payload.call_leg_id
字符串通话的唯一标识ID,可用于关联Webhook事件
data.payload.call_session_id
字符串通话会话的唯一标识ID,可用于关联Webhook事件
data.payload.client_state
字符串从命令中接收的状态信息
data.payload.stream_type
枚举流式传输的媒体类型
callStreamingStarted
字段类型描述
data.record_type
枚举标识资源类型
data.event_type
枚举标识所推送的事件类型
data.id
uuid标识资源ID
data.occurred_at
日期时间事件发生的ISO 8601格式时间戳
data.payload.call_control_id
字符串用于通过Call Control API发送命令的通话ID
data.payload.connection_id
字符串通话中使用的Call Control App ID(原Telnyx连接ID)
data.payload.call_leg_id
字符串通话的唯一标识ID,可用于关联Webhook事件
data.payload.call_session_id
字符串通话会话的唯一标识ID,可用于关联Webhook事件
data.payload.client_state
字符串从命令中接收的状态信息
data.payload.stream_url
字符串流式传输的目标WebSocket地址
callStreamingStopped
字段类型描述
data.record_type
枚举标识资源类型
data.event_type
枚举标识所推送的事件类型
data.id
uuid标识资源ID
data.occurred_at
日期时间事件发生的ISO 8601格式时间戳
data.payload.call_control_id
字符串用于通过Call Control API发送命令的通话ID
data.payload.connection_id
字符串通话中使用的Call Control App ID(原Telnyx连接ID)
data.payload.call_leg_id
字符串通话的唯一标识ID,可用于关联Webhook事件
data.payload.call_session_id
字符串通话会话的唯一标识ID,可用于关联Webhook事件
data.payload.client_state
字符串从命令中接收的状态信息
data.payload.stream_url
字符串流式传输的目标WebSocket地址
callStreamingFailed
字段类型描述
data.record_type
枚举标识资源类型
data.event_type
枚举标识所推送的事件类型
data.id
uuid标识资源ID
data.occurred_at
日期时间事件发生的ISO 8601格式时间戳
data.payload.call_control_id
字符串用于通过Call Control API发送命令的通话ID
data.payload.connection_id
字符串通话中使用的Call Control App ID(原Telnyx连接ID)
data.payload.call_leg_id
字符串通话的唯一标识ID,可用于关联Webhook事件
data.payload.call_session_id
字符串通话会话的唯一标识ID,可用于关联Webhook事件
data.payload.client_state
字符串从命令中接收的状态信息
data.payload.failure_reason
字符串媒体流式传输失败的简短原因说明
data.payload.stream_id
uuid标识流式传输任务ID
data.payload.stream_type
枚举流式传输的连接类型
transcription
字段类型描述
data.record_type
枚举标识资源类型
data.event_type
枚举标识所推送的事件类型
data.id
uuid标识资源ID
data.occurred_at
日期时间事件发生的ISO 8601格式时间戳
data.payload.call_control_id
字符串用于控制通话的唯一标识和令牌
data.payload.call_leg_id
字符串通话的唯一标识ID,可用于关联Webhook事件
data.payload.call_session_id
字符串通话会话的唯一标识ID,可用于关联Webhook事件
data.payload.client_state
字符串可使用此字段为后续所有Webhook添加状态信息
data.payload.connection_id
字符串通话中使用的Call Control App ID(原Telnyx连接ID)