Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -79,105 +79,40 @@ def controlador_generate_audio(audio_input, voice_model_input, speed_input, chec
|
|
79 |
print("Erro ao gerar áudio.")
|
80 |
return audio_file # Retornar o caminho do arquivo de áudio
|
81 |
|
82 |
-
from elevenlabs import voices, generate
|
83 |
import requests
|
84 |
|
85 |
def generate_audio_elevenlabsfree(texto, voice_name):
|
86 |
-
output_dir = "output"
|
87 |
-
os.makedirs(output_dir, exist_ok=True) # Certifique-se de que o diretório de saída exista
|
88 |
-
|
89 |
try:
|
90 |
-
# Pegar o nome abreviado do modelo de voz
|
91 |
-
modelo_abreviado = voice_name
|
92 |
-
|
93 |
-
# Gerar áudio usando elevenlabs
|
94 |
audio = generate(
|
95 |
-
text
|
96 |
-
voice=
|
97 |
-
model=
|
98 |
)
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
wf.write(audio)
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
modelos= model_elevenlabs_t
|
121 |
-
|
122 |
-
if id_voz_input.strip(): # Se um ID de voz foi fornecido
|
123 |
-
voice_id = id_voz_input
|
124 |
-
print(voice_id)
|
125 |
-
url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}"
|
126 |
-
headers = {
|
127 |
-
"Accept": "audio/mpeg",
|
128 |
-
"Content-Type": "application/json",
|
129 |
-
"xi-api-key": id_api
|
130 |
-
}
|
131 |
-
print(modelos)
|
132 |
-
print(stability_elevenlabs)
|
133 |
-
print(similarity_boost_elevenlabs)
|
134 |
-
print(style_elevenlabs)
|
135 |
-
print(use_speaker_boost_elevenlabs)
|
136 |
-
data = {
|
137 |
-
"text": audio_input_elevenlabs_api,
|
138 |
-
"model_id": modelos,
|
139 |
-
"voice_settings": {
|
140 |
-
"stability": stability_elevenlabs,
|
141 |
-
"similarity_boost": similarity_boost_elevenlabs,
|
142 |
-
"style": style_elevenlabs,
|
143 |
-
"use_speaker_boost": use_speaker_boost_elevenlabs,
|
144 |
-
}
|
145 |
-
}
|
146 |
-
print(data)
|
147 |
-
|
148 |
-
response = requests.post(url, headers=headers, json=data)
|
149 |
-
if response.status_code == 200:
|
150 |
-
audio = response.content
|
151 |
-
else:
|
152 |
-
print("Erro ao gerar áudio:", response.text)
|
153 |
-
return None
|
154 |
-
else: # Se nenhum ID de voz foi fornecido, usar o modelo de voz fornecido
|
155 |
-
print(modelos)
|
156 |
-
print(stability_elevenlabs)
|
157 |
-
print(similarity_boost_elevenlabs)
|
158 |
-
print(style_elevenlabs)
|
159 |
-
print(use_speaker_boost_elevenlabs)
|
160 |
-
audio = generate(
|
161 |
-
text=audio_input_elevenlabs_api,
|
162 |
-
voice=voice_model_input,
|
163 |
-
# voice=Voice(
|
164 |
-
# voice_id='EXAVITQu4vr4xnSDxMaL',
|
165 |
-
# name=voice_model_input,
|
166 |
-
# settings=VoiceSettings(stability=stability_elevenlabs, similarity_boost=similarity_boost_elevenlabs, style=style_elevenlabs, use_speaker_boost=use_speaker_boost_elevenlabs)
|
167 |
-
# ),
|
168 |
-
model=modelos,
|
169 |
-
api_key=id_api
|
170 |
-
)
|
171 |
-
|
172 |
-
if audio:
|
173 |
-
output_file_path = os.path.join(output_dir, "new_audio.wav")
|
174 |
-
with open(output_file_path, 'wb') as wf:
|
175 |
-
wf.write(audio)
|
176 |
-
print("Áudio gerado com sucesso em:", output_file_path)
|
177 |
-
return output_file_path
|
178 |
-
except Exception as e:
|
179 |
-
print("Erro ao gerar áudio:", e)
|
180 |
-
return None
|
181 |
|
182 |
all_voices = voices()
|
183 |
with gr.Blocks(theme=gr.themes.Default(primary_hue="green", secondary_hue="blue"), title="TTS Rápido") as iface:
|
|
|
79 |
print("Erro ao gerar áudio.")
|
80 |
return audio_file # Retornar o caminho do arquivo de áudio
|
81 |
|
82 |
+
from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError
|
83 |
import requests
|
84 |
|
85 |
def generate_audio_elevenlabsfree(texto, voice_name):
|
|
|
|
|
|
|
86 |
try:
|
|
|
|
|
|
|
|
|
87 |
audio = generate(
|
88 |
+
text[:250], # Limit to 250 characters
|
89 |
+
voice=voice_name,
|
90 |
+
model="eleven_multilingual_v2"
|
91 |
)
|
92 |
+
return (44100, np.frombuffer(pad_buffer(audio), dtype=np.int16))
|
93 |
+
except UnauthenticatedRateLimitError as e:
|
94 |
+
raise gr.Error("Thanks for trying out ElevenLabs TTS! You've reached the free tier limit. Please provide an API key to continue.")
|
95 |
+
except Exception as e:
|
96 |
+
raise gr.Error(e)
|
97 |
|
98 |
+
texto = "Olá, este é um exemplo de texto para sintetização de voz."
|
99 |
+
voice_name = "elevenlabs-multilingual-v2"
|
|
|
100 |
|
101 |
+
output_dir = "output"
|
102 |
+
os.makedirs(output_dir, exist_ok=True) # Certifique-se de que o diretório de saída exista
|
103 |
+
|
104 |
+
output_file_path = os.path.join(output_dir, "new_audio.wav")
|
105 |
+
|
106 |
+
try:
|
107 |
+
audio = generate_voice(texto, voice_name)
|
108 |
|
109 |
+
# Escrever os dados do áudio no arquivo WAV
|
110 |
+
with open(output_file_path, 'wb') as wf:
|
111 |
+
wf.write(audio[1].tobytes())
|
112 |
+
|
113 |
+
print("Áudio gerado com sucesso em:", output_file_path)
|
114 |
+
except gr.Error as e:
|
115 |
+
print("Erro ao gerar áudio:", e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
all_voices = voices()
|
118 |
with gr.Blocks(theme=gr.themes.Default(primary_hue="green", secondary_hue="blue"), title="TTS Rápido") as iface:
|