Skip to main content

Python client library for RACS

Project description

py-racs

PyPI - Version

py-racs is the python client library for RACS.

Installation

To install py-racs run:

pip install racs

Basic Operations

To open a connection, simply create a new Racs instance and provide the host and port.

from racs import Racs

r = Racs(host="localhost", port=6381)

Streaming

The pipeline function is used to chain together multiple RACS commands and execute them sequentially. In the below example, a new audio stream is created and opened. Then PCM data is chunked into frames and streamed to the RACS server.

from racs import Racs

# Connect to the RACS server
r = Racs(host="localhost", port=6381)

# Get pipeline
p = r.pipeline()

# Create a new audio stream using pipeline
p.create(stream_id="vocals", sample_rate=44100, channels=2, bit_depth=16).execute() 

# Reset pipeline
p.reset()

# // Prepare list of PCM samples (interleaved L/R, 16- or 24-bit integers)
data = [...]

# // Stream PCM data to the server
r.stream("vocals") \
    .chunk_size(1024 * 32) \ 
    .batch_size(50) \
    .compression(True) \
    .compression_level(8) \
    .execute(data)

If chunk_size, batch_size, compression and compression_level are not provided, the default values will be used.

# // Stream PCM data to the server
r.stream("vocals").execute(data)

Stream ids stored in RACS can be queried using the list command. list takes a glob pattern and returns a list of streams ids matching the pattern.

from racs import Racs

# Connect to the RACS server
r = Racs(host="localhost", port=6381)

# Get pipeline
p = r.pipeline()

# Run list command matching "*" pattern
res = p.list(pattern="*").execute()

# ['vocals']
print(res)

Extracting Audio

The below example extracts a 30-second PCM audio segment using the range command. It then encodes the data to MP3 and writes the resulting bytes to a file.

from racs import Racs

# Connect to the RACS server
r = Racs(host="localhost", port=6381)

# Get pipeline
p = r.pipeline()

# Extract PCM data
# Encode the audio to MP3
res = p.range(stream_id="vocals", start=0.0, duration=30.0) \
       .encode(mime_type="audio/mp3") \
       .execute()

# Write to a file
with open("vocals.mp3", "wb") as f:
    f.write(res)

Metadata

Stream metadata can be retrieved using the meta command. meta takes the stream id and metadata attribute as parameters.

from racs import Racs

# Connect to the RACS server
r = Racs(host="localhost", port=6381)

# Get pipeline
p = r.pipeline()

# Get sample rate attribute for stream
res = p.meta(stream_id="vocals", attr="sample_rate").execute()

# Print the sample rate
print(res) # 44100

The supported metadata attributes are:

Attribute Description
channels Channel count of the audio stream.
sample_rate Sample rate of the audio stream (Hz).
bit_depth Bit depth of the audio stream.
ref Reference timestamp (milliseconds UTC).
size Size of the uncompressed audio stream in bytes.

Raw Command Execution

To execute raw command strings, use the execute_command function.

from racs import Racs

r = Racs(host="localhost", port=6381)

res = r.execute_command("EVAL '(+ 1 2 3)'")

Refer to the documentation in RACS for the commands.

Project details


Download files

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

Source Distribution

racs-0.1.2.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

racs-0.1.2-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file racs-0.1.2.tar.gz.

File metadata

  • Download URL: racs-0.1.2.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for racs-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ac475e80f016b93a5978e32ce498e1f6392eecb8ef73568f69e68516120ef395
MD5 9e84ac1fd4e1e7181c0b149ce7104fef
BLAKE2b-256 92cb70dddca240887451262641bfcaeab5ff14f9fa286a06ccba6c8a41334b5f

See more details on using hashes here.

File details

Details for the file racs-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: racs-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for racs-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 99b44b54a6dee04ed8583077a96ce50ef5f26a1bb68d0b747b1c8fbc090786e2
MD5 27ef9f7e3d3acbffd51c5136cce33de7
BLAKE2b-256 b96ec54f964ca4d6db0548c14a2bb2cd8a967458f46e92de25b7656fd4033da7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page