This release is a pre-release and may not be stable for production use.
PyThaiASR
Python Thai Automatic Speech Recognition
PyThaiASR is a Python package for Automatic Speech Recognition with focus on Thai language. It have offline thai automatic speech recognition model.
License: Apache-2.0 License
Google Colab: Link Google colab
Model homepage: https://huggingface.co/airesearch/wav2vec2-large-xlsr-53-th
Install
pip install pythaiasr
By default, PyThaiASR uses Typhoon ASR powered by ONNX Runtime for low-latency, lightweight offline and realtime speech recognition on CPU and GPU. On first use, Typhoon model files are automatically downloaded to ~/pythaiasr-data/typhoon-asr-realtime/.
For PyTorch & Transformers models (Wav2Vec2 / Whisper): If you want to use the Wav2Vec2 or Whisper models:
pip install pythaiasr[torch]
For Wav2Vec2 with language model:
If you want to use wannaphong/wav2vec2-large-xlsr-53-th-cv8-* with a language model:
pip install pythaiasr[lm]
pip install https://github.com/kpu/kenlm/archive/refs/heads/master.zip
For live audio streaming: If you want to stream live audio from your microphone:
pip install pythaiasr[stream]
Usage
File-based ASR
from pythaiasr import asr
file = "sample.wav"
# Uses Typhoon ASR (FastConformer RNN-T ONNX) by default
print(asr(file))
# Or explicitly select another model (requires pythaiasr[torch])
# print(asr(file, model="airesearch/wav2vec2-large-xlsr-53-th"))
# print(asr(file, model="biodatlab/whisper-small-th-combined"))
Live Audio Streaming
Stream audio directly from your microphone/soundcard in real-time:
from pythaiasr import stream_asr
# Streams audio in real-time using Typhoon ASR by default
for transcription in stream_asr():
print(transcription, end=" ", flush=True)
# Press Ctrl+C to stop
Real-Time Streaming from File or Microphone
from pythaiasr import FastConformerRNNT, RealtimeStreamASR, stream_from_file, stream_from_mic
model = FastConformerRNNT(device="auto")
streamer = RealtimeStreamASR(model=model, step_sec=0.48)
# Simulate streaming from a pre-recorded audio file
stream_from_file(streamer, "sample.wav")
# Or stream live from microphone with sounddevice
# stream_from_mic(streamer)
API
asr
asr(data: str, model: str = _model_name, lm: bool=False, device: str=None, sampling_rate: int=16_000)
- data: path of sound file or numpy array of the voice
- model: The ASR model (default:
typhoon_asr) - lm: Use language model (for wav2vec2 models with LM)
- device: device (
auto,cpu,cuda) - sampling_rate: The sample rate
- return: thai text from ASR
stream_asr
stream_asr(model: str = _model_name, lm: bool=False, device: str=None, chunk_duration: float=None, sampling_rate: int=16_000)
- model: The ASR model (default:
typhoon_asr) - lm: Use language model (for wav2vec2 models with LM)
- device: device
- chunk_duration: Duration of each audio chunk in seconds (default: 0.48s for Typhoon, 5.0s for others)
- sampling_rate: The sample rate (default: 16000)
- yield: Thai text transcription from each audio chunk
Options for model
- typhoon_asr / typhoon-asr-realtime (default) - Typhoon FastConformer RNN-T ONNX model (offline & realtime)
- airesearch/wav2vec2-large-xlsr-53-th - AI RESEARCH - PyThaiNLP model (requires pythaiasr[torch])
- wannaphong/wav2vec2-large-xlsr-53-th-cv8-newmm - Thai Wav2Vec2 with CommonVoice V8 (newmm tokenizer) (requires pythaiasr[torch])
- wannaphong/wav2vec2-large-xlsr-53-th-cv8-deepcut - Thai Wav2Vec2 with CommonVoice V8 (deepcut tokenizer) (requires pythaiasr[torch])
- biodatlab/whisper-small-th-combined - Thai Whisper small model (requires pythaiasr[torch])
- biodatlab/whisper-th-medium-combined - Thai Whisper medium model (requires pythaiasr[torch])
- biodatlab/whisper-th-large-combined - Thai Whisper large model (requires pythaiasr[torch])
You can read about models from the list:
- typhoon-ai/typhoon-asr-realtime / wannaphong/typhoon-asr-realtime-onnx - Typhoon FastConformer RNN-T ONNX model
- airesearch/wav2vec2-large-xlsr-53-th - AI RESEARCH - PyThaiNLP model
- annaphong/wav2vec2-large-xlsr-53-th-cv8-newmm - Thai Wav2Vec2 with CommonVoice V8 (newmm tokenizer) + language model
- wannaphong/wav2vec2-large-xlsr-53-th-cv8-deepcut - Thai Wav2Vec2 with CommonVoice V8 (deepcut tokenizer) + language model
- biodatlab/whisper-small-th-combined - Thai Whisper small model
- biodatlab/whisper-th-medium-combined - Thai Whisper medium model
- biodatlab/whisper-th-large-combined - Thai Whisper large model
Docker
To use this inside of Docker do the following:
docker build -t <Your Tag name> .
docker run docker run --entrypoint /bin/bash -it <Your Tag name>
You will then get access to a interactive shell environment where you can use python with all packages installed.
Release files for pythaiasr 2.0.0b1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pythaiasr-2.0.0b1.tar.gz | 24.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pythaiasr-2.0.0b1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 45.1 kB
Release files / pythaiasr-2.0.0b1.tar.gz
| Download URL | pythaiasr-2.0.0b1.tar.gz |
|---|---|
| Size | 24.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
935ee6d2dcb711985981f3b7276492d0e91eb4d28e583c30cee0d83c7dd583bb
|
|
BLAKE2b-256 checksum How to use checksums |
92ad1afba53207adc3ecdd27404781612ec6ff23ffdeaa0ac0e9f13ba97e8871
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pythaiasr-2.0.0b1-py3-none-any.whl
| Download URL | pythaiasr-2.0.0b1-py3-none-any.whl |
|---|---|
| Size | 20.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a207eb8473f18bd9465e198931231aaad75c69131af26095b70383a354ae73c7
|
|
BLAKE2b-256 checksum How to use checksums |
853ad4819e351e062f647c7e29fa5f47ac4fd125d072bedc9139d9b1381f8ecd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|