load static method
Future<KokoroEngine>
load(
- KokoroBundle bundle,
- KokoroChunkPolicy policy,
- KokoroStages stages,
- KokoroReader read,
Loads the phonemizer data of bundle. stages holds the sessions; the
engine closes them.
Implementation
static Future<KokoroEngine> load(
KokoroBundle bundle,
KokoroChunkPolicy policy,
KokoroStages stages,
KokoroReader read,
) async {
final engine = KokoroEngine._(bundle, policy, stages, read);
try {
if (bundle.voices.isEmpty) {
throw ArgumentError('At least one voice is required');
}
Future<String> text(String location) async =>
utf8.decode(await read(location));
Future<Map<String, dynamic>> json(String location) async =>
jsonDecode(await text(location)) as Map<String, dynamic>;
final fallback = engine._words.call;
final us = Misaki.load(
gold: await json(bundle.usGold),
silver: await json(bundle.usSilver),
spacyConfigJson: await text(bundle.spacyConfig),
spacyWeights: await read(bundle.spacyWeights),
fallback: fallback,
unk: '',
);
final gb = Misaki(
spacy: us.spacy,
g2p: MisakiG2P(
lexicon: MisakiLexicon(
gold: await json(bundle.gbGold),
silver: await json(bundle.gbSilver),
british: true,
),
fallback: fallback,
unk: '',
),
);
engine
.._us = us
.._gb = gb;
return engine;
} catch (_) {
await engine.close();
rethrow;
}
}