correccion VAD en formato binario pcm16 - agrego transcripcion al live

This commit is contained in:
2025-08-01 21:22:11 +00:00
parent e43a8c01a7
commit 976e350436
11 changed files with 133 additions and 123 deletions

View File

@ -1,28 +1,48 @@
defmodule WhisperWeb.VadLive do
use WhisperWeb, :live_view
alias Phoenix.PubSub
def mount(_, _, socket) do
{:ok, assign(socket, started: false)}
PubSub.subscribe(Whisper.PubSub, "transcription")
socket =
socket
|> assign(:transcription, "")
|> assign(:started, false)
{:ok, socket}
end
def handle_event("start_vad", _params, socket) do
push_event(socket, "init-vad", %{})
{:noreply, assign(socket, started: true)}
end
def handle_info({:transcription, raw_json}, socket) do
new_text =
raw_json
|> Jason.decode!()
|> get_in(["chunks", Access.at(0), "text"])
{:noreply, update(socket, :transcription, &(&1 <> " " <> new_text))}
end
def render(assigns) do
~H"""
<div id="vad-container" phx-hook="VadHook">
<button phx-click="start_vad" class="btn btn-primary">🎙 Iniciar VAD</button>
<button phx-click="stop_vad" class="btn btn-danger">🛑 Detener VAD</button>
<div id="vad-status" class="mt-4 text-sm text-gray-700"></div>
</div>
<div id="transcriptionContainer" class="w-full max-w-2xl space-y-4">
<%= if @transcription != "" do %>
<div class="p-4 bg-gray-100 rounded shadow-md">
<h2 class="text-sm font-semibold text-gray-700 mb-2">✅ Transcripción</h2>
<p class="text-green-600 whitespace-pre-wrap break-words text-sm leading-relaxed"><%= @transcription %></p>
</div>
<% end %>
</div>
"""
end
def handle_event("start_vad", _, socket) do
push_event(socket, "init-vad", %{})
{:noreply, socket}
end
def handle_event("stop_vad", _, socket) do
push_event(socket, "stop-vad", %{})
{:noreply, socket}
end
end