How to use Punctuation Models in FunASR #238
-
|
There are two types of punctuation models, offline and online.
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
inference_pipeline = pipeline(
task=Tasks.punctuation,
model='damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch'
)
rec_result = inference_pipeline(text_in='example/punc_example.txt')
print(rec_result)The "text_in" supports three formats: raw inputs, text files, url files.
Different from the offline model, the online model is used at each time of speech absence of voice activity detection(VAD) and In the following code , we mark puctuation points on the pseudo streaming text where "|" represents the split points of VAD. from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
inference_pipeline = pipeline(
task=Tasks.punctuation,
model='damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727'
)
inputs = "跨境河流是养育沿岸|人民的生命之源长期以来为帮助下游地区防灾减灾中方技术人员|在上游地区极为恶劣的自然条件下克服巨大困难甚至冒着生命危险|向印方提供汛期水文资料处理紧急事件中方重视印方在跨境河流问题上的关切|愿意进一步完善双方联合工作机制|凡是|中方能做的我们|都会去做而且会做得更好我请印度朋友们放心中国在上游的|任何开发利用都会经过科学|规划和论证兼顾上下游的利益"
vads = inputs.split("|")
rec_result_all="outputs:"
param_dict = {"cache": []}
for vad in vads:
rec_result = inference_pipeline(text_in=vad, param_dict=param_dict)
rec_result_all += rec_result['text']
print(rec_result_all) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Update for current FunASR ( The original 1. Offline punctuation restorationUse from funasr import AutoModel
model = AutoModel(
model="ct-punc",
device="cpu", # use "cuda" when available
disable_update=True,
)
text = "那今天的天气呢也是蛮好的啊你觉得怎么样呢我觉得还不错"
result = model.generate(input=text)[0]
print(result["text"])Output from the environment listed below:
Punctuation restoration is not text normalization. In particular, check product names and mixed-language tokens when exact spelling boundaries matter. 2. Online punctuation after VAD chunksThe online model needs the same dictionary object to be passed as from funasr import AutoModel
model = AutoModel(
model="iic/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727",
device="cpu",
disable_update=True,
)
chunks = [
"那今天的天气呢也是蛮好的啊",
"你觉得怎么样呢",
"我觉得还不错",
]
cache = {}
pieces = []
for chunk in chunks:
result = model.generate(input=chunk, cache=cache)[0]
pieces.append(result["text"])
print(repr(result["text"]))
print("".join(pieces))Verified per-chunk output: The comma or question mark can therefore appear at the start of the next returned piece. Append the pieces in order; do not strip their leading punctuation. Creating a fresh cache for each chunk produced no punctuation for the same three chunks. The realtime model deliberately keeps the unstable tail open, so the final piece may not end with a period. At the final speech endpoint, run the completed transcript once through offline 3. Add punctuation to a Paraformer ASR pipelineParaformer does not emit punctuation natively, so attach the model at construction time: from funasr import AutoModel
model = AutoModel(
model="paraformer-zh",
vad_model="fsmn-vad",
punc_model="ct-punc",
)
result = model.generate(input="audio.wav", batch_size_s=300)Do not add a separate punctuation model to SenseVoice, Fun-ASR-Nano, or Qwen3-ASR; those model families already emit punctuation natively. The current FunASR tutorial also has the concise The raw-string paths above were tested with Python 3.12.3, FunASR 1.3.14, ModelScope 1.38.1, and PyTorch 2.11.0 CPU. Text-file and URL routing in the original post belongs to the ModelScope pipeline API and is separate from these native |
Beta Was this translation helpful? Give feedback.
Update for current FunASR (
mainat1d8080a, verified on 2026-07-15).The original
modelscope.pipelineexamples above describe the ModelScope pipeline API. For current native FunASR code, the shortest path isAutoModel.1. Offline punctuation restoration
Use
ct-puncfor the current Chinese/English model:Output from the environment listed below:
resultalso containskeyandpunc_array. The current aliases are:ct-punc->i…