demp.py 977 B

1234567891011121314151617181920212223242526272829303132333435
  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. )
  8. # example1
  9. #res = model.generate(input="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav",
  10. )
  11. #print(res)
  12. '''
  13. # tensor or numpy as input
  14. # example2
  15. import torchaudio
  16. import os
  17. wav_file = os.path.join(model.model_path, "example/asr_example.wav")
  18. input_tensor, sample_rate = torchaudio.load(wav_file)
  19. input_tensor = input_tensor.mean(0)
  20. res = model.generate(input=[input_tensor], batch_size_s=300, is_final=True)
  21. # example3
  22. import soundfile
  23. wav_file = os.path.join(model.model_path, "example/asr_example.wav")
  24. speech, sample_rate = soundfile.read(wav_file)
  25. res = model.generate(input=[speech], batch_size_s=300, is_final=True)
  26. '''