HoneyTian commited on
Commit
26dfa9a
1 Parent(s): 0e20c8d
README.md CHANGED
@@ -13,17 +13,21 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
13
  ### ASR
14
 
15
  ```text
16
- docker build -t asr:v20240510_1734 .
17
 
18
  docker run -itd --name ASR \
19
  --network host \
20
  -v /data/tianxing/PycharmProjects/asr/data/:/home/user/app/data/ \
21
  -v /data/tianxing/PycharmProjects/asr/pretrained_models/:/home/user/app/pretrained_models/ \
22
- asr:v20240510_1734 /bin/bash
23
 
24
  ```
25
 
26
 
 
 
 
 
27
  ### 异常1
28
 
29
  https://blog.csdn.net/sinat_28442665/article/details/126154991
 
13
  ### ASR
14
 
15
  ```text
16
+ docker build -t asr:v20240511_1022 .
17
 
18
  docker run -itd --name ASR \
19
  --network host \
20
  -v /data/tianxing/PycharmProjects/asr/data/:/home/user/app/data/ \
21
  -v /data/tianxing/PycharmProjects/asr/pretrained_models/:/home/user/app/pretrained_models/ \
22
+ asr:v20240511_1022 /bin/bash
23
 
24
  ```
25
 
26
 
27
+ ```text
28
+ docker cp ASR:/tmp/asr/si_chuan_hua.wav /home/nlp
29
+ ```
30
+
31
  ### 异常1
32
 
33
  https://blog.csdn.net/sinat_28442665/article/details/126154991
examples/wenet/toolbox_infer.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python3
2
+ # -*- coding: utf-8 -*-
3
+ import argparse
4
+ import os
5
+ from pathlib import Path
6
+ import sys
7
+ import tempfile
8
+
9
+ pwd = os.path.abspath(os.path.dirname(__file__))
10
+ sys.path.append(os.path.join(pwd, "../../"))
11
+
12
+ import librosa
13
+ import numpy as np
14
+ import sherpa
15
+ from scipy.io import wavfile
16
+ import torch
17
+ import torchaudio
18
+
19
+ from project_settings import project_path, temp_directory
20
+ from toolbox.k2_sherpa.utils import audio_convert
21
+ from toolbox.k2_sherpa import decode, models
22
+
23
+
24
+ def get_args():
25
+ parser = argparse.ArgumentParser()
26
+ parser.add_argument(
27
+ "--model_dir",
28
+ default=(project_path / "pretrained_models/huggingface/csukuangfj/wenet-chinese-model").as_posix(),
29
+ type=str
30
+ )
31
+ parser.add_argument(
32
+ "--in_filename",
33
+ default=(project_path / "data/test_wavs/paraformer-zh/si_chuan_hua.wav").as_posix(),
34
+ type=str
35
+ )
36
+ parser.add_argument("--sample_rate", default=16000, type=int)
37
+ args = parser.parse_args()
38
+ return args
39
+
40
+
41
+ def main():
42
+ args = get_args()
43
+
44
+ # audio convert
45
+ in_filename = Path(args.in_filename)
46
+ out_filename = Path(tempfile.gettempdir()) / "asr" / in_filename.name
47
+ out_filename.parent.mkdir(parents=True, exist_ok=True)
48
+
49
+ audio_convert(in_filename=in_filename.as_posix(),
50
+ out_filename=out_filename.as_posix(),
51
+ )
52
+
53
+ # load recognizer
54
+ m_dict = models.model_map["Chinese"][0]
55
+
56
+ local_model_dir = Path(args.model_dir)
57
+ nn_model_file = local_model_dir / m_dict["nn_model_file"]
58
+ tokens_file = local_model_dir / m_dict["tokens_file"]
59
+
60
+ recognizer = models.load_recognizer(
61
+ repo_id=m_dict["repo_id"],
62
+ nn_model_file=nn_model_file.as_posix(),
63
+ tokens_file=tokens_file.as_posix(),
64
+ sub_folder=m_dict["sub_folder"],
65
+ local_model_dir=local_model_dir,
66
+ recognizer_type=m_dict["recognizer_type"],
67
+ decoding_method="greedy_search",
68
+ num_active_paths=2,
69
+ )
70
+
71
+ text = decode.decode_by_recognizer(recognizer=recognizer,
72
+ filename=out_filename.as_posix(),
73
+ )
74
+ print("text: {}".format(text))
75
+ return
76
+
77
+
78
+ if __name__ == "__main__":
79
+ main()
start.sh ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+
3
+ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/python3.8/site-packages/k2/lib/
4
+
5
+ rm -rf logs/
6
+
7
+ python3 run_asr_server.py
stop.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/usr/bin/env bash
2
+
3
+ kill -9 `ps -aef | grep 'run_asr_server.py' | grep -v grep | awk '{print $2}'`
toolbox/k2_sherpa/models.py CHANGED
@@ -80,6 +80,7 @@ def load_sherpa_offline_recognizer(nn_model_file: str,
80
  )
81
 
82
  recognizer = sherpa.OfflineRecognizer(config)
 
83
  return recognizer
84
 
85
 
 
80
  )
81
 
82
  recognizer = sherpa.OfflineRecognizer(config)
83
+
84
  return recognizer
85
 
86