From 28ccfbfc51068a663a80764e14074df5edf2b5ba Mon Sep 17 00:00:00 2001
From: kongdeqiang <kongdeqiang960204@163.com>
Date: 星期五, 13 三月 2026 17:41:41 +0800
Subject: [PATCH] 提交

---
 examples/aishell/paraformer/utils/text2token.py |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/examples/aishell/paraformer/utils/text2token.py b/examples/aishell/paraformer/utils/text2token.py
index 56c3913..c39db1e 100755
--- a/examples/aishell/paraformer/utils/text2token.py
+++ b/examples/aishell/paraformer/utils/text2token.py
@@ -8,6 +8,7 @@
 import codecs
 import re
 import sys
+import json
 
 is_python2 = sys.version_info[0] == 2
 
@@ -37,9 +38,7 @@
         help="number of characters to split, i.e., \
                         aabb -> a a b b with -n 1 and aa bb with -n 2",
     )
-    parser.add_argument(
-        "--skip-ncols", "-s", default=0, type=int, help="skip first n columns"
-    )
+    parser.add_argument("--skip-ncols", "-s", default=0, type=int, help="skip first n columns")
     parser.add_argument("--space", default="<space>", type=str, help="space symbol")
     parser.add_argument(
         "--non-lang-syms",
@@ -62,6 +61,12 @@
                         read from SI1279.PHN file -> "sil b r ih sil k s aa r er n aa l
                         sil t er n ih sil t ih v sil" """,
     )
+    parser.add_argument(
+        "--text_format",
+        default="text",
+        type=str,
+        help="text, jsonl",
+    )
     return parser
 
 
@@ -80,12 +85,13 @@
     else:
         f = codecs.getreader("utf-8")(sys.stdin if is_python2 else sys.stdin.buffer)
 
-    sys.stdout = codecs.getwriter("utf-8")(
-        sys.stdout if is_python2 else sys.stdout.buffer
-    )
+    sys.stdout = codecs.getwriter("utf-8")(sys.stdout if is_python2 else sys.stdout.buffer)
     line = f.readline()
     n = args.nchar
     while line:
+        if args.text_format == "jsonl":
+            data = json.loads(line.strip())
+            line = data["target"]
         x = line.split()
         print(" ".join(x[: args.skip_ncols]), end=" ")
         a = " ".join(x[args.skip_ncols :])

--
Gitblit v1.9.1