ali.py 714 B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. """
  3. 阿里的语音识别API
  4. """
  5. from __future__ import division
  6. from ..__load__ import *
  7. from .base import Base
  8. class Ali(Base):
  9. def __init__(self):
  10. super(self.__class__, self).__init__(True)
  11. def setting(self, appKey, token, voice='vecan', **args):
  12. self.appKey = appKey
  13. self.token = token
  14. def asr(self, fp):
  15. result = self.sdk.asr(self.appKey, self.token, fp)
  16. if result is not None:
  17. return self.arrLog(1, result)
  18. else:
  19. return self.arrLog(2, '')
  20. def tts(self, phrase):
  21. tmpfile = self.sdk.tts(self.appKey, self.token, self.voice, phrase)
  22. if tmpfile is not None:
  23. return self.ttsLog(1, tmpfile)
  24. else:
  25. return self.ttsLog(2, '')