|
import random |
|
import numpy as np |
|
from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError |
|
|
|
def pad_buffer(audio): |
|
|
|
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, model_name): |
|
try: |
|
audio = generate( |
|
text, |
|
voice="Arnold", |
|
model="eleven_monolingual_v1" |
|
) |
|
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) |