Class WhisperGrammar

All Implemented Interfaces:
AutoCloseable

public class WhisperGrammar extends WhisperJNI.WhisperJNIPointer
The WhisperGrammar class represents a native whisper.cpp parsed grammar.

You need to dispose the native memory for its instances by calling close()

Author:
Miguel Álvarez Díez - Initial contribution
  • Constructor Details

    • WhisperGrammar

      protected WhisperGrammar(WhisperJNI whisper, int ref, String text)
      Internal context constructor
      Parameters:
      whisper - library instance
      ref - native pointer identifier
  • Method Details

    • close

      public void close()
    • assertValidGrammar

      public static void assertValidGrammar(Path grammar) throws ParseException, IOException
      Java implementation of a GBNF grammar validator. Asserts the provided grammar is valid to use with whisper.cpp. Meaning it must contain a root expression with termination which sub-expressions can be resolved.
      Parameters:
      grammar - path to a GBNF grammar.
      Throws:
      ParseException - if grammar is invalid.
      IOException
    • assertValidGrammar

      public static void assertValidGrammar(String grammarText) throws ParseException
      Java implementation of a whisper.cpp grammar validator. Asserts the provided grammar is valid to use with whisper.cpp. Meaning it must contain a root expression with termination which subexpressions can be resolved.
      Parameters:
      grammarText - GBNF grammar text.
      Throws:
      ParseException - if grammar is invalid.