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.

32 line
934B

  1. import time
  2. from elevenlabs.client import ElevenLabs
  3. from elevenlabs import save
  4. from bridge.reply import Reply, ReplyType
  5. from common.log import logger
  6. from common.tmp_dir import TmpDir
  7. from voice.voice import Voice
  8. from config import conf
  9. XI_API_KEY = conf().get("xi_api_key")
  10. client = ElevenLabs(api_key=XI_API_KEY)
  11. name = conf().get("xi_voice_id")
  12. class ElevenLabsVoice(Voice):
  13. def __init__(self):
  14. pass
  15. def voiceToText(self, voice_file):
  16. pass
  17. def textToVoice(self, text):
  18. audio = client.generate(
  19. text=text,
  20. voice=name,
  21. model='eleven_multilingual_v2'
  22. )
  23. fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".mp3"
  24. save(audio, fileName)
  25. logger.info("[ElevenLabs] textToVoice text={} voice file name={}".format(text, fileName))
  26. return Reply(ReplyType.VOICE, fileName)