sinch-voice-api
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSinch Voice API
Sinch Voice API
Overview
概述
The Sinch Voice API lets you make, receive, and control voice calls programmatically via REST. It uses SVAML (Sinch Voice Application Markup Language) to define call flows through callback events.
Sinch Voice API允许你通过REST以编程方式发起、接收和控制语音呼叫。它使用SVAML(Sinch Voice应用标记语言)通过回调事件定义呼叫流程。
Agent Instructions
Agent使用说明
Before generating code, you MUST ask the user:
- Approach — SDK or direct API calls (curl/fetch/requests)?
- Language — Node.js, Python, Java, .NET, curl?
When generating SDK code, fetch the corresponding SDK reference page for accurate method signatures, or use the bundled examples:
- Node.js examples | Python examples | Java examples | .NET examples
When generating direct API calls, use the Voice API Reference (Markdown) for request/response schemas.
在生成代码之前,你必须询问用户:
- 实现方式 — 使用SDK还是直接调用API(curl/fetch/requests)?
- 开发语言 — Node.js、Python、Java、.NET还是curl?
生成SDK代码时,请获取对应的SDK参考页面以确保方法签名准确,或使用提供的示例:
- Node.js示例 | Python示例 | Java示例 | .NET示例
生成直接API调用代码时,请参考Voice API参考文档(Markdown)获取请求/响应架构。
Getting Started
快速开始
Authentication
身份验证
See the sinch-authentication skill. The Voice API uses Application Key + Application Secret (not project-level OAuth2).
- Basic Auth:
Authorization: Basic base64(APPLICATION_KEY:APPLICATION_SECRET) - Signed Requests (production): HMAC-SHA256 signing. See Authentication Guide.
请查看sinch-authentication技能。Voice API使用应用密钥+应用密钥密码(而非项目级OAuth2)。
- 基础认证:
Authorization: Basic base64(APPLICATION_KEY:APPLICATION_SECRET) - 签名请求(生产环境):HMAC-SHA256签名。请参考身份验证指南。
Base URLs
基础URL
| Region | Base URL |
|---|---|
| Global (default) | |
| North America | |
| Europe | |
| Southeast Asia 1 | |
| Southeast Asia 2 | |
| South America | |
Configuration endpoints (numbers, callbacks) use:
https://callingapi.sinch.com| 区域 | 基础URL |
|---|---|
| 全球(默认) | |
| 北美 | |
| 欧洲 | |
| 东南亚1 | |
| 东南亚2 | |
| 南美 | |
配置端点(号码、回调)使用:
https://callingapi.sinch.comSDK Installation
SDK安装
| Language | Package | Install |
|---|---|---|
| Node.js | | |
| Java | | Maven dependency |
| Python | | |
| .NET | | |
| 语言 | 包名 | 安装命令 |
|---|---|---|
| Node.js | | |
| Java | | Maven依赖 |
| Python | | |
| .NET | | |
First API Call: TTS Callout
首次API调用:TTS呼叫发起
bash
curl -X POST "https://calling.api.sinch.com/calling/v1/callouts" \
-H "Content-Type: application/json" \
-u "YOUR_APPLICATION_KEY:YOUR_APPLICATION_SECRET" \
-d '{
"method": "ttsCallout",
"ttsCallout": {
"destination": { "type": "number", "endpoint": "+14045005000" },
"cli": "+14045001000",
"locale": "en-US",
"text": "Hello! This is a test call from Sinch."
}
}'Node.js SDK:
javascript
import { SinchClient } from "@sinch/sdk-core";
const sinch = new SinchClient({
applicationKey: "YOUR_APPLICATION_KEY",
applicationSecret: "YOUR_APPLICATION_SECRET",
});
const response = await sinch.voice.callouts.tts({
ttsCalloutRequestBody: {
destination: { type: "number", endpoint: "+14045005000" },
cli: "+14045001000",
locale: "en-US",
text: "Hello! This is a test call from Sinch.",
},
});
console.log("Call ID:", response.callId);For more examples, see Callouts Reference or bundled examples.
bash
curl -X POST "https://calling.api.sinch.com/calling/v1/callouts" \
-H "Content-Type: application/json" \
-u "YOUR_APPLICATION_KEY:YOUR_APPLICATION_SECRET" \
-d '{
"method": "ttsCallout",
"ttsCallout": {
"destination": { "type": "number", "endpoint": "+14045005000" },
"cli": "+14045001000",
"locale": "en-US",
"text": "Hello! This is a test call from Sinch."
}
}'Node.js SDK示例:
javascript
import { SinchClient } from "@sinch/sdk-core";
const sinch = new SinchClient({
applicationKey: "YOUR_APPLICATION_KEY",
applicationSecret: "YOUR_APPLICATION_SECRET",
});
const response = await sinch.voice.callouts.tts({
ttsCalloutRequestBody: {
destination: { type: "number", endpoint: "+14045005000" },
cli: "+14045001000",
locale: "en-US",
text: "Hello! This is a test call from Sinch.",
},
});
console.log("Call ID:", response.callId);更多示例请查看呼叫发起参考文档或内置示例。
Key Concepts
核心概念
SVAML (Sinch Voice Application Markup Language)
SVAML(Sinch Voice应用标记语言)
SVAML controls call flow. Every SVAML response has:
- instructions (array): Multiple tasks — play audio, record, set cookies
- action (object): Exactly ONE routing/control action
Actions (one per response)
操作(每个响应包含一个)
| Action | Description |
|---|---|
| Terminate the call |
| Continue call setup (ACE response to proceed without rerouting) |
| Connect to PSTN number. Supports |
| Connect to Sinch SDK (in-app) endpoint |
| Connect to conference room by |
| Connect to SIP endpoint |
| Connect to a WebSocket server for real-time audio streaming (closed beta — contact Sinch to enable) |
| IVR menu with DTMF collection (supports |
| Park (hold) the call with looping prompt |
| 操作 | 描述 |
|---|---|
| 终止呼叫 |
| 继续呼叫设置(ACE响应,用于无需重路由的情况) |
| 连接到PSTN号码。支持 |
| 连接到Sinch SDK(应用内)端点 |
| 通过 |
| 连接到SIP端点 |
| 连接到WebSocket服务器进行实时音频流(封闭测试版——请联系Sinch启用) |
| 支持DTMF输入的IVR菜单(支持 |
| 保持呼叫并循环播放提示音 |
Instructions (multiple per response)
指令(每个响应可包含多个)
| Instruction | Description |
|---|---|
| Play audio files, TTS via |
| Synthesize and play text-to-speech |
| Send DTMF tones |
| Persist key-value state across callback events in the session |
| Answer the call (sends a SIP 200 OK to the INVITE, which starts billing). Required before playing prompts on unanswered calls |
| Begin recording. Supports |
| Stop an active recording |
| 指令 | 描述 |
|---|---|
| 播放音频文件,通过 |
| 合成并播放文本转语音内容 |
| 发送DTMF音调 |
| 在会话的回调事件之间持久化键值对状态 |
| 接听呼叫(向INVITE发送SIP 200 OK,开始计费)。在未接听的呼叫上播放提示音前必须执行此操作 |
| 开始录音。支持 |
| 停止正在进行的录音 |
Callback Events
回调事件
| Event | Trigger | SVAML Response |
|---|---|---|
| ICE | Call received by Sinch platform | Yes |
| ACE | Call answered by callee | Yes |
| DiCE | Call disconnected | No (fire-and-forget, logging only) |
| PIE | DTMF/voice input from | Yes |
| Notify | Notification (e.g., recording finished) | No |
See Callbacks Reference for event schemas, or bundled callbacks reference for full field tables and JSON examples.
| 事件 | 触发条件 | SVAML响应 |
|---|---|---|
| ICE | Sinch平台接收到呼叫 | 需要 |
| ACE | 被叫方接听呼叫 | 需要 |
| DiCE | 呼叫断开 | 不需要(仅为通知事件,用于日志记录) |
| PIE | | 需要 |
| Notify | 通知事件(例如录音完成) | 不需要 |
请查看回调参考文档获取事件架构,或查看内置回调参考文档获取完整字段表和JSON示例。
Callout Types
呼叫发起类型
| Method | Use Case |
|---|---|
| Call and play synthesized speech. Supports |
| Call and connect to a conference room |
| Full SVAML control with inline ICE/ACE/PIE |
Callout flags: (default ), (default ), (default ) control which callbacks fire.
enableAcefalseenableDicefalseenablePiefalse| 方法 | 使用场景 |
|---|---|
| 发起呼叫并播放合成语音。支持 |
| 发起呼叫并连接到会议室 |
| 通过内联ICE/ACE/PIE实现完整的SVAML控制 |
呼叫发起标志:(默认)、(默认)、(默认)用于控制触发哪些回调事件。
enableAcefalseenableDicefalseenablePiefalseREST Endpoints
REST端点
Paths starting with use the regional base URL from the table above. Paths starting with use .
/calling/v1//v1/configuration/https://callingapi.sinch.com| Method | Endpoint | Description |
|---|---|---|
| POST | | Place a callout (TTS, conference, or custom) |
| PATCH | | Update in-progress call with SVAML (PSTN/SIP only) |
| GET | | Get call info |
| PATCH | | Manage a call leg (PlayFiles/Say only) |
| GET | | Get conference info |
| DELETE | | Kick all participants |
| PATCH | | Mute/unmute/hold participant |
| DELETE | | Kick specific participant |
| GET | | List numbers and capabilities |
| POST | | Assign numbers to an application |
| DELETE | | Un-assign a number |
| GET/POST | | Get/update callback URLs |
以开头的路径使用上述表格中的区域基础URL。以开头的路径使用。
/calling/v1//v1/configuration/https://callingapi.sinch.com| 方法 | 端点 | 描述 |
|---|---|---|
| POST | | 发起呼叫(TTS、会议或自定义类型) |
| PATCH | | 使用SVAML更新进行中的呼叫(仅支持PSTN/SIP) |
| GET | | 获取呼叫信息 |
| PATCH | | 管理呼叫分支(仅支持PlayFiles/Say操作) |
| GET | | 获取会议信息 |
| DELETE | | 踢出所有参会者 |
| PATCH | | 静音/取消静音/保持参会者 |
| DELETE | | 踢出指定参会者 |
| GET | | 列出号码及其功能 |
| POST | | 将号码分配给应用 |
| DELETE | | 解除号码与应用的关联 |
| GET/POST | | 获取/更新回调URL |
Common Patterns
常见模式
IVR Menu (SVAML)
IVR菜单(SVAML)
json
{
"instructions": [
{ "name": "setCookie", "key": "step", "value": "ivr" }
],
"action": {
"name": "runMenu",
"mainMenu": "main",
"menus": [{
"id": "main",
"mainPrompt": "#tts[Press 1 for sales or 2 for support.]",
"options": [
{ "dtmf": 1, "action": "return(sales)" },
{ "dtmf": 2, "action": "return(support)" }
]
}]
}
}json
{
"instructions": [
{ "name": "setCookie", "key": "step", "value": "ivr" }
],
"action": {
"name": "runMenu",
"mainMenu": "main",
"menus": [{
"id": "main",
"mainPrompt": "#tts[Press 1 for sales or 2 for support.]",
"options": [
{ "dtmf": 1, "action": "return(sales)" },
{ "dtmf": 2, "action": "return(support)" }
]
}]
}
}Conference with Recording
带录音的会议
json
{
"instructions": [
{ "name": "startRecording", "options": { "notificationEvents": true } }
],
"action": {
"name": "connectConf",
"conferenceId": "myRoom",
"moh": "ring"
}
}json
{
"instructions": [
{ "name": "startRecording", "options": { "notificationEvents": true } }
],
"action": {
"name": "connectConf",
"conferenceId": "myRoom",
"moh": "ring"
}
}PSTN Forward with AMD
带AMD的PSTN呼叫转移
json
{
"action": {
"name": "connectPstn",
"number": "+14045009000",
"cli": "+14045001000",
"maxDuration": 3600,
"amd": { "enabled": true }
}
}json
{
"action": {
"name": "connectPstn",
"number": "+14045009000",
"cli": "+14045001000",
"maxDuration": 3600,
"amd": { "enabled": true }
}
}Executable Scripts
可执行脚本
Bundled Node.js scripts (no external dependencies, uses Basic Auth):
bash
export SINCH_APPLICATION_KEY="your-app-key"
export SINCH_APPLICATION_SECRET="your-app-secret"
export SINCH_VOICE_REGION="global" # optional| Script | Description | Example |
|---|---|---|
| TTS callout | |
| Conference callout | |
| Get call details | |
| List voice numbers | |
内置Node.js脚本(无外部依赖,使用基础认证):
bash
export SINCH_APPLICATION_KEY="your-app-key"
export SINCH_APPLICATION_SECRET="your-app-secret"
export SINCH_VOICE_REGION="global" # 可选| 脚本 | 描述 | 示例 |
|---|---|---|
| TTS呼叫发起 | |
| 会议呼叫发起 | |
| 获取呼叫详情 | |
| 列出语音号码 | |
Gotchas and Best Practices
注意事项与最佳实践
- Callback URL must be publicly accessible. Use ngrok for local dev. Configure in Dashboard under Voice app settings.
- ONE action per SVAML response. Multiple instructions are fine. Chain callbacks for sequential actions (ICE → ACE → PIE).
- ACE not sent for in-app destinations. ACE is not issued when destination type is , only for PSTN/SIP. Setting
usernamehas no effect for in-app destinations.enableAce: true - DiCE is fire-and-forget. Informational only. No SVAML response expected. Use for logging/cleanup.
- Regional endpoints matter. Wrong region increases latency. Conference rooms have regional scope — force all participants to the same region for cross-region conferences.
- Instruction ordering matters. Array order = execution order. Place before
answer; placeplayFilesbefore the connecting action.startRecording - Max call duration: 14400 seconds (4 hours). Set on
maxDuration/connectPstnfor shorter limits.connectSip - Validate callback signatures in production. HMAC-SHA256 signature in header. See Callback Signing.
Authorization - for state. Carries key-value pairs across ICE, ACE, PIE, DiCE within a call session.
setCookie - does not support recording.
connectMxp/startRecordinginstructions are ignored withstopRecording.connectMxp - defaults.
runMenu:barge(input accepted during prompt).true:timeoutMillsms.5000 - AMD on .
connectPstnfor answering machine detection.amd: { enabled: true, async: true/false } - transcription.
startRecordingfor auto-transcription.transcriptionOptions: { enabled: true, locale: "en-US" } - Conference DTMF options. on
conferenceDtmfOptions/conferenceCalloutwith modes:connectConf(default),ignore,forward(sends PIE).detect - is required for TTS callouts to connect. The API accepts a TTS callout without a
cliparameter and returns a call ID, but the call will never reach the destination. Thecliis the number displayed as the incoming caller — use your verified number or your Dashboard-assigned number, in E.164 format (e.g.,cli). To test, register on the Sinch Dashboard and use the free number assigned to your app. See Assign your number."+14151112223333"
- 回调URL必须可公开访问。本地开发时可使用ngrok。在控制台的Voice应用设置中配置。
- 每个SVAML响应只能包含一个action。可以包含多个指令。通过链式回调实现顺序操作(ICE → ACE → PIE)。
- 应用内目标不会触发ACE。当目标类型为时,不会触发ACE事件,仅PSTN/SIP目标会触发。为应用内目标设置
username无效。enableAce: true - DiCE是通知型事件。仅用于信息告知,无需返回SVAML响应。可用于日志记录或清理操作。
- 区域端点很重要。错误的区域会增加延迟。会议室具有区域范围——跨区域会议需确保所有参会者使用同一区域。
- 指令顺序影响执行顺序。数组顺序即为执行顺序。在前执行
playFiles;在连接操作前执行answer。startRecording - 最大呼叫时长:14400秒(4小时)。可在/
connectPstn中设置connectSip以缩短时长限制。maxDuration - 生产环境需验证回调签名。头中的HMAC-SHA256签名。请参考回调签名。
Authorization - 使用存储状态。在ICE、ACE、PIE、DiCE事件之间的呼叫会话中携带键值对。
setCookie - 不支持录音。
connectMxp/startRecording指令在使用stopRecording时会被忽略。connectMxp - 默认值。
runMenu:barge(提示音播放期间可接受输入)。true:timeoutMills毫秒。5000 - 的AMD功能。
connectPstn用于答录机检测。amd: { enabled: true, async: true/false } - 的转录功能。
startRecording用于自动转录。transcriptionOptions: { enabled: true, locale: "en-US" } - 会议DTMF选项。/
conferenceCallout中的connectConf支持模式:conferenceDtmfOptions(默认)、ignore、forward(触发PIE)。detect - TTS呼叫发起需要。API接受不带
cli参数的TTS呼叫发起并返回呼叫ID,但呼叫永远无法接通。cli是显示给被叫方的来电号码——请使用已验证的号码或控制台分配给应用的号码,格式为E.164(例如cli)。测试时,请在Sinch控制台注册并使用应用分配的免费号码。请参考分配你的号码。"+14151112223333"
Links
相关链接
- Voice API Reference (Markdown)
- Voice API OpenAPI Spec (YAML)
- SVAML Actions | SVAML Instructions
- Callbacks | Callouts
- Authentication | Callback Signing
- Node.js SDK Reference
- Python SDK Reference
- Java SDK Reference
- .NET SDK Reference
- Voice Tutorials
- npm: @sinch/sdk-core | npm: @sinch/voice
- LLMs.txt (full docs index)