downloadModel method

Future<void> downloadModel({
  1. required String model,
  2. CactusProgressCallback? downloadProcessCallback,
})

Implementation

Future<void> downloadModel({
  required String model,
  final CactusProgressCallback? downloadProcessCallback,
}) async {
  if (await _isModelDownloaded(model)) {
    return;
  }

  final voiceModels = await Supabase.fetchVoiceModels();
  final currentModel = voiceModels.firstWhere(
    (m) => m.slug == model,
    orElse: () => throw Exception('Voice model $model not found'),
  );

  final task = DownloadTask(
    url: currentModel.downloadUrl,
    filename: currentModel.fileName,
    folder: currentModel.slug,
  );

  final success = await DownloadService.downloadAndExtractModels([task], downloadProcessCallback);
  if (!success) {
    throw Exception('Failed to download and extract voice model $model from ${currentModel.downloadUrl}');
  }
}