PySilk (silk-python)
raw JSON → 0.2.8 verified Sat May 09 auth: no python
A Python binding for Silk, an audio codec originally developed by Skype. Supports encoding and decoding of Silk audio data (commonly used in Telegram voice messages). Current version 0.2.8; maintained on GitHub with occasional releases.
pip install silk-python Common errors
error ModuleNotFoundError: No module named 'silk' ↓
cause Library not installed or package name confusion.
fix
Run
pip install silk-python and import as import silk. error UnboundLocalError: local variable 'rate' referenced before assignment ↓
cause Missing `rate` argument when calling `encode`.
fix
Provide the sample rate:
encode(data, rate=24000). error 'dict' object has no attribute 'data' ↓
cause Using dot notation on dict returned by `decode`. It is a dict, not an object.
fix
Use pcm['data'] instead of pcm.data.
Warnings
gotcha The `decode` function returns a dict with keys 'data' (numpy array or bytes) and 'sample_rate'. Do not assume it returns raw bytes only. ↓
fix Access pcm['data'] and pcm['sample_rate'].
deprecated In v0.1.x, the API used `silk.decode(data)` returning bytes directly. In v0.2.x, it returns a dict. Code written for v0.1.x will break. ↓
fix Update to use pcm['data'] instead of pcm.
gotcha The `encode` function requires a `rate` parameter (sample rate). Common values: 24000, 16000, 8000. Omitting it may cause errors or wrong output. ↓
fix Always supply `rate` from decoded PCM sample_rate.
Imports
- encode wrong
from silk_python import encodecorrectfrom silk import encode - decode wrong
import silk; silk.decode()correctfrom silk import decode
Quickstart
import os
import asyncio
from silk import encode, decode
# Read binary data (example: from file)
with open('input.silk', 'rb') as f:
data = f.read()
# Decode Silk to PCM
pcm = decode(data)
# Encode PCM back to Silk
silk_data = encode(pcm['data'], rate=pcm['sample_rate'])
print(f"Decoded {len(pcm['data'])} samples, encoded back to {len(silk_data)} bytes.")