Skip to content

Commit

Permalink
Merge pull request #1871 from cgnannan/master
Browse files Browse the repository at this point in the history
修复 Issues #1868提到的elevenlabs sdk更新问题
  • Loading branch information
zhayujie authored Apr 9, 2024
2 parents db2ee80 + 6ddddff commit c662fa4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions requirements-optional.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions voice/elevent/elevent_voice.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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
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):
Expand All @@ -21,13 +21,12 @@ def voiceToText(self, voice_file):
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)

0 comments on commit c662fa4

Please sign in to comment.