VoskEx.Model (VoskEx v0.2.1)

View Source

High-level wrapper for Vosk speech recognition model.

A model represents a trained language model that can be used to create recognizers. Models are loaded once and can be shared across multiple recognizers and processes.

Model Sources

Models can be downloaded from Vosk Models. Available languages include: English, Spanish, German, French, Russian, Chinese, and many more.

Use the Mix task to download models easily:

mix vosk.download_model en          # Download small English model
mix vosk.download_model es          # Download Spanish model
mix vosk.download_model vosk-model-small-en-us-0.15  # Download specific model

Thread Safety

Models are thread-safe and reference-counted by Vosk. You can safely share a model across multiple processes and recognizers. Resources are automatically cleaned up when no longer referenced.

Summary

Functions

Check if a word exists in the model's vocabulary.

Load a model from a directory path.

Load a model from a directory path, raising on error.

Types

t()

@type t() :: %VoskEx.Model{ref: reference()}

Functions

find_word(model, word)

@spec find_word(t(), String.t()) :: integer()

Check if a word exists in the model's vocabulary.

Returns the word symbol (>= 0) if found, or -1 if not found.

Examples

iex> model = VoskEx.Model.load!("path/to/model")
iex> VoskEx.Model.find_word(model, "hello")
42  # word symbol

iex> VoskEx.Model.find_word(model, "xyzabc")
-1  # not found

load(path)

@spec load(String.t()) :: {:ok, t()} | {:error, :model_load_failed}

Load a model from a directory path.

Examples

iex> VoskEx.Model.load("path/to/vosk-model-small-en-us-0.15")
{:ok, %VoskEx.Model{}}

iex> VoskEx.Model.load("invalid/path")
{:error, :model_load_failed}

load!(path)

@spec load!(String.t()) :: t()

Load a model from a directory path, raising on error.

Examples

iex> VoskEx.Model.load!("path/to/vosk-model")
%VoskEx.Model{}