Skip to main content

PocketStation for Python

PocketStation captures one desktop application and an optional microphone as separate live audio stems. A single native Session can send those stems to Python model code, a remote browser, and a multistem recording without mixing their source identities.

The Python package uses the PocketStation Rust engine for capture, routing, timing, recording, and Relay transport. Your Python code owns the model and application logic.

Capture a desktop application

Install PocketStation:

python -m pip install pocketstation

Capture one application without opening a microphone or writing files:

import pocketstation

with pocketstation.capture(application="Spotify") as live:
    for frame in live.audio:
        print(frame.source_id, frame.stem_id)

Add microphone=True when you need the default microphone as a second independent stem. Add record_to="recordings" when you want each selected stem recorded. Both behaviors are off by default.

Handle permissions and source changes

PocketStation does not prompt during import or discovery. Check microphone permission without prompting through pocketstation.sources.microphone_permission_observation(), then let Source opening report the authoritative result. Application capture and microphone capture use separate permissions.

When an application or device disappears, PocketStation reports the change and does not switch to another Source. Stop the current Session, discover again, confirm any changed selection, and create a new Session. Store a discovered identity only for its reported persistence scope. Keep fallback and provider retry policy explicit and finite.

See Prepare and qualify each Python platform for the permission states, persistence scopes, and recovery sequence.

Debug a voice interruption

examples/debug_voice_ai.py sends a physical microphone to OpenAI Realtime without another voice framework. PocketStation keeps microphone input, generated assistant audio, and the selected browser's output as independent recorded stems. Provider events and media events share one monotonic timeline, so you can see whether delay occurred before the model, inside the provider, in local output, or after Relay delivery.

See the voice-agent debugger instructions. Run repository examples from a source checkout or source archive. The installed pocketstation-demo command is the packaged application-and-microphone demo.

python -m pip install 'pocketstation[transcription]'
pocketstation-demo

Transcribe both sides of a voice application

Install the transcription extra, then run the example:

python -m pip install 'pocketstation[transcription]'
python examples/transcribe_voice_app.py

The program asks which desktop voice application to inspect. It sends the application and microphone through one faster-whisper model, then labels each transcript with the source that produced it. It does not start Relay or write a recording.

The Session preserves each source while the transcriber processes both:

voice application ── faster-whisper ── transcript labeled "application"
physical microphone ─ faster-whisper ─ transcript labeled "microphone"

The complete composition is visible in examples/transcribe_voice_app.py. The example adapter imports faster_whisper.WhisperModel when transcription starts; the provider is not part of the pocketstation namespace.

This example does not debug turn handling, interruption, agent latency, or browser playout. PocketStation does not receive those events in this program.

Stream any application audio to a browser

Run the Relay example when you want another person to listen in a browser:

python examples/stream_any_app_audio.py

Choose any running application that is producing audio. The example publishes that application as one named AudioBus, waits for Relay readiness, and prints a single-use word code and browser URL. It does not open the microphone or record audio.

The example uses PocketStation's small, rate-limited demo service unless you set POCKETSTATION_CONTROL_URL and POCKETSTATION_RELAY_URL to services you operate. The shared URLs live in pocketstation_demo; application code does not contain service credentials.

Read application and microphone audio

Set the optional microphone and recording parameters when the workflow needs both sides:

import pocketstation

with pocketstation.capture(
    application="Zoom",
    microphone=True,
    record_to="recordings",
) as live:
    for frame in live.audio:
        print(frame.source_id, frame.stem_id)

The iterator receives audio through a native queue that holds 32 frames by default. If Python stops reading and the queue fills, PocketStation drops new frames and reports the queue depth, dropped-frame count, and discontinuity.

Send application-owned audio into a Session

Use audio_input() when your application already owns PCM, such as generated speech or audio received from a call provider:

session = pocketstation.Session(recording_root="recordings")
agent = session.audio_input("agent-output")
agent.output.record("agent")

with session.start():
    agent.write(samples)

The input uses finite preallocated Core buffers. Writes report full, closed, cancelled, and invalid-buffer outcomes explicitly.

Create an integration

Create a Connector when Session audio needs to reach an API, socket, file, or provider. Most Python integrations need only a send function or a small class; PocketStation supplies the worker, queue, delivery observations, and shutdown.

Pass one function when the destination is already open:

import pocketstation as pks
import pocketstation.aio as pks_aio


async def send_audio(frame: pks.AudioFrame) -> None:
    await socket.send(frame.samples)


destination = pks_aio.Connector(send=send_audio)
application.send_to(destination)

Subclass the synchronous or asyncio Connector when the provider opens and closes resources. The provider class owns its connection; the Session owns route delivery, lineage, observations, drain, abort, and joined shutdown:

class WebSocketConnector(pks_aio.Connector):
    def __init__(self, url, token):
        self.url, self.token = url, token

    async def start(self):
        self.socket = await connect(self.url, token=self.token)

    async def send(self, frame: pks.AudioFrame):
        await self.socket.send(frame.samples)

    async def stop(self):
        await self.socket.close()

Attach one configured object to one or more stems:

destination = WebSocketConnector(url, token)
application.send_to(destination)
microphone.send_to(destination)

PocketStation calls start() once, interleaves both source-aware stems through send(), and calls stop() once. A second Connector object creates a separate destination. See Create an integration for deadlines, failures, and the advanced SPI.

Python provider callbacks execute on off-realtime workers. They cannot be used as native capture callbacks. Use a compiled native extension for native provider code, or a managed process when crash isolation is required.

Use a Source when media enters the Session, an Operator when work transforms media or emits typed signals, and an Endpoint when an integration needs direct control of outbound delivery. The integration guide starts with the normal Connector API and introduces those advanced APIs only when the task requires them.

Use Relay from Python

Python creates and deletes RelaySessions through the typed HTTP control client. The shared Rust pocketstation-relay connector publishes media. The Go Relay service forwards WebRTC audio. Python does not encode Opus, write RTP, or own a second media plane.

The control client limits request duration and response size, redacts secrets, and provides matching synchronous and asyncio APIs.

Sync and asyncio

pocketstation and pocketstation.aio operate the same native Session. The asyncio namespace provides awaitable lifecycle, stream, Relay, provider, and audio-input operations without creating another audio queue.

Python callbacks still enter the interpreter. Capture, routing, recording, and Relay transport remain native-speed; arbitrary Python model code does not have the same execution cost as Rust.

Platform support

Area Support
Python 3.11 and newer
macOS Apple silicon Installed wheel, application capture, physical microphone, 10 ms voice capture, Relay, Chromium, and multistem recording tested
Linux Core application selection and 10 ms capture tested; installed Python distribution qualification in progress
Windows 11 ARM64 Core application selection and 10 ms capture tested in a VM; installed Python distribution and physical-device qualification in progress
WAN and TURN Not yet qualified

The native binding uses PocketStation Core 1.1.7 and the shared Relay Connector 0.1.5.

The Rust-to-Python audio read currently copies native samples into Python-owned bytes before exposing a memoryview. The view avoids another Python-side copy; the call into Python still copies samples and is not zero-copy.

Develop the SDK

uv sync --extra transcription
uv run pytest -q
uv run ruff check python tests examples
uv run ruff format --check python tests examples
uv run mypy python tests/qualification/typing_contract.py examples

Reference

  • RELEASE_NOTES.md — user-visible changes and upgrade guidance.
  • docs/README.md — task guides, concepts, operations, and API ownership.
  • Write application-owned audio — PCM input with explicit queue capacity and selective output cancellation.
  • Process audio and typed signals — Operators, named ports, generated audio, and finite model work.
  • Record and observe a Session — multistem outcomes, route metrics, and lifecycle events.
  • Keep each source identifiable — selection, persistence, timestamps, generations, and discontinuities.
  • Read events, metrics, outcomes, and errors — setup failure, live observations, and terminal results.
  • Prepare each platform — permissions, source persistence, explicit rediscovery, and fallback policy.
  • examples/README.md — runnable examples and prerequisites.
  • pocketstation.capture — concise application and microphone capture.
  • pocketstation.session — Session declarations and lifecycle.
  • pocketstation.graph — stems, ports, routes, and signal specifications.
  • pocketstation.connector — outbound provider authoring.
  • pocketstation.operator_authoring — computation authoring.
  • pocketstation.source_authoring — inbound provider authoring.
  • pocketstation.aio — asyncio APIs for the same engine.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pocketstation-0.1.3.tar.gz (241.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pocketstation-0.1.3-cp311-abi3-win_arm64.whl (4.5 MB view details)

Uploaded CPython 3.11+Windows ARM64

pocketstation-0.1.3-cp311-abi3-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.11+Windows x86-64

pocketstation-0.1.3-cp311-abi3-manylinux_2_34_x86_64.whl (9.4 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ x86-64

pocketstation-0.1.3-cp311-abi3-manylinux_2_34_aarch64.whl (9.0 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ ARM64

pocketstation-0.1.3-cp311-abi3-macosx_11_0_arm64.whl (5.2 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

pocketstation-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file pocketstation-0.1.3.tar.gz.

File metadata

  • Download URL: pocketstation-0.1.3.tar.gz
  • Upload date:
  • Size: 241.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pocketstation-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0a5677a61247a4e3ff02f28699ad3ed86fcc49dd1f659a5ba66ea14c5cf55142
MD5 46f39ff4eea0085deee1cc39d3757df2
BLAKE2b-256 6d7f0026eb48346b0a500ce59bdb0e38d355561165acd4f2e867ecd2be415124

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketstation-0.1.3.tar.gz:

Publisher: release.yml on pocketstation-io/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketstation-0.1.3-cp311-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for pocketstation-0.1.3-cp311-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 4c5105addfc7602833cf28b1f2e3a54a601992b26c1bfe8a77dc363d8e95fab0
MD5 5ff2988d8a9229e7332d31c176eac9ce
BLAKE2b-256 5d9927dbdf151fe02b57e98c5cf6119925fccc2cae91387569bb49b9a5447cf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketstation-0.1.3-cp311-abi3-win_arm64.whl:

Publisher: release.yml on pocketstation-io/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketstation-0.1.3-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pocketstation-0.1.3-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 849046bb1e5ad63ace51cbf64f7200d224b0163cc1b4599f0781038b8a365918
MD5 9cf72ff95b3133ee4b64ba41e34b7090
BLAKE2b-256 724d23a22de5960e5a4225f48c8644a61b0f2f6d883c9b1bd30cefdfbea97743

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketstation-0.1.3-cp311-abi3-win_amd64.whl:

Publisher: release.yml on pocketstation-io/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketstation-0.1.3-cp311-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pocketstation-0.1.3-cp311-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 67505af937346370276221585a2cc5c10db8afed5926739bce2eb8c6ca8a19fc
MD5 469354d61c48f1c4e0725405231899ca
BLAKE2b-256 bddfba5425948c39257592ba46cc531ec3c28c7e547febf5d7a9206a61ac17c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketstation-0.1.3-cp311-abi3-manylinux_2_34_x86_64.whl:

Publisher: release.yml on pocketstation-io/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketstation-0.1.3-cp311-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pocketstation-0.1.3-cp311-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 27df7f2ee4c8ab5498c61eea14e7c07aee59fe3c5dec9405996394df27c67be9
MD5 be7d8af5587a8e585af94bdf396d5671
BLAKE2b-256 569b82cafb9eff21adac18c33c9a1077c8b6b10a63582d3c8ffd1069e015907e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketstation-0.1.3-cp311-abi3-manylinux_2_34_aarch64.whl:

Publisher: release.yml on pocketstation-io/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketstation-0.1.3-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pocketstation-0.1.3-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4812aa28563e02714fc61e40c2d1a92bddf17350c99b8beb61702e8ef5634e71
MD5 d71b5e65c4ffef4240cd9c79c6960978
BLAKE2b-256 ad61fe6a1d6c0c14c04e738dbeee07b51284026676992a5c1f35cda162896d03

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketstation-0.1.3-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on pocketstation-io/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketstation-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pocketstation-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5ce60701ea2bbc03c95649f5b52031c2da23c7f7d1313c194ecfb52f5a165a0d
MD5 992eb740ca3f04acf17754465f8fa188
BLAKE2b-256 0aeb8ea3ecf78a920f03bd13c0dd704ad4913bbf1526835e73f6b313f6ab6c42

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketstation-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on pocketstation-io/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.4

7 files

This release

0.1.3 This release

7 files

0.1.2

7 files

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