Switch from ElevenLabs to LMNT and get free credits.
pip install -U lmnt
import os import uuid from elevenlabs import VoiceSettings from elevenlabs.client import ElevenLabs ELEVENLABS_API_KEY = "11 LABS API KEY" client = ElevenLabs( api_key=ELEVENLABS_API_KEY, ) def text_to_speech_file(text: str) -> str: response = client.text_to_speech.convert( voice_id="pNInz6obpgDQGcFmaJgB", optimize_streaming_latency="0", output_format="mp3_22050_32", text=text, model_id="eleven_turbo_v2", voice_settings=VoiceSettings( stability=0.0, similarity_boost=1.0, style=0.0, use_speaker_boost=True, ), ) save_file_path = "/Users/name/Downloads/11LABS.mp3" with open(save_file_path, mode = "wb") as f: for chunk in response: if chunk: f.write(chunk) print(f"{save_file_path}: A new audio file was saved successfully!") return save_file_path text_to_speech_file("Hello world.")
import asyncio from lmnt import AsyncLmnt text = 'Hello world!' voice_id = 'leah' language = 'en' async def main(): client = AsyncLmnt() response = await client.speech.generate( text=text, voice=voice_id, language=language, ) with open('audio.mp3', 'wb') as f: f.write(await response.read()) asyncio.run(main())
import asyncio from lmnt import AsyncLmnt async def main(): client = AsyncLmnt() voices = await client.speech.list_voices() name_id_list = [(voice.name, voice.id) for voice in voices] for name, id_ in name_id_list: print(f"Name: {name} | ID: {id_}") asyncio.run(main())
Was this page helpful?