Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

elevent_voice.py 934B

1234567891011121314151617181920212223242526272829303132
  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)