demo.py 959 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. # -*- encoding: utf-8 -*-
  3. # Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
  4. # MIT License (https://opensource.org/licenses/MIT)
  5. from funasr import AutoModel
  6. model = AutoModel(model="iic/LCB-NET")
  7. # example1
  8. #res = model.generate(input="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav",
  9. # )
  10. #print(res)
  11. '''
  12. # tensor or numpy as input
  13. # example2
  14. import torchaudio
  15. import os
  16. wav_file = os.path.join(model.model_path, "example/asr_example.wav")
  17. input_tensor, sample_rate = torchaudio.load(wav_file)
  18. input_tensor = input_tensor.mean(0)
  19. res = model.generate(input=[input_tensor], batch_size_s=300, is_final=True)
  20. # example3
  21. import soundfile
  22. wav_file = os.path.join(model.model_path, "example/asr_example.wav")
  23. speech, sample_rate = soundfile.read(wav_file)
  24. res = model.generate(input=[speech], batch_size_s=300, is_final=True)
  25. '''