fromMap static method
Implementation
static IsolateCommand fromMap(Map map) {
final command = map['command'] as String?;
switch (command) {
case 'set_surah_reference':
final rawRules = map['wordRules'] as List?;
final List<List<WordTajweedRule>>? wordRules = rawRules?.map((l) {
return (l as List)
.map((r) => WordTajweedRule.fromMap(r as Map))
.toList();
}).toList();
return SetSurahReferenceCommand(
fullPhonemes: map['phonemes'] as String,
boundaries: (map['boundaries'] as List).cast<int>(),
surahNumber: map['surahNumber'] as int? ?? 0,
isTajweed: map['isTajweed'] as bool? ?? false,
forceClear: map['forceClear'] as bool? ?? false,
startGlobalWord: map['startGlobalWord'] as int? ?? 0,
wordRules: wordRules,
);
case 'sync_stream':
return SyncStreamCommand(
asrText:
map['text'] as String? ??
(map['tokens'] as List?)?.join('') ??
'',
timestamps: (map['timestamps'] as List?)?.cast<double>() ?? const [],
isNewSegment: map['is_new_segment'] as bool? ?? false,
ayahNumber: map['ayah_number'] as int? ?? 0,
);
case 'jump_to_word':
return JumpToWordCommand(
globalWordIndex: map['global_word_index'] as int? ?? 0,
);
case 'set_tajweed_mode':
return SetTajweedModeCommand(
isTajweed: map['is_tajweed'] as bool? ?? false,
);
case 'update_config':
return UpdateTrackerConfigCommand(
config: TrackerConfig(
defaultMaxPathCost: (map['defaultMaxPathCost'] as num?)?.toDouble() ?? 0.30,
shortWordPathCost: (map['shortWordPathCost'] as num?)?.toDouble() ?? 0.25,
mediumWordPathCost: (map['mediumWordPathCost'] as num?)?.toDouble() ?? 0.28,
maxSkipWords: map['maxSkipWords'] as int? ?? 2,
acousticConfusionCost: (map['acousticConfusionCost'] as num?)?.toDouble() ?? 0.25,
standardInsertionCost: (map['standardInsertionCost'] as num?)?.toDouble() ?? 0.75,
standardDeletionCost: (map['standardDeletionCost'] as num?)?.toDouble() ?? 1.0,
harakatDurationSeconds: (map['harakatDurationSeconds'] as num?)?.toDouble() ?? 0.200,
maxTokenDurationAllowed: (map['maxTokenDurationAllowed'] as num?)?.toDouble() ?? 2.5,
lookaheadDelay: (map['lookaheadDelay'] as num?)?.toDouble() ?? 0.320,
hideExpectedAsrNoise: map['hideExpectedAsrNoise'] as bool? ?? true,
),
);
case 'stop':
return const StopIsolateCommand();
default:
throw ArgumentError('Unknown IsolateCommand: $command');
}
}