| | |
| | | import torch |
| | | from pathlib import Path |
| | | from funasr_torch import Paraformer |
| | | from funasr_torch.paraformer_bin import ContextualParaformer |
| | | |
| | | model_dir = "damo/speech_paraformer-large-contextual_asr_nat-zh-cn-16k-common-vocab8404" |
| | | model = Paraformer(model_dir, batch_size=1) # cpu |
| | | # model = Paraformer(model_dir, batch_size=1, device_id=0) # gpu |
| | | model_dir = "iic/speech_paraformer-large-contextual_asr_nat-zh-cn-16k-common-vocab8404" |
| | | device_id = 0 if torch.cuda.is_available() else -1 |
| | | model = ContextualParaformer(model_dir, batch_size=1, device_id=device_id) # gpu |
| | | |
| | | wav_path = "{}/.cache/modelscope/hub/{}/example/asr_example.wav".format(Path.home(), model_dir) |
| | | hotwords = "你的热词 魔搭" |
| | | hotwords = "你的热词 魔搭 达摩苑" |
| | | |
| | | result = model(wav_path, hotwords) |
| | | print(result) |
| | |
| | | from pathlib import Path |
| | | from funasr_torch import Paraformer |
| | | from funasr_torch.paraformer_bin import Paraformer |
| | | |
| | | model_dir = "iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch" |
| | | model = Paraformer(model_dir, batch_size=1) # cpu |
| | |
| | | if quantize: |
| | | model_file = os.path.join(model_dir, "model_quant.torchscripts") |
| | | if not os.path.exists(model_file): |
| | | print(".onnx is not exist, begin to export onnx") |
| | | print(".torchscripts does not exist, begin to export torchscripts") |
| | | try: |
| | | from funasr import AutoModel |
| | | except: |
| | |
| | | if quantize: |
| | | model_file = os.path.join(model_dir, "model_quant.onnx") |
| | | if not os.path.exists(model_file): |
| | | print(".onnx is not exist, begin to export onnx") |
| | | print(".onnx does not exist, begin to export onnx") |
| | | try: |
| | | from funasr import AutoModel |
| | | except: |