diff --git a/recognition_VAD/.formatter.exs b/recognition_VAD/.formatter.exs
new file mode 100644
index 00000000..e945e12b
--- /dev/null
+++ b/recognition_VAD/.formatter.exs
@@ -0,0 +1,5 @@
+[
+ import_deps: [:phoenix],
+ plugins: [Phoenix.LiveView.HTMLFormatter],
+ inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}"]
+]
diff --git a/recognition_VAD/.gitignore b/recognition_VAD/.gitignore
new file mode 100644
index 00000000..f75e0e2e
--- /dev/null
+++ b/recognition_VAD/.gitignore
@@ -0,0 +1,37 @@
+# The directory Mix will write compiled artifacts to.
+/_build/
+
+# If you run "mix test --cover", coverage assets end up here.
+/cover/
+
+# The directory Mix downloads your dependencies sources to.
+/deps/
+
+# Where 3rd-party dependencies like ExDoc output generated docs.
+/doc/
+
+# Ignore .fetch files in case you like to edit your project deps locally.
+/.fetch
+
+# If the VM crashes, it generates a dump, let's ignore it too.
+erl_crash.dump
+
+# Also ignore archive artifacts (built via "mix archive.build").
+*.ez
+
+# Temporary files, for example, from tests.
+/tmp/
+
+# Ignore package tarball (built via "mix hex.build").
+recognition_VAD-*.tar
+
+# Ignore assets that are produced by build tools.
+/priv/static/assets/
+
+# Ignore digested assets cache.
+/priv/static/cache_manifest.json
+
+# In case you use Node.js/npm, you want to ignore these.
+npm-debug.log
+/assets/node_modules/
+
diff --git a/recognition_VAD/README.md b/recognition_VAD/README.md
new file mode 100644
index 00000000..2e3443b6
--- /dev/null
+++ b/recognition_VAD/README.md
@@ -0,0 +1,18 @@
+# Recognition_VAD
+
+To start your Phoenix server:
+
+ * Run `mix setup` to install and setup dependencies
+ * Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
+
+Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
+
+Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
+
+## Learn more
+
+ * Official website: https://www.phoenixframework.org/
+ * Guides: https://hexdocs.pm/phoenix/overview.html
+ * Docs: https://hexdocs.pm/phoenix
+ * Forum: https://elixirforum.com/c/phoenix-forum
+ * Source: https://github.com/phoenixframework/phoenix
diff --git a/recognition_VAD/assets/css/app.css b/recognition_VAD/assets/css/app.css
new file mode 100644
index 00000000..d67ce14d
--- /dev/null
+++ b/recognition_VAD/assets/css/app.css
@@ -0,0 +1,86 @@
+@import "tailwindcss/base";
+@import "tailwindcss/components";
+@import "tailwindcss/utilities";
+
+/* This file is for your main application CSS */
+ body {
+ background-color: #f4f4f9;
+ color: #333;
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ height: 100vh;
+ margin: 0;
+ }
+ #container {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ width: 100%;
+ max-width: 700px;
+ padding: 20px;
+ box-sizing: border-box;
+ gap: 20px; /* Add more vertical space between items */
+ height: 90%; /* Fixed height to prevent layout shift */
+ }
+ #status {
+ color: #0056b3;
+ font-size: 20px;
+ text-align: center;
+ }
+ #transcriptionContainer {
+ height: 90px; /* Fixed height for approximately 3 lines of text */
+ overflow-y: auto;
+ width: 100%;
+ padding: 10px;
+ box-sizing: border-box;
+ background-color: #f9f9f9;
+ border: 1px solid #ddd;
+ border-radius: 5px;
+ }
+ #transcription {
+ font-size: 18px;
+ line-height: 1.6;
+ color: #333;
+ word-wrap: break-word;
+ }
+ #fullTextContainer {
+ height: 150px; /* Fixed height to prevent layout shift */
+ overflow-y: auto;
+ width: 100%;
+ padding: 10px;
+ box-sizing: border-box;
+ background-color: #f9f9f9;
+ border: 1px solid #ddd;
+ border-radius: 5px;
+ }
+ #fullText {
+ color: #4CAF50;
+ font-size: 18px;
+ font-weight: 600;
+ word-wrap: break-word;
+ }
+ .last-word {
+ color: #007bff;
+ font-weight: 600;
+ }
+ button {
+ padding: 12px 24px;
+ font-size: 16px;
+ cursor: pointer;
+ border: none;
+ border-radius: 5px;
+ margin: 5px;
+ transition: background-color 0.3s ease;
+ color: #fff;
+ background-color: #0056b3;
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
+ }
+ button:hover {
+ background-color: #007bff;
+ }
+ button:disabled {
+ background-color: #cccccc;
+ cursor: not-allowed;
+ }
\ No newline at end of file
diff --git a/recognition_VAD/assets/js/app.js b/recognition_VAD/assets/js/app.js
new file mode 100644
index 00000000..ce20ef7b
--- /dev/null
+++ b/recognition_VAD/assets/js/app.js
@@ -0,0 +1,45 @@
+// If you want to use Phoenix channels, run `mix help phx.gen.channel`
+// to get started and then uncomment the line below.
+// import "./user_socket.js"
+
+// You can include dependencies in two ways.
+//
+// The simplest option is to put them in assets/vendor and
+// import them using relative paths:
+//
+// import "../vendor/some-package.js"
+//
+// Alternatively, you can `npm install some-package --prefix assets` and import
+// them using a path starting with the package name:
+//
+// import "some-package"
+//
+
+// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
+import "phoenix_html"
+// Establish Phoenix Socket and LiveView configuration.
+import {Socket} from "phoenix"
+import {LiveSocket} from "phoenix_live_view"
+import topbar from "../vendor/topbar"
+import SttRecorder from "./stt_recorder.js";
+
+let liveSocket = new LiveSocket("/live", Socket, {
+ hooks: { SttRecorder },
+ params: { _csrf_token: csrfToken }
+});
+
+
+// Show progress bar on live navigation and form submits
+topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
+window.addEventListener("phx:page-loading-start", _info => topbar.show(300))
+window.addEventListener("phx:page-loading-stop", _info => topbar.hide())
+
+// connect if there are any LiveViews on the page
+liveSocket.connect()
+
+// expose liveSocket on window for web console debug logs and latency simulation:
+// >> liveSocket.enableDebug()
+// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
+// >> liveSocket.disableLatencySim()
+window.liveSocket = liveSocket
+
diff --git a/recognition_VAD/assets/js/stt_recorder.js b/recognition_VAD/assets/js/stt_recorder.js
new file mode 100644
index 00000000..4f3a3ba5
--- /dev/null
+++ b/recognition_VAD/assets/js/stt_recorder.js
@@ -0,0 +1,119 @@
+// assets/js/stt_recorder.js
+
+let SttRecorder = {
+ mounted() {
+ const statusDiv = document.getElementById("status");
+ const transcriptionDiv = document.getElementById("transcription");
+ const fullTextDiv = document.getElementById("fullText");
+ const startButton = document.getElementById("startButton");
+ const stopButton = document.getElementById("stopButton");
+
+ const controlURL = "ws://127.0.0.1:8011";
+ const dataURL = "ws://127.0.0.1:8012";
+ let dataSocket;
+ let audioContext;
+ let mediaStream;
+ let mediaProcessor;
+
+ // define startRecording and stopRecording here, or attach to this
+ window.startRecording = async function () {
+ try {
+ startButton.disabled = true;
+ stopButton.disabled = false;
+ statusDiv.textContent = "Recording...";
+ transcriptionDiv.textContent = "";
+ fullTextDiv.textContent = "";
+
+ audioContext = new AudioContext();
+ mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });
+ const input = audioContext.createMediaStreamSource(mediaStream);
+
+ mediaProcessor = audioContext.createScriptProcessor(1024, 1, 1);
+ mediaProcessor.onaudioprocess = (event) => {
+ const audioData = event.inputBuffer.getChannelData(0);
+ sendAudioChunk(audioData, audioContext.sampleRate);
+ };
+
+ input.connect(mediaProcessor);
+ mediaProcessor.connect(audioContext.destination);
+
+ connectToDataSocket();
+ } catch (error) {
+ console.error("Error accessing microphone:", error);
+ statusDiv.textContent = "Error accessing microphone.";
+ stopRecording();
+ }
+ };
+
+ window.stopRecording = function () {
+ if (mediaProcessor && audioContext) {
+ mediaProcessor.disconnect();
+ audioContext.close();
+ }
+
+ if (mediaStream) {
+ mediaStream.getTracks().forEach((track) => track.stop());
+ }
+
+ if (dataSocket) {
+ dataSocket.close();
+ }
+
+ startButton.disabled = false;
+ stopButton.disabled = true;
+ statusDiv.textContent = "Stopped recording.";
+ };
+
+ function connectToDataSocket() {
+ dataSocket = new WebSocket(dataURL);
+
+ dataSocket.onopen = () => {
+ statusDiv.textContent = "Connected to STT server.";
+ };
+
+ dataSocket.onmessage = (event) => {
+ try {
+ const message = JSON.parse(event.data);
+ if (message.type === "realtime") {
+ let words = message.text.split(" ");
+ let lastWord = words.pop();
+ transcriptionDiv.innerHTML = `${words.join(" ")} ${lastWord}`;
+ } else if (message.type === "fullSentence") {
+ fullTextDiv.innerHTML += message.text + " ";
+ transcriptionDiv.innerHTML = message.text;
+ }
+ } catch (e) {
+ console.error("Error parsing message:", e);
+ }
+ };
+
+ dataSocket.onerror = (error) => {
+ console.error("WebSocket error:", error);
+ statusDiv.textContent = "Error connecting to the STT server.";
+ };
+ }
+
+ function sendAudioChunk(audioData, sampleRate) {
+ if (dataSocket && dataSocket.readyState === WebSocket.OPEN) {
+ const float32Array = new Float32Array(audioData);
+ const pcm16Data = new Int16Array(float32Array.length);
+ for (let i = 0; i < float32Array.length; i++) {
+ pcm16Data[i] = Math.max(-1, Math.min(1, float32Array[i])) * 0x7fff;
+ }
+
+ const metadata = JSON.stringify({ sampleRate });
+ const metadataLength = new Uint32Array([metadata.length]);
+ const metadataBuffer = new TextEncoder().encode(metadata);
+
+ const message = new Uint8Array(metadataLength.byteLength + metadataBuffer.byteLength + pcm16Data.byteLength);
+ message.set(new Uint8Array(metadataLength.buffer), 0);
+ message.set(metadataBuffer, metadataLength.byteLength);
+ message.set(new Uint8Array(pcm16Data.buffer), metadataLength.byteLength + metadataBuffer.byteLength);
+
+ dataSocket.send(message);
+ }
+ }
+ },
+};
+
+export default SttRecorder;
diff --git a/recognition_VAD/assets/tailwind.config.js b/recognition_VAD/assets/tailwind.config.js
new file mode 100644
index 00000000..77a889a1
--- /dev/null
+++ b/recognition_VAD/assets/tailwind.config.js
@@ -0,0 +1,74 @@
+// See the Tailwind configuration guide for advanced usage
+// https://tailwindcss.com/docs/configuration
+
+const plugin = require("tailwindcss/plugin")
+const fs = require("fs")
+const path = require("path")
+
+module.exports = {
+ content: [
+ "./js/**/*.js",
+ "../lib/recognition_VAD_web.ex",
+ "../lib/recognition_VAD_web/**/*.*ex"
+ ],
+ theme: {
+ extend: {
+ colors: {
+ brand: "#FD4F00",
+ }
+ },
+ },
+ plugins: [
+ require("@tailwindcss/forms"),
+ // Allows prefixing tailwind classes with LiveView classes to add rules
+ // only when LiveView classes are applied, for example:
+ //
+ //
+ //
+ plugin(({addVariant}) => addVariant("phx-click-loading", [".phx-click-loading&", ".phx-click-loading &"])),
+ plugin(({addVariant}) => addVariant("phx-submit-loading", [".phx-submit-loading&", ".phx-submit-loading &"])),
+ plugin(({addVariant}) => addVariant("phx-change-loading", [".phx-change-loading&", ".phx-change-loading &"])),
+
+ // Embeds Heroicons (https://heroicons.com) into your app.css bundle
+ // See your `CoreComponents.icon/1` for more information.
+ //
+ plugin(function({matchComponents, theme}) {
+ let iconsDir = path.join(__dirname, "../deps/heroicons/optimized")
+ let values = {}
+ let icons = [
+ ["", "/24/outline"],
+ ["-solid", "/24/solid"],
+ ["-mini", "/20/solid"],
+ ["-micro", "/16/solid"]
+ ]
+ icons.forEach(([suffix, dir]) => {
+ fs.readdirSync(path.join(iconsDir, dir)).forEach(file => {
+ let name = path.basename(file, ".svg") + suffix
+ values[name] = {name, fullPath: path.join(iconsDir, dir, file)}
+ })
+ })
+ matchComponents({
+ "hero": ({name, fullPath}) => {
+ let content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, "")
+ let size = theme("spacing.6")
+ if (name.endsWith("-mini")) {
+ size = theme("spacing.5")
+ } else if (name.endsWith("-micro")) {
+ size = theme("spacing.4")
+ }
+ return {
+ [`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
+ "-webkit-mask": `var(--hero-${name})`,
+ "mask": `var(--hero-${name})`,
+ "mask-repeat": "no-repeat",
+ "background-color": "currentColor",
+ "vertical-align": "middle",
+ "display": "inline-block",
+ "width": size,
+ "height": size
+ }
+ }
+ }, {values})
+ })
+ ]
+}
diff --git a/recognition_VAD/assets/vendor/topbar.js b/recognition_VAD/assets/vendor/topbar.js
new file mode 100644
index 00000000..41957274
--- /dev/null
+++ b/recognition_VAD/assets/vendor/topbar.js
@@ -0,0 +1,165 @@
+/**
+ * @license MIT
+ * topbar 2.0.0, 2023-02-04
+ * https://buunguyen.github.io/topbar
+ * Copyright (c) 2021 Buu Nguyen
+ */
+(function (window, document) {
+ "use strict";
+
+ // https://gist.github.com/paulirish/1579671
+ (function () {
+ var lastTime = 0;
+ var vendors = ["ms", "moz", "webkit", "o"];
+ for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
+ window.requestAnimationFrame =
+ window[vendors[x] + "RequestAnimationFrame"];
+ window.cancelAnimationFrame =
+ window[vendors[x] + "CancelAnimationFrame"] ||
+ window[vendors[x] + "CancelRequestAnimationFrame"];
+ }
+ if (!window.requestAnimationFrame)
+ window.requestAnimationFrame = function (callback, element) {
+ var currTime = new Date().getTime();
+ var timeToCall = Math.max(0, 16 - (currTime - lastTime));
+ var id = window.setTimeout(function () {
+ callback(currTime + timeToCall);
+ }, timeToCall);
+ lastTime = currTime + timeToCall;
+ return id;
+ };
+ if (!window.cancelAnimationFrame)
+ window.cancelAnimationFrame = function (id) {
+ clearTimeout(id);
+ };
+ })();
+
+ var canvas,
+ currentProgress,
+ showing,
+ progressTimerId = null,
+ fadeTimerId = null,
+ delayTimerId = null,
+ addEvent = function (elem, type, handler) {
+ if (elem.addEventListener) elem.addEventListener(type, handler, false);
+ else if (elem.attachEvent) elem.attachEvent("on" + type, handler);
+ else elem["on" + type] = handler;
+ },
+ options = {
+ autoRun: true,
+ barThickness: 3,
+ barColors: {
+ 0: "rgba(26, 188, 156, .9)",
+ ".25": "rgba(52, 152, 219, .9)",
+ ".50": "rgba(241, 196, 15, .9)",
+ ".75": "rgba(230, 126, 34, .9)",
+ "1.0": "rgba(211, 84, 0, .9)",
+ },
+ shadowBlur: 10,
+ shadowColor: "rgba(0, 0, 0, .6)",
+ className: null,
+ },
+ repaint = function () {
+ canvas.width = window.innerWidth;
+ canvas.height = options.barThickness * 5; // need space for shadow
+
+ var ctx = canvas.getContext("2d");
+ ctx.shadowBlur = options.shadowBlur;
+ ctx.shadowColor = options.shadowColor;
+
+ var lineGradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
+ for (var stop in options.barColors)
+ lineGradient.addColorStop(stop, options.barColors[stop]);
+ ctx.lineWidth = options.barThickness;
+ ctx.beginPath();
+ ctx.moveTo(0, options.barThickness / 2);
+ ctx.lineTo(
+ Math.ceil(currentProgress * canvas.width),
+ options.barThickness / 2
+ );
+ ctx.strokeStyle = lineGradient;
+ ctx.stroke();
+ },
+ createCanvas = function () {
+ canvas = document.createElement("canvas");
+ var style = canvas.style;
+ style.position = "fixed";
+ style.top = style.left = style.right = style.margin = style.padding = 0;
+ style.zIndex = 100001;
+ style.display = "none";
+ if (options.className) canvas.classList.add(options.className);
+ document.body.appendChild(canvas);
+ addEvent(window, "resize", repaint);
+ },
+ topbar = {
+ config: function (opts) {
+ for (var key in opts)
+ if (options.hasOwnProperty(key)) options[key] = opts[key];
+ },
+ show: function (delay) {
+ if (showing) return;
+ if (delay) {
+ if (delayTimerId) return;
+ delayTimerId = setTimeout(() => topbar.show(), delay);
+ } else {
+ showing = true;
+ if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId);
+ if (!canvas) createCanvas();
+ canvas.style.opacity = 1;
+ canvas.style.display = "block";
+ topbar.progress(0);
+ if (options.autoRun) {
+ (function loop() {
+ progressTimerId = window.requestAnimationFrame(loop);
+ topbar.progress(
+ "+" + 0.05 * Math.pow(1 - Math.sqrt(currentProgress), 2)
+ );
+ })();
+ }
+ }
+ },
+ progress: function (to) {
+ if (typeof to === "undefined") return currentProgress;
+ if (typeof to === "string") {
+ to =
+ (to.indexOf("+") >= 0 || to.indexOf("-") >= 0
+ ? currentProgress
+ : 0) + parseFloat(to);
+ }
+ currentProgress = to > 1 ? 1 : to;
+ repaint();
+ return currentProgress;
+ },
+ hide: function () {
+ clearTimeout(delayTimerId);
+ delayTimerId = null;
+ if (!showing) return;
+ showing = false;
+ if (progressTimerId != null) {
+ window.cancelAnimationFrame(progressTimerId);
+ progressTimerId = null;
+ }
+ (function loop() {
+ if (topbar.progress("+.1") >= 1) {
+ canvas.style.opacity -= 0.05;
+ if (canvas.style.opacity <= 0.05) {
+ canvas.style.display = "none";
+ fadeTimerId = null;
+ return;
+ }
+ }
+ fadeTimerId = window.requestAnimationFrame(loop);
+ })();
+ },
+ };
+
+ if (typeof module === "object" && typeof module.exports === "object") {
+ module.exports = topbar;
+ } else if (typeof define === "function" && define.amd) {
+ define(function () {
+ return topbar;
+ });
+ } else {
+ this.topbar = topbar;
+ }
+}.call(this, window, document));
diff --git a/recognition_VAD/config/config.exs b/recognition_VAD/config/config.exs
new file mode 100644
index 00000000..3eee2063
--- /dev/null
+++ b/recognition_VAD/config/config.exs
@@ -0,0 +1,65 @@
+# This file is responsible for configuring your application
+# and its dependencies with the aid of the Config module.
+#
+# This configuration file is loaded before any dependency and
+# is restricted to this project.
+
+# General application configuration
+import Config
+
+config :recognition_VAD,
+ generators: [timestamp_type: :utc_datetime]
+
+# Configures the endpoint
+config :recognition_VAD, Recognition_VADWeb.Endpoint,
+ url: [host: "localhost"],
+ adapter: Bandit.PhoenixAdapter,
+ render_errors: [
+ formats: [html: Recognition_VADWeb.ErrorHTML, json: Recognition_VADWeb.ErrorJSON],
+ layout: false
+ ],
+ pubsub_server: Recognition_VAD.PubSub,
+ live_view: [signing_salt: "MLX284g+"]
+
+# Configures the mailer
+#
+# By default it uses the "Local" adapter which stores the emails
+# locally. You can see the emails in your browser, at "/dev/mailbox".
+#
+# For production it's recommended to configure a different adapter
+# at the `config/runtime.exs`.
+config :recognition_VAD, Recognition_VAD.Mailer, adapter: Swoosh.Adapters.Local
+
+# Configure esbuild (the version is required)
+config :esbuild,
+ version: "0.17.11",
+ recognition_VAD: [
+ args:
+ ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
+ cd: Path.expand("../assets", __DIR__),
+ env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
+ ]
+
+# Configure tailwind (the version is required)
+config :tailwind,
+ version: "3.4.3",
+ recognition_VAD: [
+ args: ~w(
+ --config=tailwind.config.js
+ --input=css/app.css
+ --output=../priv/static/assets/app.css
+ ),
+ cd: Path.expand("../assets", __DIR__)
+ ]
+
+# Configures Elixir's Logger
+config :logger, :console,
+ format: "$time $metadata[$level] $message\n",
+ metadata: [:request_id]
+
+# Use Jason for JSON parsing in Phoenix
+config :phoenix, :json_library, Jason
+
+# Import environment specific config. This must remain at the bottom
+# of this file so it overrides the configuration defined above.
+import_config "#{config_env()}.exs"
diff --git a/recognition_VAD/config/dev.exs b/recognition_VAD/config/dev.exs
new file mode 100644
index 00000000..4510846b
--- /dev/null
+++ b/recognition_VAD/config/dev.exs
@@ -0,0 +1,75 @@
+import Config
+
+# For development, we disable any cache and enable
+# debugging and code reloading.
+#
+# The watchers configuration can be used to run external
+# watchers to your application. For example, we can use it
+# to bundle .js and .css sources.
+config :recognition_VAD, Recognition_VADWeb.Endpoint,
+ # Binding to loopback ipv4 address prevents access from other machines.
+ # Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
+ http: [ip: {127, 0, 0, 1}, port: 4000],
+ check_origin: false,
+ code_reloader: true,
+ debug_errors: true,
+ secret_key_base: "Vr5UJCuEhKED1UfRZzpZUzgYNeaqg6D1FYHlWKW7k5xq+g14Lh3qXov2BXJzBloD",
+ watchers: [
+ esbuild: {Esbuild, :install_and_run, [:recognition_VAD, ~w(--sourcemap=inline --watch)]},
+ tailwind: {Tailwind, :install_and_run, [:recognition_VAD, ~w(--watch)]}
+ ]
+
+# ## SSL Support
+#
+# In order to use HTTPS in development, a self-signed
+# certificate can be generated by running the following
+# Mix task:
+#
+# mix phx.gen.cert
+#
+# Run `mix help phx.gen.cert` for more information.
+#
+# The `http:` config above can be replaced with:
+#
+# https: [
+# port: 4001,
+# cipher_suite: :strong,
+# keyfile: "priv/cert/selfsigned_key.pem",
+# certfile: "priv/cert/selfsigned.pem"
+# ],
+#
+# If desired, both `http:` and `https:` keys can be
+# configured to run both http and https servers on
+# different ports.
+
+# Watch static and templates for browser reloading.
+config :recognition_VAD, Recognition_VADWeb.Endpoint,
+ live_reload: [
+ patterns: [
+ ~r"priv/static/(?!uploads/).*(js|css|png|jpeg|jpg|gif|svg)$",
+ ~r"priv/gettext/.*(po)$",
+ ~r"lib/recognition_VAD_web/(controllers|live|components)/.*(ex|heex)$"
+ ]
+ ]
+
+# Enable dev routes for dashboard and mailbox
+config :recognition_VAD, dev_routes: true
+
+# Do not include metadata nor timestamps in development logs
+config :logger, :console, format: "[$level] $message\n"
+
+# Set a higher stacktrace during development. Avoid configuring such
+# in production as building large stacktraces may be expensive.
+config :phoenix, :stacktrace_depth, 20
+
+# Initialize plugs at runtime for faster development compilation
+config :phoenix, :plug_init_mode, :runtime
+
+config :phoenix_live_view,
+ # Include HEEx debug annotations as HTML comments in rendered markup
+ debug_heex_annotations: true,
+ # Enable helpful, but potentially expensive runtime checks
+ enable_expensive_runtime_checks: true
+
+# Disable swoosh api client as it is only required for production adapters.
+config :swoosh, :api_client, false
diff --git a/recognition_VAD/config/prod.exs b/recognition_VAD/config/prod.exs
new file mode 100644
index 00000000..e318b931
--- /dev/null
+++ b/recognition_VAD/config/prod.exs
@@ -0,0 +1,21 @@
+import Config
+
+# Note we also include the path to a cache manifest
+# containing the digested version of static files. This
+# manifest is generated by the `mix assets.deploy` task,
+# which you should run after static files are built and
+# before starting your production server.
+config :recognition_VAD, Recognition_VADWeb.Endpoint,
+ cache_static_manifest: "priv/static/cache_manifest.json"
+
+# Configures Swoosh API Client
+config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: Recognition_VAD.Finch
+
+# Disable Swoosh Local Memory Storage
+config :swoosh, local: false
+
+# Do not print debug messages in production
+config :logger, level: :info
+
+# Runtime production configuration, including reading
+# of environment variables, is done on config/runtime.exs.
diff --git a/recognition_VAD/config/runtime.exs b/recognition_VAD/config/runtime.exs
new file mode 100644
index 00000000..46b65cb1
--- /dev/null
+++ b/recognition_VAD/config/runtime.exs
@@ -0,0 +1,102 @@
+import Config
+
+# config/runtime.exs is executed for all environments, including
+# during releases. It is executed after compilation and before the
+# system starts, so it is typically used to load production configuration
+# and secrets from environment variables or elsewhere. Do not define
+# any compile-time configuration in here, as it won't be applied.
+# The block below contains prod specific runtime configuration.
+
+# ## Using releases
+#
+# If you use `mix release`, you need to explicitly enable the server
+# by passing the PHX_SERVER=true when you start it:
+#
+# PHX_SERVER=true bin/recognition_VAD start
+#
+# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
+# script that automatically sets the env var above.
+if System.get_env("PHX_SERVER") do
+ config :recognition_VAD, Recognition_VADWeb.Endpoint, server: true
+end
+
+if config_env() == :prod do
+ # The secret key base is used to sign/encrypt cookies and other secrets.
+ # A default value is used in config/dev.exs and config/test.exs but you
+ # want to use a different value for prod and you most likely don't want
+ # to check this value into version control, so we use an environment
+ # variable instead.
+ secret_key_base =
+ System.get_env("SECRET_KEY_BASE") ||
+ raise """
+ environment variable SECRET_KEY_BASE is missing.
+ You can generate one by calling: mix phx.gen.secret
+ """
+
+ host = System.get_env("PHX_HOST") || "example.com"
+ port = String.to_integer(System.get_env("PORT") || "4000")
+
+ config :recognition_VAD, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
+
+ config :recognition_VAD, Recognition_VADWeb.Endpoint,
+ url: [host: host, port: 443, scheme: "https"],
+ http: [
+ # Enable IPv6 and bind on all interfaces.
+ # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
+ # See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
+ # for details about using IPv6 vs IPv4 and loopback vs public addresses.
+ ip: {0, 0, 0, 0, 0, 0, 0, 0},
+ port: port
+ ],
+ secret_key_base: secret_key_base
+
+ # ## SSL Support
+ #
+ # To get SSL working, you will need to add the `https` key
+ # to your endpoint configuration:
+ #
+ # config :recognition_VAD, Recognition_VADWeb.Endpoint,
+ # https: [
+ # ...,
+ # port: 443,
+ # cipher_suite: :strong,
+ # keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
+ # certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
+ # ]
+ #
+ # The `cipher_suite` is set to `:strong` to support only the
+ # latest and more secure SSL ciphers. This means old browsers
+ # and clients may not be supported. You can set it to
+ # `:compatible` for wider support.
+ #
+ # `:keyfile` and `:certfile` expect an absolute path to the key
+ # and cert in disk or a relative path inside priv, for example
+ # "priv/ssl/server.key". For all supported SSL configuration
+ # options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
+ #
+ # We also recommend setting `force_ssl` in your config/prod.exs,
+ # ensuring no data is ever sent via http, always redirecting to https:
+ #
+ # config :recognition_VAD, Recognition_VADWeb.Endpoint,
+ # force_ssl: [hsts: true]
+ #
+ # Check `Plug.SSL` for all available options in `force_ssl`.
+
+ # ## Configuring the mailer
+ #
+ # In production you need to configure the mailer to use a different adapter.
+ # Also, you may need to configure the Swoosh API client of your choice if you
+ # are not using SMTP. Here is an example of the configuration:
+ #
+ # config :recognition_VAD, Recognition_VAD.Mailer,
+ # adapter: Swoosh.Adapters.Mailgun,
+ # api_key: System.get_env("MAILGUN_API_KEY"),
+ # domain: System.get_env("MAILGUN_DOMAIN")
+ #
+ # For this example you need include a HTTP client required by Swoosh API client.
+ # Swoosh supports Hackney and Finch out of the box:
+ #
+ # config :swoosh, :api_client, Swoosh.ApiClient.Hackney
+ #
+ # See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
+end
diff --git a/recognition_VAD/config/test.exs b/recognition_VAD/config/test.exs
new file mode 100644
index 00000000..2bb67337
--- /dev/null
+++ b/recognition_VAD/config/test.exs
@@ -0,0 +1,24 @@
+import Config
+
+# We don't run a server during test. If one is required,
+# you can enable the server option below.
+config :recognition_VAD, Recognition_VADWeb.Endpoint,
+ http: [ip: {127, 0, 0, 1}, port: 4002],
+ secret_key_base: "1f885tm3bNhDN7TED39kLx5WBNqvhjzjw6MD7vn8+taXmArC3gcbzaRM0mUli50v",
+ server: false
+
+# In test we don't send emails
+config :recognition_VAD, Recognition_VAD.Mailer, adapter: Swoosh.Adapters.Test
+
+# Disable swoosh api client as it is only required for production adapters
+config :swoosh, :api_client, false
+
+# Print only warnings and errors during test
+config :logger, level: :warning
+
+# Initialize plugs at runtime for faster test compilation
+config :phoenix, :plug_init_mode, :runtime
+
+# Enable helpful, but potentially expensive runtime checks
+config :phoenix_live_view,
+ enable_expensive_runtime_checks: true
diff --git a/recognition_VAD/lib/recognition_VAD.ex b/recognition_VAD/lib/recognition_VAD.ex
new file mode 100644
index 00000000..0f513733
--- /dev/null
+++ b/recognition_VAD/lib/recognition_VAD.ex
@@ -0,0 +1,9 @@
+defmodule Recognition_VAD do
+ @moduledoc """
+ Recognition_VAD keeps the contexts that define your domain
+ and business logic.
+
+ Contexts are also responsible for managing your data, regardless
+ if it comes from the database, an external API or others.
+ """
+end
diff --git a/recognition_VAD/lib/recognition_VAD/application.ex b/recognition_VAD/lib/recognition_VAD/application.ex
new file mode 100644
index 00000000..7c802ea4
--- /dev/null
+++ b/recognition_VAD/lib/recognition_VAD/application.ex
@@ -0,0 +1,36 @@
+defmodule Recognition_VAD.Application do
+ # See https://hexdocs.pm/elixir/Application.html
+ # for more information on OTP Applications
+ @moduledoc false
+
+ use Application
+
+ @impl true
+ def start(_type, _args) do
+ children = [
+ Recognition_VADWeb.Telemetry,
+ {DNSCluster, query: Application.get_env(:recognition_VAD, :dns_cluster_query) || :ignore},
+ {Phoenix.PubSub, name: Recognition_VAD.PubSub},
+ Recognition_VAD.AudioProcessor,
+ # Start the Finch HTTP client for sending emails
+ {Finch, name: Recognition_VAD.Finch},
+ # Start a worker by calling: Recognition_VAD.Worker.start_link(arg)
+ # {Recognition_VAD.Worker, arg},
+ # Start to serve requests, typically the last entry
+ Recognition_VADWeb.Endpoint
+ ]
+
+ # See https://hexdocs.pm/elixir/Supervisor.html
+ # for other strategies and supported options
+ opts = [strategy: :one_for_one, name: Recognition_VAD.Supervisor]
+ Supervisor.start_link(children, opts)
+ end
+
+ # Tell Phoenix to update the endpoint configuration
+ # whenever the application is updated.
+ @impl true
+ def config_change(changed, _new, removed) do
+ Recognition_VADWeb.Endpoint.config_change(changed, removed)
+ :ok
+ end
+end
diff --git a/recognition_VAD/lib/recognition_VAD/audio_processor.ex b/recognition_VAD/lib/recognition_VAD/audio_processor.ex
new file mode 100644
index 00000000..ae4e42ca
--- /dev/null
+++ b/recognition_VAD/lib/recognition_VAD/audio_processor.ex
@@ -0,0 +1,32 @@
+defmodule Recognition_VAD.AudioProcessor do
+ use GenServer
+ require Logger
+
+ def start_link(_opts) do
+ GenServer.start_link(__MODULE__, %{}, name: __MODULE__)
+ end
+
+ def init(_) do
+ {:ok, %{buffer: [], sample_rate: 0}}
+ end
+
+ def handle_cast({:chunk, binary_audio, sample_rate}, state) do
+ # 👇 Guardamos el chunk en el buffer
+ new_buffer = [binary_audio | state.buffer] |> Enum.take(100) # máximo 100 chunks
+
+ Logger.info("🟡 Recibido chunk de #{byte_size(binary_audio)} bytes a #{sample_rate} Hz")
+
+ {:noreply, %{state | buffer: new_buffer, sample_rate: sample_rate}}
+ end
+
+ def handle_cast(:save_wav, state) do
+ timestamp = DateTime.utc_now() |> DateTime.to_unix()
+ filename = "recording_#{timestamp}.wav"
+
+ Recognition_VAD.WavWriter.write_pcm_chunks_to_wav(state.buffer, state.sample_rate, filename)
+ Logger.info("💾 Guardado archivo: #{filename}")
+ {:noreply, state}
+ end
+
+
+end
diff --git a/recognition_VAD/lib/recognition_VAD/mailer.ex b/recognition_VAD/lib/recognition_VAD/mailer.ex
new file mode 100644
index 00000000..b428d007
--- /dev/null
+++ b/recognition_VAD/lib/recognition_VAD/mailer.ex
@@ -0,0 +1,3 @@
+defmodule Recognition_VAD.Mailer do
+ use Swoosh.Mailer, otp_app: :recognition_VAD
+end
diff --git a/recognition_VAD/lib/recognition_VAD/wav_writer.ex b/recognition_VAD/lib/recognition_VAD/wav_writer.ex
new file mode 100644
index 00000000..dd61a6bc
--- /dev/null
+++ b/recognition_VAD/lib/recognition_VAD/wav_writer.ex
@@ -0,0 +1,29 @@
+defmodule Recognition_VAD.WavWriter do
+ def write_pcm_chunks_to_wav(chunks, sample_rate, path) do
+ data = IO.iodata_to_binary(Enum.reverse(chunks))
+
+ num_channels = 1
+ bits_per_sample = 16
+ byte_rate = sample_rate * num_channels * div(bits_per_sample, 8)
+ block_align = div(bits_per_sample * num_channels, 8)
+
+ header =
+ <<
+ "RIFF",
+ 36 + byte_size(data)::little-size(32),
+ "WAVE",
+ "fmt ",
+ 16::little-size(32),
+ 1::little-size(16),
+ num_channels::little-size(16),
+ sample_rate::little-size(32),
+ byte_rate::little-size(32),
+ block_align::little-size(16),
+ bits_per_sample::little-size(16),
+ "data",
+ byte_size(data)::little-size(32)
+ >>
+
+ File.write!(path, header <> data)
+ end
+end
diff --git a/recognition_VAD/lib/recognition_VAD_web.ex b/recognition_VAD/lib/recognition_VAD_web.ex
new file mode 100644
index 00000000..0e65231a
--- /dev/null
+++ b/recognition_VAD/lib/recognition_VAD_web.ex
@@ -0,0 +1,116 @@
+defmodule Recognition_VADWeb do
+ @moduledoc """
+ The entrypoint for defining your web interface, such
+ as controllers, components, channels, and so on.
+
+ This can be used in your application as:
+
+ use Recognition_VADWeb, :controller
+ use Recognition_VADWeb, :html
+
+ The definitions below will be executed for every controller,
+ component, etc, so keep them short and clean, focused
+ on imports, uses and aliases.
+
+ Do NOT define functions inside the quoted expressions
+ below. Instead, define additional modules and import
+ those modules here.
+ """
+
+ def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)
+
+ def router do
+ quote do
+ use Phoenix.Router, helpers: false
+
+ # Import common connection and controller functions to use in pipelines
+ import Plug.Conn
+ import Phoenix.Controller
+ import Phoenix.LiveView.Router
+ end
+ end
+
+ def channel do
+ quote do
+ use Phoenix.Channel
+ end
+ end
+
+ def controller do
+ quote do
+ use Phoenix.Controller,
+ formats: [:html, :json],
+ layouts: [html: Recognition_VADWeb.Layouts]
+
+ use Gettext, backend: Recognition_VADWeb.Gettext
+
+ import Plug.Conn
+
+ unquote(verified_routes())
+ end
+ end
+
+ def live_view do
+ quote do
+ use Phoenix.LiveView,
+ layout: {Recognition_VADWeb.Layouts, :app}
+
+ unquote(html_helpers())
+ end
+ end
+
+ def live_component do
+ quote do
+ use Phoenix.LiveComponent
+
+ unquote(html_helpers())
+ end
+ end
+
+ def html do
+ quote do
+ use Phoenix.Component
+
+ # Import convenience functions from controllers
+ import Phoenix.Controller,
+ only: [get_csrf_token: 0, view_module: 1, view_template: 1]
+
+ # Include general helpers for rendering HTML
+ unquote(html_helpers())
+ end
+ end
+
+ defp html_helpers do
+ quote do
+ # Translation
+ use Gettext, backend: Recognition_VADWeb.Gettext
+
+ # HTML escaping functionality
+ import Phoenix.HTML
+ # Core UI components
+ import Recognition_VADWeb.CoreComponents
+
+ # Shortcut for generating JS commands
+ alias Phoenix.LiveView.JS
+
+ # Routes generation with the ~p sigil
+ unquote(verified_routes())
+ end
+ end
+
+ def verified_routes do
+ quote do
+ use Phoenix.VerifiedRoutes,
+ endpoint: Recognition_VADWeb.Endpoint,
+ router: Recognition_VADWeb.Router,
+ statics: Recognition_VADWeb.static_paths()
+ end
+ end
+
+ @doc """
+ When used, dispatch to the appropriate controller/live_view/etc.
+ """
+ defmacro __using__(which) when is_atom(which) do
+ apply(__MODULE__, which, [])
+ end
+end
diff --git a/recognition_VAD/lib/recognition_VAD_web/channels/control_channel.ex b/recognition_VAD/lib/recognition_VAD_web/channels/control_channel.ex
new file mode 100644
index 00000000..7edaf9de
--- /dev/null
+++ b/recognition_VAD/lib/recognition_VAD_web/channels/control_channel.ex
@@ -0,0 +1,17 @@
+defmodule Recognition_VADWeb.ControlChannel do
+ use Phoenix.Channel
+
+ def join("control:lobby", _payload, socket) do
+ {:ok, socket}
+ end
+
+ def handle_in("set_parameter", %{"parameter" => param, "value" => value}, socket) do
+ GenServer.cast(Recognition_VAD.Transcriber, {:set_param, param, value})
+ {:reply, {:ok, %{message: "Parameter updated"}}, socket}
+ end
+
+ def handle_in("call_method", %{"method" => method}, socket) do
+ GenServer.cast(Recognition_VAD.Transcriber, {:call_method, method})
+ {:reply, {:ok, %{message: "Method called"}}, socket}
+ end
+end
diff --git a/recognition_VAD/lib/recognition_VAD_web/channels/data_channel.ex b/recognition_VAD/lib/recognition_VAD_web/channels/data_channel.ex
new file mode 100644
index 00000000..ac87dfff
--- /dev/null
+++ b/recognition_VAD/lib/recognition_VAD_web/channels/data_channel.ex
@@ -0,0 +1,35 @@
+defmodule Recognition_VADWeb.DataChannel do
+ use Phoenix.Channel
+
+ def join("data:lobby", _params, socket) do
+ Phoenix.PubSub.subscribe(Recognition_VAD.PubSub, "audio_output")
+ {:ok, socket}
+ end
+
+ def handle_info({:broadcast_audio, msg}, socket) do
+ push(socket, "transcription", Jason.decode!(msg))
+ {:noreply, socket}
+ end
+
+ # Recibe audio codificado en base64 (para transporte seguro)
+ def handle_in("audio_chunk", %{"data" => base64_chunk, "sample_rate" => sample_rate}, socket) do
+ case Base.decode64(base64_chunk) do
+ {:ok, binary_audio} ->
+ GenServer.cast(Recognition_VAD.AudioProcessor, {:chunk, binary_audio, sample_rate})
+ {:noreply, socket}
+
+ :error ->
+ IO.puts("⚠️ Error al decodificar base64")
+ {:reply, {:error, %{reason: "Invalid base64 audio"}}, socket}
+ end
+ end
+
+ def handle_in("save_audio", _params, socket) do
+ GenServer.cast(Recognition_VAD.AudioProcessor, :save_wav)
+ {:noreply, socket}
+ end
+
+ def handle_in(_unknown, _payload, socket) do
+ {:noreply, socket}
+ end
+end
diff --git a/recognition_VAD/lib/recognition_VAD_web/channels/user_socket.ex b/recognition_VAD/lib/recognition_VAD_web/channels/user_socket.ex
new file mode 100644
index 00000000..f68d7e08
--- /dev/null
+++ b/recognition_VAD/lib/recognition_VAD_web/channels/user_socket.ex
@@ -0,0 +1,9 @@
+defmodule Recognition_VADWeb.UserSocket do
+ use Phoenix.Socket
+
+ channel "control:*", Recognition_VADWeb.ControlChanel
+ channel "data:*", Recognition_VADWeb.DataChannel
+
+ def connect(_params, socket, _connect_info), do: {:ok, socket}
+ def id(_socket), do: nil
+end
diff --git a/recognition_VAD/lib/recognition_VAD_web/components/core_components.ex b/recognition_VAD/lib/recognition_VAD_web/components/core_components.ex
new file mode 100644
index 00000000..466e7872
--- /dev/null
+++ b/recognition_VAD/lib/recognition_VAD_web/components/core_components.ex
@@ -0,0 +1,676 @@
+defmodule Recognition_VADWeb.CoreComponents do
+ @moduledoc """
+ Provides core UI components.
+
+ At first glance, this module may seem daunting, but its goal is to provide
+ core building blocks for your application, such as modals, tables, and
+ forms. The components consist mostly of markup and are well-documented
+ with doc strings and declarative assigns. You may customize and style
+ them in any way you want, based on your application growth and needs.
+
+ The default components use Tailwind CSS, a utility-first CSS framework.
+ See the [Tailwind CSS documentation](https://tailwindcss.com) to learn
+ how to customize them or feel free to swap in another framework altogether.
+
+ Icons are provided by [heroicons](https://heroicons.com). See `icon/1` for usage.
+ """
+ use Phoenix.Component
+ use Gettext, backend: Recognition_VADWeb.Gettext
+
+ alias Phoenix.LiveView.JS
+
+ @doc """
+ Renders a modal.
+
+ ## Examples
+
+ <.modal id="confirm-modal">
+ This is a modal.
+
+
+ JS commands may be passed to the `:on_cancel` to configure
+ the closing/cancel event, for example:
+
+ <.modal id="confirm" on_cancel={JS.navigate(~p"/posts")}>
+ This is another modal.
+
+
+ """
+ attr :id, :string, required: true
+ attr :show, :boolean, default: false
+ attr :on_cancel, JS, default: %JS{}
+ slot :inner_block, required: true
+
+ def modal(assigns) do
+ ~H"""
+
+ """
+ end
+
+ @doc """
+ Shows the flash group with standard titles and content.
+
+ ## Examples
+
+ <.flash_group flash={@flash} />
+ """
+ attr :flash, :map, required: true, doc: "the map of flash messages"
+ attr :id, :string, default: "flash-group", doc: "the optional id of flash container"
+
+ def flash_group(assigns) do
+ ~H"""
+
+ <.flash kind={:info} title={gettext("Success!")} flash={@flash} />
+ <.flash kind={:error} title={gettext("Error!")} flash={@flash} />
+ <.flash
+ id="client-error"
+ kind={:error}
+ title={gettext("We can't find the internet")}
+ phx-disconnected={show(".phx-client-error #client-error")}
+ phx-connected={hide("#client-error")}
+ hidden
+ >
+ {gettext("Attempting to reconnect")}
+ <.icon name="hero-arrow-path" class="ml-1 h-3 w-3 animate-spin" />
+
+
+ <.flash
+ id="server-error"
+ kind={:error}
+ title={gettext("Something went wrong!")}
+ phx-disconnected={show(".phx-server-error #server-error")}
+ phx-connected={hide("#server-error")}
+ hidden
+ >
+ {gettext("Hang in there while we get back on track")}
+ <.icon name="hero-arrow-path" class="ml-1 h-3 w-3 animate-spin" />
+
+
+ """
+ end
+
+ @doc """
+ Renders a simple form.
+
+ ## Examples
+
+ <.simple_form for={@form} phx-change="validate" phx-submit="save">
+ <.input field={@form[:email]} label="Email"/>
+ <.input field={@form[:username]} label="Username" />
+ <:actions>
+ <.button>Save
+
+
+ """
+ attr :for, :any, required: true, doc: "the data structure for the form"
+ attr :as, :any, default: nil, doc: "the server side parameter to collect all input under"
+
+ attr :rest, :global,
+ include: ~w(autocomplete name rel action enctype method novalidate target multipart),
+ doc: "the arbitrary HTML attributes to apply to the form tag"
+
+ slot :inner_block, required: true
+ slot :actions, doc: "the slot for form actions, such as a submit button"
+
+ def simple_form(assigns) do
+ ~H"""
+ <.form :let={f} for={@for} as={@as} {@rest}>
+
+ {render_slot(@inner_block, f)}
+
+ {render_slot(action, f)}
+
+
+
+ """
+ end
+
+ @doc """
+ Renders a button.
+
+ ## Examples
+
+ <.button>Send!
+ <.button phx-click="go" class="ml-2">Send!
+ """
+ attr :type, :string, default: nil
+ attr :class, :string, default: nil
+ attr :rest, :global, include: ~w(disabled form name value)
+
+ slot :inner_block, required: true
+
+ def button(assigns) do
+ ~H"""
+
+ """
+ end
+
+ @doc """
+ Renders an input with label and error messages.
+
+ A `Phoenix.HTML.FormField` may be passed as argument,
+ which is used to retrieve the input name, id, and values.
+ Otherwise all attributes may be passed explicitly.
+
+ ## Types
+
+ This function accepts all HTML input types, considering that:
+
+ * You may also set `type="select"` to render a `