|
| 1 | +import time |
| 2 | + |
| 3 | +import torch |
| 4 | +from funasr_onnx import SenseVoiceSmall |
| 5 | +from funasr_onnx.utils.postprocess_utils import rich_transcription_postprocess |
| 6 | + |
| 7 | +from omnisense import OmniSenseVoiceSmall |
| 8 | + |
| 9 | +model_dir = "iic/SenseVoiceSmall" |
| 10 | +model = SenseVoiceSmall(model_dir, batch_size=10, quantize=False, device_id=1) |
| 11 | + |
| 12 | +# inference |
| 13 | +wav_or_scp = ["tests/data/example.wav"] |
| 14 | +for textnorm in ["woitn", "withitn"]: |
| 15 | + print(f"\n====== Text normalization: {textnorm} ======") |
| 16 | + start_time = time.time() |
| 17 | + res = model(wav_or_scp, language="auto", textnorm=textnorm) |
| 18 | + print(f"Time cost: {time.time() - start_time:.2f}s") |
| 19 | + |
| 20 | + print(res) |
| 21 | + print([rich_transcription_postprocess(i) for i in res]) |
| 22 | + |
| 23 | + |
| 24 | +model_dir = "iic/SenseVoiceSmall" |
| 25 | +model = OmniSenseVoiceSmall(model_dir, quantize=False, device_id=0 if torch.cuda.is_available() else -1) |
| 26 | + |
| 27 | + |
| 28 | +# inference |
| 29 | +wav_or_scp = ["tests/data/Laughter.wav", "tests/data/Cry.wav", "tests/data/Applause.wav"] |
| 30 | +for textnorm in ["woitn", "withitn"]: |
| 31 | + print(f"\n====== Text normalization: {textnorm} ======") |
| 32 | + start_time = time.time() |
| 33 | + res = model.transcribe(wav_or_scp, language="auto", textnorm=textnorm, timestamps=True) |
| 34 | + print(f"Time cost: {time.time() - start_time:.2f}s") |
| 35 | + print(res) |
| 36 | + |
| 37 | + |
| 38 | +wav_or_scp = ["tests/data/example.wav"] |
| 39 | +for textnorm in ["woitn", "withitn"]: |
| 40 | + print(f"\n====== Text normalization: {textnorm} ======") |
| 41 | + start_time = time.time() |
| 42 | + res = model.transcribe(wav_or_scp, language="auto", textnorm=textnorm, timestamps=True) |
| 43 | + print(f"Time cost: {time.time() - start_time:.2f}s") |
| 44 | + print(res) |
0 commit comments