瀏覽代碼

update SDK version of elevenlabs and corresponding code snippets.

master
cgnannan 8 月之前
父節點
當前提交
6ddddffc0f
共有 2 個文件被更改,包括 7 次插入7 次删除
  1. +1
    -0
      requirements-optional.txt
  2. +6
    -7
      voice/elevent/elevent_voice.py

+ 1
- 0
requirements-optional.txt 查看文件

@@ -10,6 +10,7 @@ azure-cognitiveservices-speech # azure voice
edge-tts # edge-tts
numpy<=1.24.2
langid # language detect
elevenlabs==1.0.3 # elevenlabs TTS

#install plugin
dulwich


+ 6
- 7
voice/elevent/elevent_voice.py 查看文件

@@ -1,7 +1,7 @@
import time

from elevenlabs import set_api_key,generate
from elevenlabs.client import ElevenLabs
from elevenlabs import save
from bridge.reply import Reply, ReplyType
from common.log import logger
from common.tmp_dir import TmpDir
@@ -9,7 +9,7 @@ from voice.voice import Voice
from config import conf

XI_API_KEY = conf().get("xi_api_key")
set_api_key(XI_API_KEY)
client = ElevenLabs(api_key=XI_API_KEY)
name = conf().get("xi_voice_id")

class ElevenLabsVoice(Voice):
@@ -21,13 +21,12 @@ class ElevenLabsVoice(Voice):
pass

def textToVoice(self, text):
audio = generate(
audio = client.generate(
text=text,
voice=name,
model='eleven_multilingual_v1'
model='eleven_multilingual_v2'
)
fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".mp3"
with open(fileName, "wb") as f:
f.write(audio)
save(audio, fileName)
logger.info("[ElevenLabs] textToVoice text={} voice file name={}".format(text, fileName))
return Reply(ReplyType.VOICE, fileName)

Loading…
取消
儲存