VoiceEngine.STT behaviour (voice_engine v0.1.0)

Copy Markdown View Source

Behaviour for speech-to-text adapters.

Streaming is modelled as a state machine:

  • stream_start/1 → opaque stream ref
  • stream_chunk/2 → feed audio, get updated ref
  • stream_end/1 → finalise, return transcript

Implementations may proxy real streaming APIs or buffer locally.

Summary

Types

stream_ref()

@type stream_ref() :: term()

transcript()

@type transcript() :: %{
  :text => String.t(),
  optional(:confidence) => number() | nil,
  optional(:alternatives) => [map()],
  optional(:raw) => term()
}

Callbacks

stream_chunk(stream_ref, chunk)

@callback stream_chunk(stream_ref(), chunk :: binary()) ::
  {:ok, stream_ref()} | {:error, term()}

stream_end(stream_ref)

@callback stream_end(stream_ref()) :: {:ok, transcript()} | {:error, term()}

stream_start(opts)

@callback stream_start(opts :: keyword()) :: {:ok, stream_ref()} | {:error, term()}

transcribe(audio, opts)

@callback transcribe(audio :: binary(), opts :: keyword()) ::
  {:ok, transcript()} | {:error, term()}