Streaming speech-to-text providers.
A provider is a process, usually a WebSocket client, that one owner feeds with audio and that reports back with messages:
{:ok, stt} = Octoroom.Agent.STT.start_link("soniox:stt-rt-v6", sample_rate: 16_000)
Octoroom.Agent.STT.send_audio(stt, pcm)
# receive {:stt, ^stt, {:final, "hello"}}Options
start_link/2 takes a provider and options. The provider is a
"provider:model" string, a registered name, or a module; options can also
name it with :provider and :model. Every provider takes:
:owner- the process that gets the events (default: the caller):api_key- defaults to the provider's environment variable:model- needed: no provider picks one for you:sample_rate- of the audio sent: 16-bit little-endian mono PCM:language_hints
Anything else is passed to the provider, which ignores what it doesn't use.
Events
The owner gets {:stt, pid, event}, where event is:
:connected- audio sent from now on is heard{:partial, text}- an interim transcript of the current utterance{:final, text}- the final transcript of an utterance, after the provider's endpointing or afinalize/1. Afterfinalize/1, it comes even iftextis"":finished- the provider is done, afterclose/1{:warning, reason}- something went wrong but the session goes on{:error, reason}- the session failed;reasonis a string or a map with:messagewhen the provider gave one{:disconnected, reason, %{intentional?: boolean}}- the connection closed; intentional afterclose/1
Adding a provider
Implement this behaviour, sending events with notify/2, and register it:
config :octoroom_agents, stt_providers: [acme: MyApp.AcmeSTT]A module that implements the behaviour also works as :provider without
being registered.
Summary
Callbacks
Flushes the audio sent, then ends the session.
Options used when the caller doesn't give them, such as :sample_rate.
Finalizes what's been heard so far, without waiting for the provider's
endpointing. Answered with a {:final, text}. Providers without it just
wait for their endpointing.
Starts a session that sends events to opts[:owner].
Functions
A message for a user to read about an {:error, reason} event.
Asks module's session to finalize, if the provider can.
Sends event from the calling provider process to owner.
The registered providers, by name.
Finds the provider for opts. Returns the module and its options, with
the provider's defaults filled in.
Starts a session. See the module docs for provider and opts.
Types
Callbacks
@callback close(pid()) :: :ok
Flushes the audio sent, then ends the session.
@callback default_options() :: keyword()
Options used when the caller doesn't give them, such as :sample_rate.
@callback finalize(pid()) :: :ok
Finalizes what's been heard so far, without waiting for the provider's
endpointing. Answered with a {:final, text}. Providers without it just
wait for their endpointing.
Starts a session that sends events to opts[:owner].
Functions
A message for a user to read about an {:error, reason} event.
Asks module's session to finalize, if the provider can.
Sends event from the calling provider process to owner.
The registered providers, by name.
Finds the provider for opts. Returns the module and its options, with
the provider's defaults filled in.
Starts a session. See the module docs for provider and opts.