Python SDK for connecting to a Pion Voice Agent server via WebRTC + WHIP
Project description
streamcore (Python)
Python SDK for connecting to a streamcore server via WebRTC + WHIP, powered by aiortc.
Requirements
- Python 3.10+
Installation
pip install streamcore
Or install from source:
cd python-sdk
pip install -e .
Quick Start
import asyncio
import numpy as np
import streamcore
async def main():
def on_transcript(entry, all_entries):
print(f"[{entry.role}] {entry.text}")
client = streamcore.Client(
config=streamcore.Config(whip_endpoint="http://localhost:8080/whip"),
events=streamcore.EventHandler(
on_transcript=on_transcript,
on_error=lambda err: print(f"Error: {err}"),
),
)
await client.connect()
# Send a 20 ms frame of silence
pcm = np.zeros(streamcore.FRAME_SIZE, dtype=np.int16)
await client.send_pcm(pcm)
# Receive decoded audio from the agent
audio = await client.recv_pcm() # numpy int16 array
await client.disconnect()
asyncio.run(main())
API
Client(config?, events?)
Creates a new voice agent client.
Config
| Field | Type | Default | Description |
|---|---|---|---|
whip_endpoint |
str |
"http://localhost:8080/whip" |
WHIP signaling endpoint URL |
ice_servers |
list[str] |
["stun:stun.l.google.com:19302"] |
ICE server URLs |
EventHandler
| Callback | Signature | Description |
|---|---|---|
on_status_change |
(status: ConnectionStatus) -> None |
Fired when connection status changes |
on_transcript |
(entry: TranscriptEntry, all: list[TranscriptEntry]) -> None |
Fired on new or updated transcript |
on_error |
(error: Exception) -> None |
Fired on connection or server errors |
on_data_channel_message |
(msg: DataChannelMessage) -> None |
Fired for every raw DC message |
Methods
| Method | Description |
|---|---|
await client.connect(track?) |
Connect via WHIP. Optionally pass an aiortc audio track. |
await client.disconnect() |
Tear down connection and free resources. |
await client.send_pcm(pcm) |
Send a numpy int16 PCM buffer (mono 48 kHz) to the agent. |
await client.recv_pcm() |
Receive decoded PCM audio as a numpy int16 array. |
client.status |
Current ConnectionStatus. |
client.transcript |
Current conversation as list[TranscriptEntry]. |
client.remote_track |
Inbound audio track from the agent (available after connect). |
Audio Constants
| Constant | Value | Description |
|---|---|---|
SAMPLE_RATE |
48000 |
Audio sample rate in Hz |
CHANNELS |
1 |
Number of channels (mono) |
FRAME_SIZE |
960 |
Samples per 20 ms frame |
Audio I/O
The SDK handles aiortc track management, av.AudioFrame construction, and
resampling internally. Callers only deal with raw PCM data as numpy int16
arrays:
# Send microphone audio (960 samples = 20 ms at 48 kHz)
await client.send_pcm(pcm_int16)
# Receive agent audio
audio = await client.recv_pcm()
If you need direct track access (e.g. for a custom aiortc pipeline), pass
your own AudioStreamTrack via client.connect(user_track=my_track).
Dependencies
| Package | Purpose |
|---|---|
aiortc |
WebRTC stack |
aiohttp |
HTTP client for WHIP signaling |
av |
Audio frame encoding/decoding |
numpy |
PCM audio buffers |
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamcore-0.1.2.tar.gz.
File metadata
- Download URL: streamcore-0.1.2.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12cc6284a734f9b5e64758112f81808eaabf6426c842a3cfe27bc1cb94293730
|
|
| MD5 |
d332adae1d1229a20d06aadf4d721b7a
|
|
| BLAKE2b-256 |
bda2e48489ea29c2c5d8ce4cb0e6cc94b3deefd2cd9596a10f4d2ecce9a39b8f
|
Provenance
The following attestation bundles were made for streamcore-0.1.2.tar.gz:
Publisher:
publish.yml on streamcoreai/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
streamcore-0.1.2.tar.gz -
Subject digest:
12cc6284a734f9b5e64758112f81808eaabf6426c842a3cfe27bc1cb94293730 - Sigstore transparency entry: 1392797359
- Sigstore integration time:
-
Permalink:
streamcoreai/python-sdk@4bf008051ca5545439c7f6303dda46dec4cf4380 -
Branch / Tag:
refs/tags/0.0.2 - Owner: https://github.com/streamcoreai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4bf008051ca5545439c7f6303dda46dec4cf4380 -
Trigger Event:
release
-
Statement type:
File details
Details for the file streamcore-0.1.2-py3-none-any.whl.
File metadata
- Download URL: streamcore-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
439d68b5a323017d839483f590aff87b65300747efc3c0b782760a2ff395bee1
|
|
| MD5 |
125c44cdc672560a83a8a367a1f085ea
|
|
| BLAKE2b-256 |
253bc516e3084fe9ec45e060a7063175ecc1b6aabc662a68f09efc39c89b089b
|
Provenance
The following attestation bundles were made for streamcore-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on streamcoreai/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
streamcore-0.1.2-py3-none-any.whl -
Subject digest:
439d68b5a323017d839483f590aff87b65300747efc3c0b782760a2ff395bee1 - Sigstore transparency entry: 1392797379
- Sigstore integration time:
-
Permalink:
streamcoreai/python-sdk@4bf008051ca5545439c7f6303dda46dec4cf4380 -
Branch / Tag:
refs/tags/0.0.2 - Owner: https://github.com/streamcoreai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4bf008051ca5545439c7f6303dda46dec4cf4380 -
Trigger Event:
release
-
Statement type: