You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 line
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)