{"library":"sherpa-onnx","title":"Sherpa ONNX","description":"sherpa-onnx is a next-generation speech recognition (ASR) and text-to-speech (TTS) toolkit built with k2 and ONNX Runtime. It provides high-performance, cross-platform inference for various state-of-the-art speech models, enabling real-time and offline processing. The library is actively maintained with frequent minor releases, often multiple times a week, reflecting rapid development and integration of new models and features. The current version is 1.12.38.","language":"python","status":"active","last_verified":"Mon May 18","install":{"commands":["pip install sherpa-onnx","pip install sherpa-onnx onnxruntime-gpu"],"cli":{"name":"sherpa-onnx","version":"sh: 1: sherpa-onnx: not found"}},"imports":["from sherpa_onnx import OfflineRecognizer","from sherpa_onnx import OfflineRecognizerConfig","from sherpa_onnx import FeatureConfig","from sherpa_onnx import OnlineRecognizer","from sherpa_onnx import VitsModel"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport wave\nimport urllib.request\nfrom sherpa_onnx import OfflineRecognizer, OfflineRecognizerConfig, FeatureConfig, SpeakerEmbeddingExtractorConfig, OfflineStream\n\n# --- Configuration and Model Download ---\n# This example uses a small, popular ASR model.\n# You can find more models at https://k2-fsa.github.io/sherpa-onnx/index.html\n\nMODEL_DIR = \"./sherpa-onnx-models/csukuangfj/sherpa-onnx-offline-zh-en-conformer-mix-init-transducer-2023-12-13\"\nMODEL_URL = \"https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.12.38/sherpa-onnx-offline-zh-en-conformer-mix-init-transducer-2023-12-13.tar.bz2\"\nMODEL_TAR_FILE = os.path.join(os.path.dirname(MODEL_DIR), os.path.basename(MODEL_URL))\nMODEL_FILES = {\n    \"encoder\": \"encoder-epoch-99-avg-1.onnx\",\n    \"decoder\": \"decoder-epoch-99-avg-1.onnx\",\n    \"joiner\": \"joiner-epoch-99-avg-1.onnx\",\n    \"tokens\": \"tokens.txt\"\n}\n\nAUDIO_FILE = \"./sherpa-onnx-models/test.wav\"\nAUDIO_URL = \"https://github.com/k2-fsa/sherpa-onnx/raw/master/sherpa-onnx/python/test.wav\"\n\ndef download_file_if_not_exists(url, filename):\n    if not os.path.exists(filename):\n        print(f\"Downloading {os.path.basename(filename)} from {url}...\")\n        os.makedirs(os.path.dirname(filename), exist_ok=True)\n        urllib.request.urlretrieve(url, filename)\n        print(\"Download complete.\")\n\ndef extract_tar_bz2(tar_path, extract_path):\n    if not os.path.exists(extract_path) or not os.listdir(extract_path):\n        print(f\"Extracting {os.path.basename(tar_path)} to {extract_path}...\")\n        import tarfile\n        with tarfile.open(tar_path, \"r:bz2\") as tar:\n            tar.extractall(path=extract_path)\n        print(\"Extraction complete.\")\n\n# Ensure model directory exists and models are downloaded/extracted\nos.makedirs(MODEL_DIR, exist_ok=True)\nif not all(os.path.exists(os.path.join(MODEL_DIR, f)) for f in MODEL_FILES.values()):\n    download_file_if_not_exists(MODEL_URL, MODEL_TAR_FILE)\n    extract_tar_bz2(MODEL_TAR_FILE, MODEL_DIR)\n\n# Ensure test audio exists\ndownload_file_if_not_exists(AUDIO_URL, AUDIO_FILE)\n\n# --- Recognizer Configuration ---\nfeat_config = FeatureConfig(sample_rate=16000, feature_dim=80)\n\nrecognizer_config = OfflineRecognizerConfig(\n    feat_config=feat_config,\n    model_config={\n        \"encoder\": os.path.join(MODEL_DIR, MODEL_FILES[\"encoder\"]),\n        \"decoder\": os.path.join(MODEL_DIR, MODEL_FILES[\"decoder\"]),\n        \"joiner\": os.path.join(MODEL_DIR, MODEL_FILES[\"joiner\"]),\n        \"tokens\": os.path.join(MODEL_DIR, MODEL_FILES[\"tokens\"]),\n        \"num_threads\": 1, # Use 1 thread for CPU inference\n        \"debug\": False\n    },\n    lm_config={},\n    transducer_config={},\n    decode_config={\n        \"method\": \"modified_beam_search\",\n        \"num_active_paths\": 4\n    }\n)\n\n# --- Create Recognizer and Process Audio ---\nrecognizer = OfflineRecognizer(recognizer_config)\n\n# Read the audio file\nwith wave.open(AUDIO_FILE, \"rb\") as f:\n    assert f.getframerate() == 16000, f.getframerate()\n    assert f.getnchannels() == 1, f.getnchannels()\n    assert f.getsampwidth() == 2, f.getsampwidth()\n    n_samples = f.getnframes()\n    audio_bytes = f.readframes(n_samples)\n\n# Create an audio stream and pass the audio data\nstream = recognizer.create_stream()\n# Data expects float32 array, scale int16 to float32 range\nimport numpy as np\nsamples = np.frombuffer(audio_bytes, dtype=np.int16).astype(np.float32) / 32768.0\nstream.accept_waveform(16000, samples)\n\n# Decode the stream\nrecognizer.decode_stream(stream)\n\n# Get the result\nresult = stream.result.text\nprint(f\"Recognition Result: {result}\")\n","lang":"python","description":"This quickstart demonstrates how to perform offline speech recognition using `sherpa-onnx`. It first ensures that a sample ASR model and an audio file are downloaded locally, then configures and initializes an `OfflineRecognizer`. Finally, it processes the sample audio file and prints the transcribed text. For GPU inference, install `onnxruntime-gpu` and ensure CUDA is properly set up.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-18","installed_version":"1.13.2","pypi_latest":"1.13.2","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":50,"avg_install_s":7.9,"avg_import_s":0.04,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"sherpa-onnx","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-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"sherpa-onnx","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":"sherpa-onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.4,"import_time_s":0.02,"mem_mb":1.9,"disk_size":"59M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"sherpa-onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":16,"import_time_s":0.03,"mem_mb":1.9,"disk_size":"656M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"sherpa-onnx","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-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"sherpa-onnx","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":"sherpa-onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.4,"import_time_s":0.05,"mem_mb":2.1,"disk_size":"61M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"sherpa-onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":11.1,"import_time_s":0.04,"mem_mb":2.1,"disk_size":"575M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"sherpa-onnx","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-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"sherpa-onnx","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":"sherpa-onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.2,"import_time_s":0.04,"mem_mb":1.8,"disk_size":"52M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"sherpa-onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":10.8,"import_time_s":0.05,"mem_mb":1.8,"disk_size":"563M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"sherpa-onnx","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-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"sherpa-onnx","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":"sherpa-onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.2,"import_time_s":0.03,"mem_mb":1.6,"disk_size":"52M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"sherpa-onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":11.6,"import_time_s":0.04,"mem_mb":1.6,"disk_size":"562M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"sherpa-onnx","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-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"sherpa-onnx","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":"sherpa-onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.7,"import_time_s":0.05,"mem_mb":1.9,"disk_size":"58M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"sherpa-onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":17.3,"import_time_s":0.03,"mem_mb":1.9,"disk_size":"814M"}]}}