File size: 1,405 Bytes
70e5c60 |
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 |
import gradio as gr
import csv
import os
import difflib
from pydub import AudioSegment
from pydub.playback import play
DATASET = "dataset.csv"
AUDIO_DIR = "voces"
# Carga el dataset
def cargar_dataset():
with open(DATASET, newline='', encoding='utf-8') as f:
reader = csv.DictReader(f)
return [{"path": row["path"], "text": row["text"].lower().strip()} for row in reader]
dataset = cargar_dataset()
def buscar_audio(texto):
texto = texto.lower().strip()
coincidencias = difflib.get_close_matches(texto, [d["text"] for d in dataset], n=1, cutoff=0.6)
if not coincidencias:
return None, "❌ No encontré coincidencias."
for d in dataset:
if d["text"] == coincidencias[0]:
ruta = d["path"]
return ruta, f"🔊 Reproduciendo: {ruta}"
return None, "❌ Algo falló."
def demo_func(texto):
ruta, mensaje = buscar_audio(texto)
if ruta:
return ruta, mensaje
else:
return None, mensaje
demo = gr.Interface(
fn=demo_func,
inputs=gr.Textbox(label="Texto para buscar en tu voz real"),
outputs=[gr.Audio(label="Audio encontrado"), gr.Textbox(label="Resultado")],
title="🐽 Voz Kuchiyuya - Búsqueda de frase grabada",
description="Introduce una frase parecida a una grabada. El sistema reproducirá el clip más cercano."
)
if __name__ == "__main__":
demo.launch(share=True)
|