{"library":"s3tokenizer","title":"S3Tokenizer","description":"S3Tokenizer is a Python library that provides a reverse-engineered PyTorch implementation of the Supervised Semantic Speech Tokenizer (S3Tokenizer), originally proposed in CosyVoice. It enables high-throughput batch inference and online speech code extraction. The current version is 0.3.0, and the library demonstrates a rapid release cadence, frequently adding support for newer CosyVoice versions and improving audio processing capabilities.","language":"python","status":"active","last_verified":"Tue May 12","install":{"commands":["pip install s3tokenizer"],"cli":null},"imports":["import s3tokenizer\ntokenizer = s3tokenizer.load_model(\"speech_tokenizer_v1\")","import s3tokenizer\naudio = s3tokenizer.load_audio(\"path/to/audio.wav\")"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import s3tokenizer\nimport os\n\n# Ensure PyTorch is available and CUDA is configured if using GPU\n# For demonstration, we'll try to use CUDA if available, otherwise CPU.\n# In a real scenario, you might want to explicitly set device or handle errors.\n\n# Assuming a dummy audio file for demonstration. \n# In a real use case, replace with your .wav file path.\n# You might need to create a dummy WAV file or download one from the S3Tokenizer repo assets.\n# For example, by downloading from: https://github.com/xingchensong/S3Tokenizer/blob/main/s3tokenizer/assets/BAC009S0764W0121.wav\n\n# Create a dummy .wav file if it doesn't exist for a runnable example\ndummy_wav_path = \"dummy_audio.wav\"\nif not os.path.exists(dummy_wav_path):\n    try:\n        import torchaudio\n        import torch\n        sample_rate = 16000\n        duration_seconds = 5\n        waveform = torch.randn(1, sample_rate * duration_seconds)\n        torchaudio.save(dummy_wav_path, waveform, sample_rate)\n        print(f\"Created dummy audio file: {dummy_wav_path}\")\n    except ImportError:\n        print(\"torchaudio or torch not found. Cannot create dummy audio. Please provide a real .wav file.\")\n        exit()\n\n\n# Load the tokenizer model, preferring CUDA if available\ndevice = \"cuda\" if torch.cuda.is_available() else \"cpu\"\ntokenizer = s3tokenizer.load_model(\"speech_tokenizer_v1\").to(device)\nprint(f\"Tokenizer model loaded on device: {device}\")\n\n# Load an audio file\n# Replace `dummy_wav_path` with your actual audio file path if not using the dummy\nif os.path.exists(dummy_wav_path):\n    audio = s3tokenizer.load_audio(dummy_wav_path)\n    audio = audio.to(device)\n    audio_len = torch.tensor([audio.shape[1]], device=device)\n\n    # Quantize the audio to get speech codes\n    speech_codes, speech_codes_lens = tokenizer.quantize(audio, audio_len)\n\n    print(f\"Shape of extracted speech codes: {speech_codes.shape}\")\n    print(f\"Length of speech codes: {speech_codes_lens.item()}\")\nelse:\n    print(f\"Error: Audio file not found at {dummy_wav_path}.\")","lang":"python","description":"This quickstart demonstrates how to load an S3Tokenizer model, load an audio file, and extract discrete speech codes from it. The example prioritizes GPU usage if available and includes a fallback to CPU. It also includes code to generate a dummy WAV file for immediate execution.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-12","installed_version":null,"pypi_latest":"0.3.0","is_stale":null,"summary":{"python_range":"3.10–3.9","success_rate":0,"avg_install_s":null,"avg_import_s":null,"wheel_type":null},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"s3tokenizer","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"s3tokenizer","exit_code":1,"wheel_type":null,"failure_reason":"timeout","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"s3tokenizer","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"s3tokenizer","exit_code":1,"wheel_type":null,"failure_reason":"timeout","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"s3tokenizer","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"s3tokenizer","exit_code":1,"wheel_type":null,"failure_reason":"timeout","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"s3tokenizer","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"s3tokenizer","exit_code":1,"wheel_type":null,"failure_reason":"timeout","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"s3tokenizer","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"s3tokenizer","exit_code":1,"wheel_type":null,"failure_reason":"timeout","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]}}