Тёмный

How to use the ElevenLabs API: Python text-to-speech tutorial with examples 

PuppyCoding – for Python & AI
Подписаться 1 тыс.
Просмотров 27 тыс.
50% 1

A beginner-friendly tutorial showing how to generate voice output with Python using the ElevenLabs API for TTS (text-to-speech). No account or API key is needed for the initial trial so you can run the code in this video for free.
Get the source code here:
puppycoding.com/2023/08/24/el...
And see a video of all the premade ElevenLabs voice samples here:
• ElevenLabs Voice Sampl...
00:00 Intro
00:27 Install the "elevenlabs" package
00:56 Generate & play audio
04:01 Change the voice
06:09 Save as an audio file
07:25 Control how the voice sounds
10:29 Use an API key
#Python #programming #ElevenLabs

Наука

Опубликовано:

 

1 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 87   
@mikebledig7208
@mikebledig7208 7 месяцев назад
Thank you for a very easy to follow video. It's to the point, well explained. Also a big thank you for putting the sample code for us to cross reference to. If someone who is visually impaired can follow your videos without any difficulty, then anyone can! Once again, a big THANK YOU from me!
@ItsThies
@ItsThies 5 месяцев назад
Thank you so much, no other videos code worked for me! You're a lifesaver!
@solagbenro7295
@solagbenro7295 11 месяцев назад
Short succinct and to the point. Thank you!
@PuppyCoding
@PuppyCoding 11 месяцев назад
I really appreciate that, thank you!
@elwoodfanwwod
@elwoodfanwwod 8 месяцев назад
I just wanted to say that, as someone who isn't much of a programmer, you do a really good job of explaining this stuff and thank you.
@abagatelle
@abagatelle 10 месяцев назад
Very pleased I found your {straight to the point}{no waffle} channel :-)
@PuppyCoding
@PuppyCoding 10 месяцев назад
That's great to hear - thanks!
@user-qt1ne9qu3u
@user-qt1ne9qu3u 9 месяцев назад
really good teacher !! Merci
@gustephens111
@gustephens111 10 месяцев назад
Brilliant, thank you so much, I have decent coding skills and it still took me quite some time to find an example of someone actually doing it from txt to running the program
@PuppyCoding
@PuppyCoding 10 месяцев назад
Thanks Garrett! Like you, I was surprised there weren't more examples like this.
@vrpig
@vrpig 5 месяцев назад
brilliant, thankyou so much
@bungandri
@bungandri 10 месяцев назад
thank you for the tutorial, before I found this video I asked Chat GPT and got a lot of errors and took almost 2-3 hours. but here I learned again in just 10 minutes. you are amazing sir.
@PuppyCoding
@PuppyCoding 10 месяцев назад
Cool, I'm delighted to hear that - thank you!
@PuppyCoding
@PuppyCoding 11 месяцев назад
If you're looking for ElevenLabs voice IDs and samples, I have them listed in the description of this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-pXArMwOgjPU.html And here's a video showing how to use custom voices with the ElevenLabs API: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-r5aJeq-f0OY.html
@MoroccanAvatar
@MoroccanAvatar 6 месяцев назад
why i get this error 'elevenlabs' has no attribute 'generate'
@edosetiawan9589
@edosetiawan9589 3 месяца назад
Pliss help sir
@WorkFlow-tf9jc
@WorkFlow-tf9jc 2 месяца назад
@@edosetiawan9589 not a great solution but I installed an older version in terminal (elevenlabs==0.2.27) and then I had to 'brew install ffmpeg' and then it worked!!
@otimistarj
@otimistarj 6 дней назад
@@edosetiawan9589 i gave an complex answer. If you know something easier please post here
@freepythoncode
@freepythoncode 6 месяцев назад
Thank you so much 🙂❤ I will change my voice soon 😎
@abelelizardo1452
@abelelizardo1452 3 месяца назад
I can't find the argument for generation is there a new update?
@user-wf9kh9hf6k
@user-wf9kh9hf6k 8 месяцев назад
Hello Sir! Can you please tell me if I can change the speech language by code in Python and by using "eleven_multilingual_v2"?
@ShyamJourneyz
@ShyamJourneyz 5 месяцев назад
Hello, I was wondering if you could help me with my following scenario. I am getting a ValueError two times and was wondering if you knew the cause of it. First one looks like this: "f"Voice '{voice_str}' not found.". The second value error is "Voice 'Bella' not found. I installed using pip3 and I have tried putting the code into both Visual Studio and TextMate. I am running it in the terminal as well. Any help is greatly appreciated. ~New Programmer
@komoisan-8081
@komoisan-8081 8 месяцев назад
I have used elevnlabs in the past but never the python api, so dont you need a api key for this to work?
@FushigiMigi
@FushigiMigi Месяц назад
love you bro
@TanDoori_GamEr
@TanDoori_GamEr 6 месяцев назад
You Deserve Millions Of Subscribers For this Work. May Allah Success You!
@speedeespeedboi9527
@speedeespeedboi9527 9 месяцев назад
i get 'list' object has no attribute 'get'. what do?
@neptosuprananas4434
@neptosuprananas4434 5 месяцев назад
Hello, the save method isn't working for me
@eachandeverything111
@eachandeverything111 6 месяцев назад
Text to Speech is working Good but Eleven Labs allows us "speech to Speech" feature. How it Possible by using Please help
@juncando
@juncando 5 месяцев назад
The decrease in stability will bring in the wonkiness, for lack of a better word. It is better suited for your own voice samples where you can see the levels of excitement and guttoral noises like filler words and sounds. The default value keeps it monotone. I feel the best samples are conversations or interviews. My question now is how will I move this to my DID model so I can animate my avatar. I suppose I can use the same procedure and pump the generated audio to the D-ID.
@yaga4429
@yaga4429 10 месяцев назад
Hello Im very new to all this and I was trying to follow along but every time I put in "pip install elevenlabs" I get a SyntaxError and to be honest I have no idea what that means. Im putting into a fresh Python 3.11 terminal. Not sure how to fix that.
@PuppyCoding
@PuppyCoding 10 месяцев назад
Hi Yaga. No problem, I think we can fix this. It sounds like you might have typed "pip install elevenlabs" directly into a text file (a Python program) and then tried to run it. Is that correct? If so, the "pip install elevenlabs" (without quotes) is something you type directly into the terminal *before* running your Python program. That will install the module. Then, in your program at the top, you'd type "import elevenlabs" to use the module. Does that make sense? If that doesn't work, it could be because your terminal is a kind of Python terminal (used for typing Python commands directly). In that case, type "exit()" (without quotes) to exit into a regular terminal. Then you can try "pip install elevenlabs" again. I hope that works! Let me know how it goes.
@withondra
@withondra 7 месяцев назад
hi mate, I know that your message is 2 months old but I hope you will find this. Try instead typing this: python.exe -m pip install eleven labs
@railgundotenc8538
@railgundotenc8538 11 месяцев назад
Where do I get the model ID for voice lab voices. For example I got one from the voice library and saved it. How do I use it now
@railgundotenc8538
@railgundotenc8538 11 месяцев назад
Nvm works the same way but require api key
@PuppyCoding
@PuppyCoding 11 месяцев назад
@@railgundotenc8538 Hi there. Just in case, I made a list of all premade voices and their voice IDs in the description of this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-pXArMwOgjPU.html Hope that helps.
@railgundotenc8538
@railgundotenc8538 11 месяцев назад
I'm talking about not premade voices.
@PuppyCoding
@PuppyCoding 11 месяцев назад
@@railgundotenc8538 Ah sorry, my misunderstanding. Yes, as you mentioned, I think you need to use the API's "voices" endpoint for that: docs.elevenlabs.io/api-reference/voices
@PuppyCoding
@PuppyCoding 10 месяцев назад
Hi again. In case it helps you (or others with the same question), I just made a video showing how to get custom voice IDs: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-r5aJeq-f0OY.html
@Nick-kp7iw
@Nick-kp7iw 4 месяца назад
Great vid! Thanks! Do you have one in the works for instant clones or recommendation on approach?
@drewsisera
@drewsisera 4 месяца назад
I'm also curious to know if you can use an API for an instant cloned voice.
@ilizapink
@ilizapink 2 месяца назад
guys is this linux where can i code with python?!
@RedpaX
@RedpaX 10 месяцев назад
How to get an existing list of my voice_id?
@PuppyCoding
@PuppyCoding 10 месяцев назад
Hi. Good question. There are a couple of ways (from the ElevenLabs docs or using Python) so I made a video showing how to do it: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-r5aJeq-f0OY.html I hope that helps!
@maedeha.b4714
@maedeha.b4714 9 месяцев назад
mine gives error ffmpeg not found although I installed it :( any help?
@PuppyCoding
@PuppyCoding 9 месяцев назад
Hi. That's strange. I've not come across this myself, but I found a few other people that had this problem and other people have suggested solutions. Perhaps one of these will work for you: github.com/elevenlabs/elevenlabs-python/issues/56 github.com/elevenlabs/elevenlabs-python/issues/59 github.com/elevenlabs/elevenlabs-python/issues/44 stackoverflow.com/questions/77150521/eleven-labs-api-not-working-is-ffmpeg-not-installed-properly If not, it'd be helpful to have some more details to help debug, e.g. what operating system you're using, whether you're using the terminal or a Python environment (e.g. Replit, Pycharm), how you installed ffmpeg (e.g. pip, brew), and what the full error message is.
@eternal_dread666
@eternal_dread666 Месяц назад
mine says 'elevenlabs not defined'
@HackersAcademyHQ
@HackersAcademyHQ Месяц назад
Im getting a problem where elevenlabs has no attribute 'generate'. Could this be the wrong python version?
@bitsnstuff
@bitsnstuff Месяц назад
I get the same thing :(
@generalknowledge6631
@generalknowledge6631 10 месяцев назад
How do you make it work on Pycharm?
@PuppyCoding
@PuppyCoding 10 месяцев назад
Hi. I just tried in PyCharm and I see what you mean. It seems that the VoiceSettings class doesn't work in PyCharm unfortunately (I don't know why), so here are a couple of workarounds: Option 1: Remove this from the example code: settings = elevenlabs.VoiceSettings( stability = 0, similarity_boost = 0.75 ) Option 2: Just use the voice name or voice ID directly in the generate() function, like this: audio = elevenlabs.generate( text = "Hi, I'm from the future!", voice = "Bella" ) or audio = elevenlabs.generate( text = "Hi, I'm from the future!", voice = "ZQe5CZNOzWyzPSCn5a3c" ) Either of these makes it work for me in PyCharm.
@BillYovino
@BillYovino 10 месяцев назад
Raspberry Pi 4b Bullseye (OS 11) the ElevenLabs.Voice clause yields an error " message = detail.get("message", "") AttributeError: 'list' object has no attribute 'get'. But if I just use "voice = "Bella" (or other voice name) it works. "
@PuppyCoding
@PuppyCoding 10 месяцев назад
Hi Bill. Hmm, that's strange. For me it worked using "pip install elevenlabs" in the terminal (although I haven't tried on a Raspberry Pi). Maybe check that other packages can be installed as well, if you haven't already. For example, try "pip install openai" or something similar. One possible cause could be that both Python 2 and 3 are installed, in which case maybe "pip3 install elevenlabs" works instead? I hope that helps.
@BillYovino
@BillYovino 10 месяцев назад
@@PuppyCoding I've done the pip and pip3 installs. Both work. It just errors if I try to specify the voice_id instead of the name.
@PuppyCoding
@PuppyCoding 10 месяцев назад
@@BillYovino That's really weird - I don't understand why there'd be a difference. If you're able to paste that section of your code here (or somewhere else), I'm happy to take a look.
@BillYovino
@BillYovino 10 месяцев назад
@@PuppyCoding import elevenlabs elevenlabs.set_api_key() voice = elevenlabs.Voice( voice_id = "vuZhMxquIvNVUPRorn2I", settings = elevenlabs.VoiceSettings( stability = 0.3, similarity_boost = 0.75 ) ) audio = elevenlabs.generate( text = "Hi, I'm from the future!", voice = voice ) elevenlabs.play(audio)
@PuppyCoding
@PuppyCoding 10 месяцев назад
Hi again Bill. I did some investigating and it seems that the VoiceSettings class doesn't work in some software, e.g. PyCharm. I don't know why but maybe the the Raspberry 4 is the same. Anyway, here are a couple of workarounds: Option 1: Remove this from the example code: settings = elevenlabs.VoiceSettings( stability = 0, similarity_boost = 0.75 ) Option 2: Just use the voice name or voice ID directly in the generate() function, like this: audio = elevenlabs.generate( text = "Hi, I'm from the future!", voice = "Bella" ) or audio = elevenlabs.generate( text = "Hi, I'm from the future!", voice = "ZQe5CZNOzWyzPSCn5a3c" ) Either of these makes it work for me in PyCharm, so hopefully Raspberry Pi 4 as well.
@pauloroberto-gz4kv
@pauloroberto-gz4kv 9 месяцев назад
how to put the voice portuguese pt-br
@hedgedoge5562
@hedgedoge5562 10 месяцев назад
Hi friend, I really love your tutorial! Take my like hhahahaa I was wondering, is there any way to use the ElevenLabs API in Python with voice cloning voices?
@PuppyCoding
@PuppyCoding 10 месяцев назад
Hi there - thank you! Yes, it is possible to use cloned voices with the ElevenLabs API, and thankfully it's straightforward - it's actually the same as with premade voices. You can access both premade and cloned voices with your API key. You just need to know the voice name or ID of the cloned voice. You can get the voice ID from the "voices" function of the API, either using Python code like this example here: github.com/elevenlabs/elevenlabs-python#%EF%B8%8F-voices Or using the Try It Out feature of the API docs here: api.elevenlabs.io/docs#/voices/Get_voices_v1_voices_get
@hedgedoge5562
@hedgedoge5562 10 месяцев назад
@@PuppyCoding This helped a lot! Thank you so much for the extensive reply, you're a legend ahahaa
@PuppyCoding
@PuppyCoding 10 месяцев назад
@@hedgedoge5562 Great - you're welcome!
@mr.8oom
@mr.8oom 9 месяцев назад
how many characters you can use
@PuppyCoding
@PuppyCoding 9 месяцев назад
Hi. I couldn't find an official page with the character limits, but in my testing I was able to use up to around 300 characters for free without an API key. For longer text it started asking me for an API key. If you need more than around 300 characters each time, then you'll need a paid account. Their pricing page is here: elevenlabs.io/pricing
@pauloroberto-gz4kv
@pauloroberto-gz4kv 9 месяцев назад
Can anyone help me with how to put it in Portuguese
@PuppyCoding
@PuppyCoding 9 месяцев назад
Olá, Paolo. I don't think there's a way to choose a voice specifically for Portuguese unfortunately. I had the same problem with Japanese and the only thing I could do was go through each of the current ElevenLabs voices and see which one sounds best. I think we just have to wait for ElevenLabs to release voices for each language.
@pauloroberto-gz4kv
@pauloroberto-gz4kv 9 месяцев назад
I found another alternative I used Microsoft Azure, it has voices in Portuguese,thanks for the feedback!
@PuppyCoding
@PuppyCoding 9 месяцев назад
@@pauloroberto-gz4kv Oh nice, I didn't know that was possible. Thanks for letting me know.
@angelohenriquems
@angelohenriquems 9 месяцев назад
Fala, Paulo! Tudo bem com você? Você achou um jeito de usar o TTS da Azure clonando a voz? Ou no caso deles só é possível utilizar com vozes já existentes? Outra dúvida: você não encontrou uma voz em português padrão com o ElevenLabs? Você considerou clonar alguma voz e usar ela? Muito obrigado! @@pauloroberto-gz4kv
@pastuh
@pastuh 11 месяцев назад
Nice, but not so many languages :)
@PuppyCoding
@PuppyCoding 11 месяцев назад
That's true. I hope they add more languages soon because the quality of what they already have is so good.
@ColinHanra
@ColinHanra 7 месяцев назад
And it’s free?
@mungojelly
@mungojelly 10 месяцев назад
this is a nice video but it feels old fashioned, like, this is an ai video right? are you really still writing your code by hand w/ no copilot?? 🤔 in this day & age what i'd like is advice how to ask for scripts that use this api from a model, including like, terse instructions how to use the api that i can paste in as part of the instructions when i want to ask for one ,, i mean i guess this is simple enough i can bother to type it in myself, it just, feels anachronistic to me
@PuppyCoding
@PuppyCoding 10 месяцев назад
Thanks for your comment. I agree, the way I code in the video can seem old fashioned, given the modern tools we now have available. I do it this way partly because I am old fashioned (sorry!) but also because my priority is for the videos to be educational for people just getting familiar with Python. I feel that typing everything by hand gives me the chance to explain what's going on, without code appearing "by magic". I should have made that more clear, so I've just updated the channel About page. Hopefully that reduces confusion, and thanks for pointing it out.
@mungojelly
@mungojelly 10 месяцев назад
@@PuppyCoding you're fine, you can code however you want, i'm just surprised by how slowly AI tools are coming into use even on channels that talk a lot about AI ,, not just you, pretty universally, i guess that's just human speed, we're the very slowest thing that can general intelligence at all ,, have you tried copilot or asking gpt4 for programs yet yourself?? i think there's a huge opportunity coming up to allow people to ask for programs who aren't traditional style programmers,, & beginning programmers starting right now should be encouraged to leapfrog and just never learn the old way at all, that's my intuition
@PuppyCoding
@PuppyCoding 10 месяцев назад
@@mungojelly Ah, I see what you mean. Yes, I think I agree, there doesn't seem to be that much hands-on content with AI programming tools. Perhaps the audience can be roughly divided - 1) those that want to learn how to build something, and 2) those that want to learn the fundamentals to embark on a career. Personally I prefer teaching the "old way" for people in the second group, but there is a need for content for the first group too. I do use ChatGPT + Code Interpreter (now called Advanced Data Analysis) for my own coding and love it, although I still prefer to verify its output before using it. Maybe I should do a video on that, from a more practical standpoint. Thanks for the food for thought!
@ollie6845
@ollie6845 6 месяцев назад
don't fall for this trap, you will be very very limited by the eleven labs API if you don't sign in and pay, so it's useless.
@kunalr_ai
@kunalr_ai 9 месяцев назад
It is not free
@PuppyCoding
@PuppyCoding 9 месяцев назад
Hi Kunal. You're right, you need a subscription to use the API long-term, but they allow a free initial trial without an API key, just to test it out. I found that I could use it up to about 300 characters for free. After that, it started asking me for an API key.
@yotamarker
@yotamarker 6 месяцев назад
fake tutorial : raise ValueError(f"Voice '{voice_str}' not found.") ValueError: Voice 'Bella' not found.
@blueboi-wk8gq
@blueboi-wk8gq 6 месяцев назад
use Arnold instead of bella, bro if there is no bella just looks for other names on the webpage, you could have find out that urself
@yotamarker
@yotamarker 6 месяцев назад
@@blueboi-wk8gq I tried all sorts of voices including Sarah, this library needs some complex 3rd party installation called FFmpeg, which of course is not explained by the uploader seeing as this "tutorial" is another classic example of search engine poisoning.
Далее
BEST AI Voice Generator | ElevenLabs Tutorial
9:52
Просмотров 567 тыс.
Best exercises to lose weight ! 😱
00:19
Просмотров 11 млн
Ne jamais regarder une fille à la plage 😂
00:10
Просмотров 677 тыс.
How to Install & Use Whisper AI Voice to Text
12:44
Просмотров 451 тыс.
Use OpenAI's API for Free
7:36
Просмотров 24 тыс.
Modern Graphical User Interfaces in Python
11:12
Просмотров 1,5 млн
Voice Cloning In Multiple Languages - Open Source
16:49