Closed jujutsu764e closed 7 months ago
Lets say that you are interested in a particular voice. Then you can grab the id of the that particular voice and use it. I hope it helps.
uri = f"wss://api.elevenlabs.io/v1/text-to-speech/{voice_id}/stream-input?model_id=eleven_monolingual_v1"
from elevenlabs import voices
from elevenlabs import generate, stream
from elevenlabs import set_api_key
from elevenlabs import generate, stream
from dotenv import load_dotenv
import os
import requests
load_dotenv()
set_api_key(os.getenv("ELEVEN_API_KEY"))
def get_voice_setting(voice_id):
url = f"https://api.elevenlabs.io/v1/voices/{voice_id}/settings"
headers = {
"Accept": "application/json",
"xi-api-key": os.getenv("ELEVEN_API_KEY")
}
response = requests.get(url, headers=headers)
return response.text
for voice in voices():
print(100*"-")
voice_setting = get_voice_setting(voice_id=voice.voice_id)
print(voice_setting)
At the moment I grab all voices from API and then use the number in the list, like voice = voices[23]. But the problem is that when I update my voices lib, some of them can be replaced with new positions in the list. For example, I deleted some of them and when I tried to pick one which was the last one recently, I got an "out of list indexes" error. Is there any way to set a direct pick for voice in Python using it's voice id?