Skip to content

Commit 5e2b340

Browse files
authoredMay 24, 2023
examples : update elevenlabs scripts to use official python API (ggerganov#837)
* Update elevenlabs example to use ufficial python API * Update elevenlabs example to use official python API
1 parent 4e16a8f commit 5e2b340

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed
 

‎examples/talk-llama/eleven-labs.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import sys
22
import importlib.util
33

4-
api_key = "" #Write your https://beta.elevenlabs.io api key here
5-
if not api_key:
6-
print("To use elevenlabs you have to register to https://beta.elevenlabs.io and add your elevenlabs api key to examples/talk-llama/eleven-labs.py")
7-
sys.exit()
8-
94
if importlib.util.find_spec("elevenlabs") is None:
105
print("elevenlabs library is not installed, you can install it to your enviroment using 'pip install elevenlabs'")
116
sys.exit()
127

13-
from elevenlabs import ElevenLabs
14-
eleven = ElevenLabs(api_key)
8+
from elevenlabs import generate, play, save
159

1610
# Get a Voice object, by name or UUID
17-
voice = eleven.voices["Arnold"] #Possible Voices: Adam Antoni Arnold Bella Domi Elli Josh
11+
voice = "Arnold" #Possible Voices: Adam Antoni Arnold Bella Domi Elli Josh
1812

1913
# Generate the TTS
20-
audio = voice.generate(str(sys.argv[2:]))
14+
audio = generate(
15+
text=str(sys.argv[2:]),
16+
voice=voice
17+
)
2118

2219
# Save the TTS to a file
23-
audio.save("audio")
20+
save(audio, "audio.mp3")

‎examples/talk-llama/speak.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
say "$2"
1414

1515
# Eleven Labs
16-
# To use it, install the elevenlabs module from pip (pip install elevenlabs), register to https://beta.elevenlabs.io to get an api key and paste it in /examples/talk-llama/eleven-labs.py
16+
# To use it, install the elevenlabs module from pip (pip install elevenlabs)
17+
# It's possible to use the API for free with limited number of characters. To increase this limit register to https://beta.elevenlabs.io to get an api key and paste it after 'ELEVEN_API_KEY='
18+
#Keep the line commented to use the free version whitout api key
1719
#
20+
#export ELEVEN_API_KEY=your_api_key
1821
#wd=$(dirname $0)
1922
#script=$wd/eleven-labs.py
2023
#python3 $script $1 "$2" >/dev/null 2>&1

‎examples/talk/eleven-labs.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import sys
22
import importlib.util
33

4-
api_key = "" #Write your https://beta.elevenlabs.io api key here
5-
if not api_key:
6-
print("To use elevenlabs you have to register to https://beta.elevenlabs.io and add your elevenlabs api key to examples/talk/eleven-labs.py")
7-
sys.exit()
8-
94
if importlib.util.find_spec("elevenlabs") is None:
105
print("elevenlabs library is not installed, you can install it to your enviroment using 'pip install elevenlabs'")
116
sys.exit()
127

13-
from elevenlabs import ElevenLabs
14-
eleven = ElevenLabs(api_key)
8+
from elevenlabs import generate, play, save
159

1610
# Get a Voice object, by name or UUID
17-
voice = eleven.voices["Arnold"] #Possible Voices: Adam Antoni Arnold Bella Domi Elli Josh
11+
voice = "Arnold" #Possible Voices: Adam Antoni Arnold Bella Domi Elli Josh
1812

1913
# Generate the TTS
20-
audio = voice.generate(str(sys.argv[2:]))
14+
audio = generate(
15+
text=str(sys.argv[2:]),
16+
voice=voice
17+
)
2118

2219
# Save the TTS to a file
23-
audio.save("audio")
20+
save(audio, "audio.mp3")

‎examples/talk/speak.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
say "$2"
1414

1515
# Eleven Labs
16-
# To use it, install the elevenlabs module from pip (pip install elevenlabs), register to https://beta.elevenlabs.io to get an api key and paste it in /examples/talk/eleven-labs.py
16+
# To use it, install the elevenlabs module from pip (pip install elevenlabs)
17+
# It's possible to use the API for free with limited number of characters. To increase this limit register to https://beta.elevenlabs.io to get an api key and paste it after 'ELEVEN_API_KEY='
18+
#Keep the line commented to use the free version whitout api key
1719
#
20+
#export ELEVEN_API_KEY=your_api_key
1821
#wd=$(dirname $0)
1922
#script=$wd/eleven-labs.py
2023
#python3 $script $1 "$2"

0 commit comments

Comments
 (0)
Please sign in to comment.