Spaces:
Sleeping
Sleeping
File size: 2,015 Bytes
18be831 3498704 c6699ff 18be831 3498704 18be831 3498704 18be831 3498704 18be831 3498704 18be831 3498704 18be831 3498704 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import whisper
from transformers import pipeline
import gradio as gr
import numpy as np
import torch
from bark import generate_audio
from scipy.io.wavfile import write
import tempfile
# Cargar el modelo Whisper-small y bark
transcribir = pipeline("automatic-speech-recognition", model="openai/whisper-small")
bark = pipeline("text-to-speech", model="suno/bark")
# Funci贸n para transcribir el audio y traducir el audio de entrada
def transcribir_audio(audio):
# Usamos el pipeline de Hugging Face para la transcripci贸n
result = transcribir_audio(audio)
return result["text"]
#Funci贸n para generar el audio
def generar_audio(text):
#Generar audio con Bark
audio_array = generate_audio(text)
# Normalizar el array de audio (opcional si Bark ya devuelve datos normalizados)
audio_array = np.clip(audio_array, -1.0, 1.0) # Asegurar que los valores est茅n en [-1.0, 1.0]
# Crear un archivo temporal para almacenar el audio
temp_wav = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
write(temp_wav.name, 24000, (audio_array * 32767).astype(np.int16)) # Guardar el archivo como WAV
return temp_wav.name
def process_audio(audio_file):
# Paso 1: Transcripci贸n y traducci贸n con Whisper
transcripcion_traducida = transcribir(audio_file)["text"]
# Paso 2: Generaci贸n de audio con Bark
audio_sintetizado = generar_audio(transcripcion_traducida)
return transcripcion_traducida, audio_sintetizado
# Crear interfaz Gradio
with gr.Blocks() as demo:
gr.Markdown("### Transcripci贸n y S铆ntesis de Voz")
with gr.Row():
input_audio = gr.Audio(label="Sube tu archivo de audio", type="filepath")
transcription_output = gr.Textbox(label="Texto transcrito")
output_audio = gr.Audio(label="Audio generado")
process_button = gr.Button("Procesar")
process_button.click(process_audio, inputs=input_audio, outputs=[transcription_output, output_audio])
# Lanzar la app
demo.launch() |