{"id":28180,"library":"silk-python","title":"PySilk (silk-python)","description":"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.","status":"active","version":"0.2.8","language":"python","source_language":"en","source_url":"https://github.com/synodriver/pysilk","tags":["audio","codec","silk","telegram","voip"],"install":[{"cmd":"pip install silk-python","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Module is named 'silk', not 'silk_python'.","wrong":"from silk_python import encode","symbol":"encode","correct":"from silk import encode"},{"note":"Common mistake: decode is a top-level function, not a method of the module.","wrong":"import silk; silk.decode()","symbol":"decode","correct":"from silk import decode"}],"quickstart":{"code":"import os\nimport asyncio\nfrom silk import encode, decode\n\n# Read binary data (example: from file)\nwith open('input.silk', 'rb') as f:\n    data = f.read()\n\n# Decode Silk to PCM\npcm = decode(data)\n\n# Encode PCM back to Silk\nsilk_data = encode(pcm['data'], rate=pcm['sample_rate'])\nprint(f\"Decoded {len(pcm['data'])} samples, encoded back to {len(silk_data)} bytes.\")","lang":"python","description":"Basic usage: read a Silk file, decode to PCM, then encode back to Silk."},"warnings":[{"fix":"Access pcm['data'] and pcm['sample_rate'].","message":"The `decode` function returns a dict with keys 'data' (numpy array or bytes) and 'sample_rate'. Do not assume it returns raw bytes only.","severity":"gotcha","affected_versions":"all"},{"fix":"Update to use pcm['data'] instead of pcm.","message":"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.","severity":"deprecated","affected_versions":"v0.2.x"},{"fix":"Always supply `rate` from decoded PCM sample_rate.","message":"The `encode` function requires a `rate` parameter (sample rate). Common values: 24000, 16000, 8000. Omitting it may cause errors or wrong output.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Run `pip install silk-python` and import as `import silk`.","cause":"Library not installed or package name confusion.","error":"ModuleNotFoundError: No module named 'silk'"},{"fix":"Provide the sample rate: `encode(data, rate=24000)`.","cause":"Missing `rate` argument when calling `encode`.","error":"UnboundLocalError: local variable 'rate' referenced before assignment"},{"fix":"Use pcm['data'] instead of pcm.data.","cause":"Using dot notation on dict returned by `decode`. It is a dict, not an object.","error":"'dict' object has no attribute 'data'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}