您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

33 行
762B

  1. """
  2. eleventLabs voice service
  3. """
  4. import time
  5. from elevenlabs import generate
  6. from bridge.reply import Reply, ReplyType
  7. from common.log import logger
  8. from common.tmp_dir import TmpDir
  9. from voice.voice import Voice
  10. class ElevenLabsVoice(Voice):
  11. def __init__(self):
  12. pass
  13. def voiceToText(self, voice_file):
  14. pass
  15. def textToVoice(self, text):
  16. audio = generate(
  17. text=text
  18. )
  19. fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".mp3"
  20. with open(fileName, "wb") as f:
  21. f.write(audio)
  22. logger.info("[ElevenLabs] textToVoice text={} voice file name={}".format(text, fileName))
  23. return Reply(ReplyType.VOICE, fileName)