flavioschneider commited on
Commit
5bd7020
1 Parent(s): 7779a3f

fix: buffer padding, default text

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -3,6 +3,14 @@ import gradio as gr
3
  import numpy as np
4
  from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError
5
 
 
 
 
 
 
 
 
 
6
  def generate_voice(text, voice_name, model_name, api_key):
7
  try:
8
  audio = generate(text, voice=voice_name, model=model_name, api_key=api_key)
@@ -10,7 +18,7 @@ def generate_voice(text, voice_name, model_name, api_key):
10
  raise gr.Error("Thanks for trying out ElevenLabs TTS! You've reached the free tier limit. Please provide an API key to continue.")
11
  except Exception as e:
12
  raise gr.Error(e)
13
- return (44100, np.frombuffer(audio, dtype=np.int16))
14
 
15
  badges = """
16
  <div style="display: flex">
@@ -44,14 +52,14 @@ with gr.Blocks() as block:
44
  input_text = gr.Textbox(
45
  label="Input Text",
46
  lines=2,
47
- value="Hi! I'm Eleven, the worlds most advanced TTS system.",
48
  elem_id="input_text"
49
  )
50
 
51
  all_voices = voices()
52
  input_voice = gr.Dropdown(
53
  [ voice.name for voice in all_voices ],
54
- value=random.choice(all_voices).name,
55
  label="Voice",
56
  elem_id="input_voice"
57
  )
@@ -59,7 +67,7 @@ with gr.Blocks() as block:
59
  input_model = gr.Radio(
60
  ["eleven_monolingual_v1", "eleven_multilingual_v1"],
61
  label="Model",
62
- value="eleven_multilingual_v1",
63
  elem_id="input_model",
64
  )
65
 
 
3
  import numpy as np
4
  from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError
5
 
6
+ def pad_buffer(audio):
7
+ # Pad buffer to multiple of 2 bytes
8
+ buffer_size = len(audio)
9
+ element_size = np.dtype(np.int16).itemsize
10
+ if buffer_size % element_size != 0:
11
+ audio = audio + b'\0' * (element_size - (buffer_size % element_size))
12
+ return audio
13
+
14
  def generate_voice(text, voice_name, model_name, api_key):
15
  try:
16
  audio = generate(text, voice=voice_name, model=model_name, api_key=api_key)
 
18
  raise gr.Error("Thanks for trying out ElevenLabs TTS! You've reached the free tier limit. Please provide an API key to continue.")
19
  except Exception as e:
20
  raise gr.Error(e)
21
+ return (44100, np.frombuffer(pad_buffer(audio), dtype=np.int16))
22
 
23
  badges = """
24
  <div style="display: flex">
 
52
  input_text = gr.Textbox(
53
  label="Input Text",
54
  lines=2,
55
+ value="Hahaha OHH MY GOD! This is SOOO funny, I-I am Eleven and-and I am a text to speech system!!",
56
  elem_id="input_text"
57
  )
58
 
59
  all_voices = voices()
60
  input_voice = gr.Dropdown(
61
  [ voice.name for voice in all_voices ],
62
+ value="Arnold",
63
  label="Voice",
64
  elem_id="input_voice"
65
  )
 
67
  input_model = gr.Radio(
68
  ["eleven_monolingual_v1", "eleven_multilingual_v1"],
69
  label="Model",
70
+ value="eleven_monolingual_v1",
71
  elem_id="input_model",
72
  )
73