|
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" |
|
|
|
|
|
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) |
|
|