requireLiteRtLmAudioEncoder function

void requireLiteRtLmAudioEncoder(
  1. String modelPath
)

Throws EmbedderLoadException unless the .litertlm bundle at modelPath has an audio encoder, read from its container header (D23: ModelInfo claims audio on the 270m and the 440m). A header this reader cannot parse is a load failure, never "no audio".

LiteRtEmbeddingBackend.describe() calls it for declared audio, and the pass's load() again as a backstop. In describe() is where it matters: core calls describe() before it closes the embedder it holds, so a refusal there leaves that embedder working, while one from load() comes after the close.

Implementation

void requireLiteRtLmAudioEncoder(String modelPath) {
  final file = _fileName(modelPath);
  Never cannotRead(Object e, String reason) =>
      throw liteRtLmUnreadableContainer(file, reason, e);
  final List<String> types;
  try {
    types = readLitertlmModelTypes(modelPath);
  } on FileSystemException catch (e) {
    cannotRead(e, e.osError?.message ?? e.message);
  } on FormatException catch (e) {
    cannotRead(e, e.message);
  }
  if (!litertlmHasAudioEncoder(types)) throw liteRtLmNoAudioEncoder(file);
}