import random import gradio as gr import numpy as np import time from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError def pad_buffer(audio): # Pad buffer to multiple of 2 bytes buffer_size = len(audio) element_size = np.dtype(np.int16).itemsize if buffer_size % element_size != 0: audio = audio + b'\0' * (element_size - (buffer_size % element_size)) return audio def generate_voice(text, voice_name, api_key): set_api_key(api_key) #set API key try: audio = generate( text[:4000], # Limit to 4000 characters voice=voice_name, model="eleven_multilingual_v2" ) return (44100, np.frombuffer(pad_buffer(audio), dtype=np.int16)) except UnauthenticatedRateLimitError as e: raise gr.Error("Thanks for trying out ElevenLabs TTS! You've reached the free tier limit. Please provide an API key to continue.") except Exception as e: raise gr.Error(e) # description = """ # Eleven Multilingual V2 is the world's best Text-to-Speech model. Features 38 voices and supports 28 languages. Sign up on [ElevenLabs](https://elevenlabs.io/?from=partnerpierce7156) to get an API Key. # """ with gr.Blocks(theme='Nymbo/Alyx_Theme') as block: #gr.Markdown('[ ![ElevenLabs](https://user-images.githubusercontent.com/12028621/262629275-4f85c9cf-85b6-435e-ab50-5b8c7c4e9dd2.png) ](https://elevenlabs.io)') #gr.Markdown("#