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

@ -26,22 +26,20 @@ defmodule WhisperWeb.AudioChannel do
<<header_len::16, rest::binary>> = raw_binary
<<header::binary-size(header_len), audio::binary>> = rest
IO.inspect(header, label: "HEADER BINARIO RECIBIDO")
%{"sample_rate" => rate} = Jason.decode!(header)
ref = socket_id(socket)
case Jason.decode(header) do
{:ok, %{"sample_rate" => rate}} ->
Logger.info("Chunk recibido: #{byte_size(audio)} bytes, sample_rate: #{rate}")
AudioBuffer.append(socket_id(socket), {rate, audio})
{:noreply, socket}
Logger.info("Chunk recibido: #{byte_size(audio)} bytes, sample_rate: #{rate}")
AudioBuffer.append(ref, {rate, audio})
{:error, reason} ->
Logger.error("Error decodificando header JSON: #{inspect(reason)}")
{:noreply, socket}
end
# {:ok, path} = AudioSaver.save_chunk_as_wav(ref, audio, rate, "part")
# AudioFilesList.add_file(path)
{:noreply, socket}
end
@doc """
Recupera todos los chunks acumulados en el buffer, los concatena y guarda un archivo WAV final (sufijo `"final"`).
"""
@ -60,8 +58,8 @@ defmodule WhisperWeb.AudioChannel do
Task.start(fn ->
transcription = Whisper.SendToModel.large(path)
Logger.info("✅ Transcripción completa:\n#{transcription}")
# message = %{"chunks" => [%{"text" => transcription}]}
# Phoenix.PubSub.broadcast(Whisper.PubSub, "transcription", {:transcription_m, Jason.encode!(message)})
message = %{"chunks" => [%{"text" => transcription}]}
Phoenix.PubSub.broadcast(Whisper.PubSub, "transcription", {:transcription, Jason.encode!(message)})
File.rm!(path)
end)
end