demo2.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. # -*- encoding: utf-8 -*-
  3. # Copyright FunASR (https://github.com/FunAudioLLM/SenseVoice). All Rights Reserved.
  4. # MIT License (https://opensource.org/licenses/MIT)
  5. from model import SenseVoiceSmall
  6. from funasr.utils.postprocess_utils import rich_transcription_postprocess
  7. model_dir = "iic/SenseVoiceSmall"
  8. m, kwargs = SenseVoiceSmall.from_pretrained(model=model_dir, device="cuda:0")
  9. m.eval()
  10. res = m.inference(
  11. data_in=f"{kwargs['model_path']}/example/en.mp3",
  12. language="auto", # "zh", "en", "yue", "ja", "ko", "nospeech"
  13. use_itn=False,
  14. ban_emo_unk=False,
  15. **kwargs,
  16. )
  17. text = rich_transcription_postprocess(res[0][0]["text"])
  18. print(text)
  19. res = m.inference(
  20. data_in=f"{kwargs['model_path']}/example/en.mp3",
  21. language="auto", # "zh", "en", "yue", "ja", "ko", "nospeech"
  22. use_itn=False,
  23. ban_emo_unk=False,
  24. output_timestamp=True,
  25. **kwargs,
  26. )
  27. timestamp = res[0][0]["timestamp"]
  28. text = rich_transcription_postprocess(res[0][0]["text"])
  29. print(text)
  30. print(timestamp)