Files
voice_recognition/whisper2/lib/whisper/application.ex

64 lines
1.9 KiB
Elixir

defmodule Whisper.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
args = parse_args(System.argv())
client = args[:client] || System.get_env("CLIENT") || "cuda"
Application.put_env(:whisper, :client, String.to_atom(client))
Application.put_env(:whisper, :model_name, args[:model] || System.get_env("MODEL") || "openai/whisper-tiny")
Application.put_env(:whisper, :batch_size, args[:batch_size] || String.to_integer(System.get_env("BATCH_SIZE") || "3"))
Application.put_env(:whisper, :batch_timeout, args[:batch_timeout] || String.to_integer(System.get_env("BATCH_TIMEOUT") || "3000"))
Application.put_env(:whisper, :port, args[:port] || String.to_integer(System.get_env("PORT") || "4003"))
children = [
Whisper.RealtimeModel,
Whisper.LargeModel,
# Whisper.Transcriber,
# {Plug.Cowboy, scheme: :http, plug: Whisper, options: [port: Application.get_env(:whisper, :port)]},
{Registry, keys: :unique, name: Whisper.Registry},
{Registry, keys: :unique, name: Whisper.AudioRegistry},
{Phoenix.PubSub, name: Whisper.PubSub},
WhisperWeb.Endpoint,
Whisper.Counter,
AudioBuffer
# AudioFilesList
]
opts = [strategy: :one_for_one, name: Whisper.Supervisor]
Supervisor.start_link(children, opts)
end
@impl true
def config_change(changed, _new, removed) do
WhisperWeb.Endpoint.config_change(changed, removed)
:ok
end
defp parse_args(argv) do
{opts, _, _} = OptionParser.parse(argv,
switches: [
batch_size: :integer,
batch_timeout: :integer,
client: :string,
model: :string,
port: :integer
],
aliases: [
b: :batch_size,
t: :batch_timeout,
c: :client,
m: :model,
p: :port
]
)
opts
end
end