ONNXRuntime-python
Install funasr-onnx
funasr-onnx is a separate distribution from funasr. Upgrading funasr
does not update the installed ONNX wrappers. Check their versions separately
with python -m pip show funasr-onnx funasr; use the source installation below
when a required wrapper fix is newer than the published PyPI package.
Version 0.4.7 includes the Contextual/Seaco Paraformer hotword batching fix (#3838), including empty hotword-file handling. This is a runtime wrapper fix, not a model-weight update or an ASR accuracy claim.
Version 0.4.6 fixes offline FSMN-VAD calls with multiple inputs so each waveform is scored independently and returns one independent result per input. Requested batch sizes remain accepted, while the effective model batch remains 1 (#3831).
Version 0.4.5 also fixes streaming Paraformer crashes on short packets that have not produced a feature frame yet. Buffered audio and final cache flushing are preserved (#3827).
Version 0.4.4 includes the streaming Paraformer zero-overlap cache and empty-final result fixes, short/final VAD handling and stream-cache reset, and corrected timestamp alignment and rich-transcription event handling. These are wrapper and postprocessing fixes, not a model-weight update or an ASR accuracy claim.
install from pip
pip install -U "funasr-onnx>=0.4.7"
# For the users in China, you could install with the command:
# pip install -U "funasr-onnx>=0.4.7" -i https://mirror.sjtu.edu.cn/pypi/web/simple
# If you want to export .onnx file, you should install modelscope and funasr
pip install -U modelscope funasr
# For the users in China, you could install with the command:
# pip install -U modelscope funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple
or install from source code
git clone https://github.com/modelscope/FunASR.git
cd FunASR/runtime/python/onnxruntime
pip install -e ./
# For the users in China, you could install with the command:
# pip install -e ./ -i https://mirror.sjtu.edu.cn/pypi/web/simple
Inference with runtime
Speech Recognition
Paraformer
from funasr_onnx import Paraformer
from pathlib import Path
model_dir = "damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch"
model = Paraformer(model_dir, batch_size=1, quantize=True)
wav_path = ['{}/.cache/modelscope/hub/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch/example/asr_example.wav'.format(Path.home())]
result = model(wav_path)
print(result)
model_dir: model_name in modelscope or local path downloaded from modelscope. If the local path is set, it should containmodel.onnx,config.yaml,am.mvnbatch_size:1(Default), the batch size duration inferencedevice_id:-1(Default), infer on CPU. If you want to infer with GPU, set it to gpu_id (Please make sure that you have install the onnxruntime-gpu)quantize:False(Default), load the model ofmodel.onnxinmodel_dir. If setTrue, load the model ofmodel_quant.onnxinmodel_dirintra_op_num_threads:4(Default), sets the number of threads used for intraop parallelism on CPU
Input: wav formt file, support formats: str, np.ndarray, List[str]
Output: List[str]: recognition result
Paraformer-online
Voice Activity Detection
FSMN-VAD
from funasr_onnx import Fsmn_vad
from pathlib import Path
model_dir = "damo/speech_fsmn_vad_zh-cn-16k-common-pytorch"
wav_path = '{}/.cache/modelscope/hub/damo/speech_fsmn_vad_zh-cn-16k-common-pytorch/example/vad_example.wav'.format(Path.home())
model = Fsmn_vad(model_dir)
result = model(wav_path)
print(result)
model_dir: model_name in modelscope or local path downloaded from modelscope. If the local path is set, it should containmodel.onnx,config.yaml,am.mvnbatch_size:1(Default), the batch size duration inferencedevice_id:-1(Default), infer on CPU. If you want to infer with GPU, set it to gpu_id (Please make sure that you have install the onnxruntime-gpu)quantize:False(Default), load the model ofmodel.onnxinmodel_dir. If setTrue, load the model ofmodel_quant.onnxinmodel_dirintra_op_num_threads:4(Default), sets the number of threads used for intraop parallelism on CPU
Input: wav formt file, support formats: str, np.ndarray, List[str]
Output: List[str]: recognition result
FSMN-VAD-online
from funasr_onnx import Fsmn_vad_online
import soundfile
from pathlib import Path
model_dir = "damo/speech_fsmn_vad_zh-cn-16k-common-pytorch"
wav_path = '{}/.cache/modelscope/hub/damo/speech_fsmn_vad_zh-cn-16k-common-pytorch/example/vad_example.wav'.format(Path.home())
model = Fsmn_vad_online(model_dir)
##online vad
speech, sample_rate = soundfile.read(wav_path)
speech_length = speech.shape[0]
#
sample_offset = 0
step = 1600
param_dict = {'in_cache': []}
for sample_offset in range(0, speech_length, min(step, speech_length - sample_offset)):
if sample_offset + step >= speech_length - 1:
step = speech_length - sample_offset
is_final = True
else:
is_final = False
param_dict['is_final'] = is_final
segments_result = model(audio_in=speech[sample_offset: sample_offset + step],
param_dict=param_dict)
if segments_result:
print(segments_result)
model_dir: model_name in modelscope or local path downloaded from modelscope. If the local path is set, it should containmodel.onnx,config.yaml,am.mvnbatch_size:1(Default), the batch size duration inferencedevice_id:-1(Default), infer on CPU. If you want to infer with GPU, set it to gpu_id (Please make sure that you have install the onnxruntime-gpu)quantize:False(Default), load the model ofmodel.onnxinmodel_dir. If setTrue, load the model ofmodel_quant.onnxinmodel_dirintra_op_num_threads:4(Default), sets the number of threads used for intraop parallelism on CPU
Input: wav formt file, support formats: str, np.ndarray, List[str]
Output: List[str]: recognition result
Punctuation Restoration
CT-Transformer
from funasr_onnx import CT_Transformer
model_dir = "damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch"
model = CT_Transformer(model_dir)
text_in="è·¨å¢æ²³æµæ¯å
»è²æ²¿å²¸äººæ°ççå½ä¹æºé¿æä»¥æ¥ä¸ºå¸®å©ä¸æ¸¸å°åºé²ç¾åç¾ä¸æ¹ææ¯äººåå¨ä¸æ¸¸å°åºæä¸ºæ¶å£çèªç¶æ¡ä»¶ä¸å
æå·¨å¤§å°é¾çè³åççå½å±é©åå°æ¹æä¾æ±ææ°´æèµæå¤çç´§æ¥äºä»¶ä¸æ¹éè§å°æ¹å¨è·¨å¢æ²³æµé®é¢ä¸çå
³åæ¿æè¿ä¸æ¥å®ååæ¹èå工使ºå¶å¡æ¯ä¸æ¹è½åçæä»¬é½ä¼å»åèä¸ä¼å徿´å¥½æè¯·å°åº¦æå们æ¾å¿ä¸å½å¨ä¸æ¸¸çä»»ä½å¼åå©ç¨é½ä¼ç»è¿ç§å¦è§åå论è¯å
¼é¡¾ä¸ä¸æ¸¸çå©ç"
result = model(text_in)
print(result[0])
model_dir: model_name in modelscope or local path downloaded from modelscope. If the local path is set, it should containmodel.onnx,config.yaml,am.mvndevice_id:-1(Default), infer on CPU. If you want to infer with GPU, set it to gpu_id (Please make sure that you have install the onnxruntime-gpu)quantize:False(Default), load the model ofmodel.onnxinmodel_dir. If setTrue, load the model ofmodel_quant.onnxinmodel_dirintra_op_num_threads:4(Default), sets the number of threads used for intraop parallelism on CPU
Input: str, raw text of asr result
Output: List[str]: recognition result
CT-Transformer-online
from funasr_onnx import CT_Transformer_VadRealtime
model_dir = "damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727"
model = CT_Transformer_VadRealtime(model_dir)
text_in = "è·¨å¢æ²³æµæ¯å
»è²æ²¿å²¸|人æ°ççå½ä¹æºé¿æä»¥æ¥ä¸ºå¸®å©ä¸æ¸¸å°åºé²ç¾åç¾ä¸æ¹ææ¯äººå|å¨ä¸æ¸¸å°åºæä¸ºæ¶å£çèªç¶æ¡ä»¶ä¸å
æå·¨å¤§å°é¾çè³åççå½å±é©|åå°æ¹æä¾æ±ææ°´æèµæå¤çç´§æ¥äºä»¶ä¸æ¹éè§å°æ¹å¨è·¨å¢æ²³æµ>é®é¢ä¸çå
³å|æ¿æè¿ä¸æ¥å®ååæ¹èå工使ºå¶|塿¯|䏿¹è½åçæä»¬|é½ä¼å»åèä¸ä¼å徿´å¥½æè¯·å°åº¦æå们æ¾å¿ä¸å½å¨ä¸æ¸¸ç|ä»»ä½å¼åå©ç¨é½ä¼ç»è¿ç§å¦|è§åå论è¯å
¼é¡¾ä¸ä¸æ¸¸çå©ç"
vads = text_in.split("|")
rec_result_all=""
param_dict = {"cache": []}
for vad in vads:
result = model(vad, param_dict=param_dict)
rec_result_all += result[0]
print(rec_result_all)
model_dir: model_name in modelscope or local path downloaded from modelscope. If the local path is set, it should containmodel.onnx,config.yaml,am.mvndevice_id:-1(Default), infer on CPU. If you want to infer with GPU, set it to gpu_id (Please make sure that you have install the onnxruntime-gpu)quantize:False(Default), load the model ofmodel.onnxinmodel_dir. If setTrue, load the model ofmodel_quant.onnxinmodel_dirintra_op_num_threads:4(Default), sets the number of threads used for intraop parallelism on CPU
Input: str, raw text of asr result
Output: List[str]: recognition result
Performance benchmark
Please ref to benchmark
Acknowledge
- This project is maintained by FunASR community.
- We partially refer SWHL for onnxruntime (only for paraformer model).
Metadata
Release files for funasr-onnx 0.4.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| funasr_onnx-0.4.7.tar.gz | 38.1 kB | Without provenance | Details for funasr_onnx-0.4.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| funasr_onnx-0.4.7-py3-none-any.whl | Python 3 | none | any | Details for funasr_onnx-0.4.7-py3-none-any.whl |
Total release size: 81.2 kB
Release files / funasr_onnx-0.4.7.tar.gz
| Download URL | funasr_onnx-0.4.7.tar.gz |
|---|---|
| Size | 38.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e98e2bbbe52562f5601c3b9283426448474a9d18e7b670265c6fdc503cabcd2a
|
|
BLAKE2b-256 checksum How to use checksums |
48474af9558a7d75f1c14dcf9a83f418530e3ba17321fbf99ae70c09112a508c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / funasr_onnx-0.4.7-py3-none-any.whl
| Download URL | funasr_onnx-0.4.7-py3-none-any.whl |
|---|---|
| Size | 43.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e3247e04f1eaeac196c7e61ee466fa3ad8127bc46edf12b5e245eb37d465689d
|
|
BLAKE2b-256 checksum How to use checksums |
9e56c1daf60284cd7e61e4f287272ca628e8a004f6f6aebc9b9a51963f6cbed8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for funasr-onnx 0.4.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.