paraformer.py 750 B

12345678910111213141516171819
  1. # For prerequisites running the following sample, visit https://help.aliyun.com/document_detail/611472.html
  2. import dashscope
  3. from urllib import request
  4. import json
  5. import api
  6. dashscope.api_key= api.api_key
  7. task_response=dashscope.audio.asr.Transcription.async_call(
  8. model='paraformer-v1',
  9. file_urls=['https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world.wav']
  10. )
  11. transcription_response=dashscope.audio.asr.Transcription.wait(task=task_response.output.task_id)
  12. transcription_url=transcription_response.output['results'][0]['transcription_url']
  13. transcription_results=json.loads(request.urlopen(transcription_url).read().decode('utf8'))
  14. print(json.dumps(transcription_results, indent=4, ensure_ascii=False))