KittenTtsEngine.load constructor

KittenTtsEngine.load({
  1. required String snapshotPath,
  2. required String espeakLibPath,
  3. required String espeakDataPath,
  4. String voice = 'en-us',
})

Loads all model components from a snapshot directory.

snapshotPath — directory containing model.safetensors, config.json, and voices.npz. espeakLibPath — path to libespeak-ng.dylib. espeakDataPath — path to the espeak-ng-data directory. voice — eSpeak voice identifier (default en-us).

Implementation

factory KittenTtsEngine.load({
  required String snapshotPath,
  required String espeakLibPath,
  required String espeakDataPath,
  String voice = 'en-us',
}) {
  final config = ModelConfig.fromSnapshot(snapshotPath);
  final tensors = loadKittenTensors(snapshotPath);
  final voices = loadKittenVoices(snapshotPath, config);

  final front = KittenFrontRunner.fromTensors(
    config: config,
    tensors: tensors,
  );

  final activationQuant = config.activationQuantModules.contains('decoder');
  final decoder = KittenDecoder.load(
    tensors,
    prefix: 'decoder',
    config: config,
    activationQuant: activationQuant,
  );

  final g2p = EspeakG2p(
    libraryPath: espeakLibPath,
    dataPath: espeakDataPath,
    voice: voice,
  );

  return KittenTtsEngine._(
    config: config,
    front: front,
    decoder: decoder,
    voices: voices,
    g2p: g2p,
  );
}