Skip to main content

SRTC Python SDK

English | 中文

SRTC is a real-time audio/video engine built for fully private deployment, with SDKs for every major platform, support for domestic (Xinchuang) OS and hardware, interoperability with legacy SIP/H.323 devices, and built-in AI Agent capabilities.

This SDK is for server-side AI: voice agents (ASR → LLM → TTS), recording, transcription and QA. Full documentation: docs.stmlink.com.

  • PCM in, PCM out — remote audio arrives decoded at the sample rate you choose; write TTS output as raw PCM. Codecs and resampling are handled inside the SDK.
  • Real-time pacing built in — however fast your TTS is, audio goes out one 20 ms frame at a time; clear() stops playback instantly when the user barges in.
  • Continuous timeline — silence the remote side suppresses (DTX) is filled back in by RTP timestamp, so VAD and recording durations stay correct.
  • asyncio native — async with to leave automatically, async for to consume frames, sync or async event handlers.
  • Native core — signaling, reconnection and media transport run in a bundled native library, behaving the same as every other SRTC SDK and staying off the GIL.
  • pipecat ready — a built-in pipecat transport drops into existing voice-agent pipelines.

Install

pip install srtc                # core
pip install "srtc[pipecat]"     # with pipecat integration

Python 3.10+. Linux x86_64 / aarch64, macOS Apple Silicon, Windows x64. Dependencies: cffi, av (bundles ffmpeg and libopus — no system ffmpeg needed), numpy.

Linux with glibc < 2.28 (e.g. CentOS 7): the latest av only ships wheels for glibc 2.28+. Pin it: pip install srtc "av>=12,<14".

Quick start

import asyncio
import srtc

async def main(token: str):   # token is issued by your backend via the SRTC server API
    async with await srtc.Channel.join(
        token,
        auto_subscribe_audio=True,                  # hear everyone, including later joiners
        audio_format=srtc.AudioFormat(16000, 1),    # PCM format you receive (default 16 kHz mono)
    ) as ch:
        tts = await ch.publish_audio(desc="tts", audio_format=srtc.AudioFormat(24000, 1))

        async for frame in ch.audio_frames():       # frame.uid tells you who is speaking
            text = asr.feed(frame.uid, frame.to_numpy())
            if text:
                await tts.write(await tts_engine.synthesize(await llm.chat(text)))

asyncio.run(main(token))

Each Channel.join needs a freshly issued token — a token is bound to one session.

Sending audio

await tts.write(pcm)            # any length; paced out in real time, back-pressure when the buffer is full
tts.clear()                     # user barged in: drop everything not yet sent
await tts.wait_for_playout()    # wait until everything written has been sent
tts.buffered_seconds            # > 0 while the agent is still "speaking"

Events — subclass srtc.ChannelHandler and override what you need (on_user_join, on_user_leave, on_track_added, on_audio_frame, on_active_speakers, on_custom_msg, on_disconnected, …), then pass handler= to Channel.join.

pipecat

from srtc.pipecat_transport import SRTCParams, SRTCTransport

transport = SRTCTransport(token, SRTCParams(audio_in_enabled=True, audio_out_enabled=True))
pipeline = Pipeline([transport.input(), stt, llm, tts, transport.output()])

Errors — failures raise srtc.SdkError with code, msg (English) and base_code: 180xxx are SDK errors whose last 3 digits (base_code, see srtc.ErrorCode) are shared across all SRTC SDKs (e.g. 180031 invalid argument); codes ≥ 1000 come from the server (e.g. 1033 concurrency limit reached). Check code / base_code, not the message text. srtc.set_language("en") sets the language of server error messages (sent as Accept-Language); by default it follows the system locale (LC_ALL / LC_MESSAGES / LANG).

Deployment notes — don't fork a process that has already created a Channel (use spawn with multiprocessing; importing before fork is fine). A single process handles about 20 concurrent channels at ~61% of one core; scale out with more processes.

See the documentation for the full API, the voice-agent guide and the pipecat guide.

License

Proprietary. Copyright © Seastart. Use requires an SRTC service license; copying, modification or redistribution without permission is prohibited. A free edition with limited concurrency is available; higher concurrency and private deployments require a commercial license — see stmlink.com.


SRTC Python SDK(中文)

English | 中文

SRTC 是一款支持完全私有化部署的实时音视频通信引擎,覆盖全平台 SDK,支持信创国产化,兼容传统 SIP/H.323 设备,集成 AI Agent 能力。

本 SDK 面向服务端 AI 场景:语音 agent(ASR → LLM → TTS)、录音、转写、质检。完整文档见 SRTC 文档中心。

  • 收发都是 PCM:远端音频按你指定的采样率解码后交给你;TTS 输出的 PCM 直接写进去,编解码、重采样都在 SDK 内完成。
  • SDK 控发送节奏:TTS 生成再快,也按实时节奏每 20ms 发一帧;用户插话时 clear() 立即停止播报。
  • 时间轴连续:对端 DTX 静音不发包时,SDK 按 RTP 时间戳补回静音帧,VAD 断句和录音时长都不会错位。
  • asyncio 原生:async with 自动离开、async for 逐帧消费,事件回调可以是普通函数也可以是 async 函数。
  • 原生内核:信令、断线重连、音视频收发由内置原生库完成,与 SRTC 其它端行为一致,不占 Python GIL。
  • 接入 pipecat:内置 pipecat transport,直接接进现有的语音 agent 管线。

安装

pip install srtc                # 核心
pip install "srtc[pipecat]"     # 同时安装 pipecat 集成

Python 3.10+。平台:Linux x86_64 / aarch64、macOS Apple Silicon、Windows x64。依赖:cffi、av(自带 ffmpeg 与 libopus,无需系统安装 ffmpeg)、numpy。

glibc 低于 2.28 的 Linux(如 CentOS 7):av 的新版本只提供 glibc 2.28+ 的安装包,请固定版本安装:pip install srtc "av>=12,<14"。

快速开始

import asyncio
import srtc

async def main(token: str):   # token 由你的业务服务端通过 SRTC 服务端 API 签发
    async with await srtc.Channel.join(
        token,
        auto_subscribe_audio=True,                  # 自动订阅所有人(含之后加入者)的音频
        audio_format=srtc.AudioFormat(16000, 1),    # 收到的 PCM 格式,默认 16k 单声道
    ) as ch:
        tts = await ch.publish_audio(desc="tts", audio_format=srtc.AudioFormat(24000, 1))

        async for frame in ch.audio_frames():       # 用 frame.uid 区分说话人
            text = asr.feed(frame.uid, frame.to_numpy())
            if text:
                await tts.write(await tts_engine.synthesize(await llm.chat(text)))

asyncio.run(main(token))

每次 Channel.join 都要用新签发的 Token,一个 Token 只绑定一次会话。

发送音频

await tts.write(pcm)            # 任意长度,按实时节奏发送;缓冲满时 write 会等待(背压)
tts.clear()                     # 用户插话:丢弃所有未发出的音频
await tts.wait_for_playout()    # 等待已写入的全部发完
tts.buffered_seconds            # 大于 0 表示 agent 还在"说话"

事件回调:继承 srtc.ChannelHandler,覆写需要的方法(on_user_join、on_user_leave、on_track_added、on_audio_frame、on_active_speakers、on_custom_msg、on_disconnected 等),在 Channel.join 时通过 handler= 传入。

pipecat

from srtc.pipecat_transport import SRTCParams, SRTCTransport

transport = SRTCTransport(token, SRTCParams(audio_in_enabled=True, audio_out_enabled=True))
pipeline = Pipeline([transport.input(), stt, llm, tts, transport.output()])

错误:失败时抛 srtc.SdkError,带 code、msg(英文)与 base_code。180xxx 为 SDK 自身错误,后三位(base_code,见 srtc.ErrorCode)各端 SDK 通用(如 180031 参数非法);≥1000 为服务端错误码(如 1033 并发已达上限)。请按 code / base_code 判断,不要按文案判断。srtc.set_language("en") 设置服务端错误文案的语言(以 Accept-Language 发送),不设置时跟随系统语言(LC_ALL / LC_MESSAGES / LANG)。

部署注意:已创建过 Channel 的进程不要再 fork(multiprocessing 请用 spawn;fork 前只 import 没问题)。单进程约 20 个频道同时在线时占约 61% 单核 CPU,会话更多请多进程横向扩展。

完整接口、语音 agent 实践与 pipecat 接入见 文档中心。

许可证

专有软件,版权归 Seastart 所有。使用需获得 SRTC 服务授权,未经许可不得复制、修改或再分发。SRTC 提供免费版(并发量受限),超出限额的并发与私有化部署需购买商业授权,详见 官网。

Metadata

Release files for srtc 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for srtc 0.2.4
File Actions
srtc-0.2.4-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for srtc-0.2.4-py3-none-win_amd64.whl
srtc-0.2.4-py3-none-manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for srtc-0.2.4-py3-none-manylinux2014_x86_64.whl
srtc-0.2.4-py3-none-manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for srtc-0.2.4-py3-none-manylinux2014_aarch64.whl
srtc-0.2.4-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for srtc-0.2.4-py3-none-macosx_11_0_arm64.whl

Total release size: 18.5 MB

Release files / srtc-0.2.4-py3-none-win_amd64.whl

Download URL srtc-0.2.4-py3-none-win_amd64.whl
Size 4.8 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
2d5337dd73c4a6bca82e179d24219cfc1e65f47b31cb90899e3f96b05ed30e88
BLAKE2b-256 checksum
How to use checksums
ba9480ee64a99612ba44d9b4a781e9ce674eafd48e32dd95810df14b7c957c49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / srtc-0.2.4-py3-none-manylinux2014_x86_64.whl

Download URL srtc-0.2.4-py3-none-manylinux2014_x86_64.whl
Size 4.9 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
4bdde82b26c830e3a43ed0a4abed98ad567b0664e4470f12edb239a075f885b7
BLAKE2b-256 checksum
How to use checksums
e3edd1b68a42e8bcb7c6ce115c284f4aa8506d5fd1f9b5362cbe46d0d2397619
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / srtc-0.2.4-py3-none-manylinux2014_aarch64.whl

Download URL srtc-0.2.4-py3-none-manylinux2014_aarch64.whl
Size 4.5 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
1f1ccbb8809543c8df51886776b043d7fb48f8df7fea756470d540241a9a3e41
BLAKE2b-256 checksum
How to use checksums
ab1f59d9a3d98cd2aadd79c2a70b419e5cc474200e517c2a88ad566f73a02001
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / srtc-0.2.4-py3-none-macosx_11_0_arm64.whl

Download URL srtc-0.2.4-py3-none-macosx_11_0_arm64.whl
Size 4.3 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5ca864008117bd17e381ed499d91cedae06442bba362efe7b254e6a2a4dffcca
BLAKE2b-256 checksum
How to use checksums
3f24a90513bdeadf8cbdbb1907581855cc91d6bcfc610e4b19f5077ec4b1a74e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for srtc 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page