{"id":71,"date":"2025-11-27T00:01:12","date_gmt":"2025-11-26T16:01:12","guid":{"rendered":"http:\/\/81.68.81.149\/?p=71"},"modified":"2025-11-27T00:01:14","modified_gmt":"2025-11-26T16:01:14","slug":"%e5%9c%a8sherpa_onnx_asr-%e4%b8%ad%e6%94%af%e6%8c%81-fireredasr","status":"publish","type":"post","link":"http:\/\/81.68.81.149\/index.php\/2025\/11\/27\/%e5%9c%a8sherpa_onnx_asr-%e4%b8%ad%e6%94%af%e6%8c%81-fireredasr\/","title":{"rendered":"\u5728Sherpa_onnx_asr \u4e2d\u652f\u6301 FireredASR"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">FireredASR \u96c6\u6210\u603b\u7ed3<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">1. \u4fee\u6539 ASR \u5b9e\u73b0\u7c7b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6587\u4ef6\uff1a<\/strong> sherpa_onnx_asr.py<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 \u6dfb\u52a0\u6784\u9020\u51fd\u6570\u53c2\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">def __init__(<br> &nbsp; &nbsp;self,<br> &nbsp; &nbsp;# ... \u5176\u4ed6\u53c2\u6570 ...<br> &nbsp; &nbsp;fire_red_asr_encoder: str = \"\",<br> &nbsp; &nbsp;fire_red_asr_decoder: str = \"\",<br> &nbsp; &nbsp;# ... \u5176\u4ed6\u53c2\u6570 ...<br>):<br> &nbsp; &nbsp;# ... \u5176\u4ed6\u521d\u59cb\u5316\u4ee3\u7801 ...<br> &nbsp; &nbsp;self.fire_red_asr_encoder = fire_red_asr_encoder<br> &nbsp; &nbsp;self.fire_red_asr_decoder = fire_red_asr_decoder<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 \u5728 <code>_create_recognizer<\/code> \u65b9\u6cd5\u4e2d\u6dfb\u52a0\u5206\u652f<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">def _create_recognizer(self):<br> &nbsp; &nbsp;# ... \u5176\u4ed6 model_type \u7684\u5904\u7406 ...<br> &nbsp; &nbsp;<br> &nbsp; &nbsp;elif self.model_type == \"fire_red_asr\":<br> &nbsp; &nbsp; &nbsp; &nbsp;recognizer = sherpa_onnx.OfflineRecognizer.from_fire_red_asr(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;encoder=self.fire_red_asr_encoder,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;decoder=self.fire_red_asr_decoder,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tokens=self.tokens,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;num_threads=self.num_threads,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;decoding_method=self.decoding_method,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;debug=self.debug,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;provider=self.provider,<br> &nbsp; &nbsp; &nbsp;  )<br> &nbsp; &nbsp;<br> &nbsp; &nbsp;return recognizer<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u66f4\u65b0\u914d\u7f6e\u9a8c\u8bc1\u6a21\u578b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6587\u4ef6\uff1a<\/strong> asr.py<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 \u6dfb\u52a0\u5230 model_type \u679a\u4e3e<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">class SherpaOnnxASRConfig(BaseModel):<br> &nbsp; &nbsp;model_type: Literal[<br> &nbsp; &nbsp; &nbsp; &nbsp;\"transducer\",<br> &nbsp; &nbsp; &nbsp; &nbsp;\"paraformer\",<br> &nbsp; &nbsp; &nbsp; &nbsp;\"nemo_ctc\",<br> &nbsp; &nbsp; &nbsp; &nbsp;\"wenet_ctc\",<br> &nbsp; &nbsp; &nbsp; &nbsp;\"whisper\",<br> &nbsp; &nbsp; &nbsp; &nbsp;\"tdnn_ctc\",<br> &nbsp; &nbsp; &nbsp; &nbsp;\"sense_voice\",<br> &nbsp; &nbsp; &nbsp; &nbsp;\"fire_red_asr\", &nbsp;# \u65b0\u589e<br> &nbsp;  ] = Field(<br> &nbsp; &nbsp; &nbsp; &nbsp;default=\"sense_voice\",<br> &nbsp; &nbsp; &nbsp; &nbsp;description=\"Type of the ASR model\"<br> &nbsp;  )<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 \u6dfb\u52a0\u914d\u7f6e\u5b57\u6bb5<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"># FireredASR \u6a21\u578b\u8def\u5f84<br>fire_red_asr_encoder: str = Field(<br> &nbsp; &nbsp;default=\"\",<br> &nbsp; &nbsp;description=\"Path to the FireredASR encoder model (.onnx file)\"<br>)<br>fire_red_asr_decoder: str = Field(<br> &nbsp; &nbsp;default=\"\",<br> &nbsp; &nbsp;description=\"Path to the FireredASR decoder model (.onnx file)\"<br>)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 \u6dfb\u52a0\u9a8c\u8bc1\u903b\u8f91<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">@model_validator(mode=\"after\")<br>def check_model_paths(self) -&gt; \"SherpaOnnxASRConfig\":<br> &nbsp; &nbsp;# ... \u5176\u4ed6\u9a8c\u8bc1\u903b\u8f91 ...<br> &nbsp; &nbsp;<br> &nbsp; &nbsp;elif self.model_type == \"fire_red_asr\":<br> &nbsp; &nbsp; &nbsp; &nbsp;if not self.fire_red_asr_encoder:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise ValueError(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"fire_red_asr_encoder is required when model_type is 'fire_red_asr'\"<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  )<br> &nbsp; &nbsp; &nbsp; &nbsp;if not self.fire_red_asr_decoder:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise ValueError(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"fire_red_asr_decoder is required when model_type is 'fire_red_asr'\"<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  )<br> &nbsp; &nbsp; &nbsp; &nbsp;if not self.tokens:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise ValueError(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"tokens file is required when model_type is 'fire_red_asr'\"<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  )<br> &nbsp; &nbsp;<br> &nbsp; &nbsp;return self<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u66f4\u65b0\u914d\u7f6e\u6a21\u677f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6587\u4ef6\uff1a<\/strong> conf.default.yaml \u548c conf.ZH.default.yaml<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 \u6dfb\u52a0\u5230 model_type \u9009\u9879<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">sherpa_onnx_asr:<br>  model_type: 'sense_voice' &nbsp;# \u53ef\u9009\u503c\u5305\u542b: 'fire_red_asr'<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 \u6dfb\u52a0\u914d\u7f6e\u793a\u4f8b\uff08\u4e2d\u6587\u7248\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"># --- \u5bf9\u4e8e model_type: 'fire_red_asr' (FireredASR) ---<br># FireredASR (\u963f\u91cc\u8fbe\u6469\u9662 Paraformer) - \u9ad8\u6027\u80fd\u4e2d\u82f1\u6587\u8bc6\u522b<br># \u652f\u6301 fp16 \u548c int8 \u91cf\u5316\u7248\u672c<br># fire_red_asr_encoder: '.\/models\/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16\/encoder.int8.onnx'<br># fire_red_asr_decoder: '.\/models\/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16\/decoder.int8.onnx'<br># tokens: '.\/models\/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16\/tokens.txt'<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.3 \u6dfb\u52a0\u914d\u7f6e\u793a\u4f8b\uff08\u82f1\u6587\u7248\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"># --- For model_type: 'fire_red_asr' (FireredASR) ---<br># FireredASR (Alibaba DAMO Academy Paraformer) - High-performance Chinese\/English ASR<br># Supports fp16 and int8 quantized versions<br># fire_red_asr_encoder: '.\/models\/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16\/encoder.int8.onnx'<br># fire_red_asr_decoder: '.\/models\/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16\/decoder.int8.onnx'<br># tokens: '.\/models\/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16\/tokens.txt'<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u4e0b\u8f7d\u6a21\u578b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 huggingface-cli \u4e0b\u8f7d\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># int8 \u7248\u672c\uff08\u63a8\u8350 CPU\uff09<br>uv run hf download csukuangfj\/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16 --local-dir models\/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16<br>\u200b<br># fp16 \u7248\u672c\uff08\u9700\u8981 GPU \u652f\u6301\uff09<br>uv run hf download csukuangfj\/sherpa-onnx-fire-red-asr-large-zh_en-fp16-2025-02-16<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u5230\u9879\u76ee\u76ee\u5f55\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">xcopy \/E \/I \/Y \"C:\\Users\\&lt;username&gt;\\.cache\\huggingface\\hub\\models--csukuangfj--sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16\\snapshots\\&lt;hash&gt;\" \".\\models\\sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16\"<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u914d\u7f6e\u4f7f\u7528<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6587\u4ef6\uff1a<\/strong> conf.yaml<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">asr_config:<br>  asr_model: 'sherpa_onnx_asr'<br> &nbsp;<br>  sherpa_onnx_asr:<br> &nbsp;  model_type: 'fire_red_asr'<br> &nbsp; &nbsp;<br> &nbsp;  fire_red_asr_encoder: '.\/models\/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16\/encoder.int8.onnx'<br> &nbsp;  fire_red_asr_decoder: '.\/models\/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16\/decoder.int8.onnx'<br> &nbsp;  tokens: '.\/models\/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16\/tokens.txt'<br> &nbsp; &nbsp;<br> &nbsp;  num_threads: 4<br> &nbsp;  provider: 'cpu' &nbsp;# 'cpu' \u6216 'cuda'<br> &nbsp;  use_itn: False<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5173\u952e\u8981\u70b9<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6a21\u578b\u7c7b\u578b\uff1a<\/strong> FireredASR \u57fa\u4e8e\u963f\u91cc\u8fbe\u6469\u9662\u7684 Paraformer \u67b6\u6784<\/li>\n\n\n\n<li><strong>\u652f\u6301\u8bed\u8a00\uff1a<\/strong> \u4e2d\u6587\u3001\u82f1\u6587\u3001\u65b9\u8a00\uff08\u5ddd\u666e\u3001\u6d25\u666e\u3001\u8c6b\u666e\uff09<\/li>\n\n\n\n<li><strong>\u6a21\u578b\u89c4\u683c\uff1a<\/strong>\n<ul class=\"wp-block-list\">\n<li>int8\uff1a1.74GB\uff08\u63a8\u8350 CPU\uff09<\/li>\n\n\n\n<li>fp16\uff1a2.34GB\uff08\u9700\u8981 GPU \u4f46 sherpa-onnx \u9884\u7f16\u8bd1\u7248\u4e0d\u652f\u6301\uff09<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u52a0\u8f7d\u65f6\u95f4\uff1a<\/strong> \u7ea6 8 \u79d2\uff08\u9996\u6b21\u52a0\u8f7d\u6a21\u578b\u5230\u5185\u5b58\uff09<\/li>\n\n\n\n<li><strong>API \u53c2\u6570\uff1a<\/strong> \u4f7f\u7528 <code>encoder<\/code>\u3001<code>decoder<\/code>\u3001<code>tokens<\/code>\uff0c\u4e0d\u9700\u8981 <code>sample_rate<\/code>\/<code>feature_dim<\/code><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e0e\u5176\u4ed6\u6a21\u578b\u7684\u533a\u522b<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7279\u6027<\/th><th>SenseVoice<\/th><th>FireredASR<\/th><\/tr><\/thead><tbody><tr><td>\u67b6\u6784<\/td><td>CTC<\/td><td>Paraformer<\/td><\/tr><tr><td>\u8bed\u8a00<\/td><td>\u4e2d\u82f1\u65e5\u97e9\u7ca4<\/td><td>\u4e2d\u82f1+\u65b9\u8a00<\/td><\/tr><tr><td>\u914d\u7f6e\u53c2\u6570<\/td><td><code>sense_voice<\/code>, <code>use_itn=True<\/code><\/td><td><code>encoder<\/code>, <code>decoder<\/code><\/td><\/tr><tr><td>\u6a21\u578b\u6587\u4ef6<\/td><td>\u5355\u6587\u4ef6<\/td><td>\u53cc\u6587\u4ef6\uff08\u7f16\u7801\u5668+\u89e3\u7801\u5668\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u96c6\u6210\u5b8c\u6210\uff01\u2705<\/p>\n","protected":false},"excerpt":{"rendered":"<p>FireredASR \u96c6\u6210\u603b\u7ed3 1. \u4fee\u6539 ASR \u5b9e\u73b0\u7c7b \u6587\u4ef6\uff1a sherpa_onnx_asr.py 1. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":72,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-71","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn"],"_links":{"self":[{"href":"http:\/\/81.68.81.149\/index.php\/wp-json\/wp\/v2\/posts\/71","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/81.68.81.149\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/81.68.81.149\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/81.68.81.149\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/81.68.81.149\/index.php\/wp-json\/wp\/v2\/comments?post=71"}],"version-history":[{"count":1,"href":"http:\/\/81.68.81.149\/index.php\/wp-json\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":73,"href":"http:\/\/81.68.81.149\/index.php\/wp-json\/wp\/v2\/posts\/71\/revisions\/73"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/81.68.81.149\/index.php\/wp-json\/wp\/v2\/media\/72"}],"wp:attachment":[{"href":"http:\/\/81.68.81.149\/index.php\/wp-json\/wp\/v2\/media?parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/81.68.81.149\/index.php\/wp-json\/wp\/v2\/categories?post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/81.68.81.149\/index.php\/wp-json\/wp\/v2\/tags?post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}