DGdev91 commited on
Commit
ed6d1a3
·
unverified ·
1 Parent(s): ee7503d

examples : update elevenlabs scripts to use official python API (#837)

Browse files

* Update elevenlabs example to use ufficial python API

* Update elevenlabs example to use official python API

examples/talk-llama/eleven-labs.py CHANGED
@@ -1,23 +1,20 @@
1
  import sys
2
  import importlib.util
3
 
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
-
9
  if importlib.util.find_spec("elevenlabs") is None:
10
  print("elevenlabs library is not installed, you can install it to your enviroment using 'pip install elevenlabs'")
11
  sys.exit()
12
 
13
- from elevenlabs import ElevenLabs
14
- eleven = ElevenLabs(api_key)
15
 
16
  # Get a Voice object, by name or UUID
17
- voice = eleven.voices["Arnold"] #Possible Voices: Adam Antoni Arnold Bella Domi Elli Josh
18
 
19
  # Generate the TTS
20
- audio = voice.generate(str(sys.argv[2:]))
 
 
 
21
 
22
  # Save the TTS to a file
23
- audio.save("audio")
 
1
  import sys
2
  import importlib.util
3
 
 
 
 
 
 
4
  if importlib.util.find_spec("elevenlabs") is None:
5
  print("elevenlabs library is not installed, you can install it to your enviroment using 'pip install elevenlabs'")
6
  sys.exit()
7
 
8
+ from elevenlabs import generate, play, save
 
9
 
10
  # Get a Voice object, by name or UUID
11
+ voice = "Arnold" #Possible Voices: Adam Antoni Arnold Bella Domi Elli Josh
12
 
13
  # Generate the TTS
14
+ audio = generate(
15
+ text=str(sys.argv[2:]),
16
+ voice=voice
17
+ )
18
 
19
  # Save the TTS to a file
20
+ save(audio, "audio.mp3")
examples/talk-llama/speak.sh CHANGED
@@ -13,8 +13,11 @@
13
  say "$2"
14
 
15
  # 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
 
 
17
  #
 
18
  #wd=$(dirname $0)
19
  #script=$wd/eleven-labs.py
20
  #python3 $script $1 "$2" >/dev/null 2>&1
 
13
  say "$2"
14
 
15
  # Eleven Labs
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
19
  #
20
+ #export ELEVEN_API_KEY=your_api_key
21
  #wd=$(dirname $0)
22
  #script=$wd/eleven-labs.py
23
  #python3 $script $1 "$2" >/dev/null 2>&1
examples/talk/eleven-labs.py CHANGED
@@ -1,23 +1,20 @@
1
  import sys
2
  import importlib.util
3
 
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
-
9
  if importlib.util.find_spec("elevenlabs") is None:
10
  print("elevenlabs library is not installed, you can install it to your enviroment using 'pip install elevenlabs'")
11
  sys.exit()
12
 
13
- from elevenlabs import ElevenLabs
14
- eleven = ElevenLabs(api_key)
15
 
16
  # Get a Voice object, by name or UUID
17
- voice = eleven.voices["Arnold"] #Possible Voices: Adam Antoni Arnold Bella Domi Elli Josh
18
 
19
  # Generate the TTS
20
- audio = voice.generate(str(sys.argv[2:]))
 
 
 
21
 
22
  # Save the TTS to a file
23
- audio.save("audio")
 
1
  import sys
2
  import importlib.util
3
 
 
 
 
 
 
4
  if importlib.util.find_spec("elevenlabs") is None:
5
  print("elevenlabs library is not installed, you can install it to your enviroment using 'pip install elevenlabs'")
6
  sys.exit()
7
 
8
+ from elevenlabs import generate, play, save
 
9
 
10
  # Get a Voice object, by name or UUID
11
+ voice = "Arnold" #Possible Voices: Adam Antoni Arnold Bella Domi Elli Josh
12
 
13
  # Generate the TTS
14
+ audio = generate(
15
+ text=str(sys.argv[2:]),
16
+ voice=voice
17
+ )
18
 
19
  # Save the TTS to a file
20
+ save(audio, "audio.mp3")
examples/talk/speak.sh CHANGED
@@ -13,8 +13,11 @@
13
  say "$2"
14
 
15
  # 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
 
 
17
  #
 
18
  #wd=$(dirname $0)
19
  #script=$wd/eleven-labs.py
20
  #python3 $script $1 "$2"
 
13
  say "$2"
14
 
15
  # Eleven Labs
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
19
  #
20
+ #export ELEVEN_API_KEY=your_api_key
21
  #wd=$(dirname $0)
22
  #script=$wd/eleven-labs.py
23
  #python3 $script $1 "$2"