Spaces:
Sleeping
Sleeping
ojú
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ import tempfile
|
|
10 |
|
11 |
# Cargar el modelo Whisper-small y bark
|
12 |
transcribir = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
|
|
13 |
|
14 |
|
15 |
# Función para transcribir el audio y traducir el audio de entrada
|
@@ -19,29 +20,29 @@ def transcribir_audio(audio):
|
|
19 |
return result["text"]
|
20 |
|
21 |
|
22 |
-
#Función para generar el audio
|
23 |
def generar_audio(text):
|
24 |
-
|
|
|
25 |
audio_array = generate_audio(text)
|
26 |
-
|
27 |
-
# Normalizar el array de audio (opcional si Bark ya devuelve datos normalizados)
|
28 |
-
audio_array = np.clip(audio_array, -1.0, 1.0) # Asegurar que los valores estén en [-1.0, 1.0]
|
29 |
-
|
30 |
-
# Crear un archivo temporal para almacenar el audio
|
31 |
temp_wav = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
32 |
-
write(temp_wav.name, 24000, (audio_array * 32767).astype(np.int16))
|
33 |
-
|
34 |
return temp_wav.name
|
35 |
|
36 |
|
37 |
def process_audio(audio_file):
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
45 |
|
46 |
|
47 |
# Crear interfaz Gradio
|
|
|
10 |
|
11 |
# Cargar el modelo Whisper-small y bark
|
12 |
transcribir = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
13 |
+
"""bark = pipeline("text-to-speech", model="suno/bark")"""
|
14 |
|
15 |
|
16 |
# Función para transcribir el audio y traducir el audio de entrada
|
|
|
20 |
return result["text"]
|
21 |
|
22 |
|
23 |
+
# Función para generar el audio
|
24 |
def generar_audio(text):
|
25 |
+
if not isinstance(text, str):
|
26 |
+
raise ValueError("El texto debe ser una cadena")
|
27 |
audio_array = generate_audio(text)
|
28 |
+
audio_array = np.clip(audio_array, -1.0, 1.0)
|
|
|
|
|
|
|
|
|
29 |
temp_wav = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
30 |
+
write(temp_wav.name, 24000, (audio_array * 32767).astype(np.int16))
|
|
|
31 |
return temp_wav.name
|
32 |
|
33 |
|
34 |
def process_audio(audio_file):
|
35 |
+
try:
|
36 |
+
# Paso 1: Transcripción y traducción con Whisper
|
37 |
+
transcripcion_traducida = transcribir_audio(audio_file)
|
38 |
+
|
39 |
+
# Paso 2: Generación de audio con Bark
|
40 |
+
audio_sintetizado = generar_audio(transcripcion_traducida)
|
41 |
+
|
42 |
+
return transcripcion_traducida, audio_sintetizado
|
43 |
+
except Exception as e:
|
44 |
+
return str(e), None
|
45 |
+
|
46 |
|
47 |
|
48 |
# Crear interfaz Gradio
|