| 1 | enum PiperTtsModelVariant { enUsLessacMedium, enUsRyanMedium } |
| 2 | |
| 3 | extension PiperTtsModelVariantExtension on PiperTtsModelVariant { |
| 4 | String get id { |
| 5 | switch (this) { |
| 6 | case PiperTtsModelVariant.enUsLessacMedium: |
| 7 | return 'en_US-lessac-medium'; |
| 8 | case PiperTtsModelVariant.enUsRyanMedium: |
| 9 | return 'en_US-ryan-medium'; |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | String get displayName { |
| 14 | switch (this) { |
| 15 | case PiperTtsModelVariant.enUsLessacMedium: |
| 16 | return 'English (US) - Lessac (Medium)'; |
| 17 | case PiperTtsModelVariant.enUsRyanMedium: |
| 18 | return 'English (US) - Ryan (Medium)'; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | String get modelFileName => '$id.onnx'; |
| 23 | String get configFileName => '$id.onnx.json'; |
| 24 | String get bundleDirName { |
| 25 | return 'vits-piper-$id'; |
| 26 | } |
| 27 | |
| 28 | String get tarballUrl => |
| 29 | 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/$bundleDirName.tar.bz2'; |
| 30 | |
| 31 | String get tokensFileName => 'tokens.txt'; |
| 32 | String get dataDirName => 'espeak-ng-data'; |
| 33 | |
| 34 | int get totalSizeBytes { |
| 35 | switch (this) { |
| 36 | case PiperTtsModelVariant.enUsLessacMedium: |
| 37 | case PiperTtsModelVariant.enUsRyanMedium: |
| 38 | return 60 * 1024 * 1024; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | bool get isRecommended => this == PiperTtsModelVariant.enUsLessacMedium; |
| 43 | } |
| 44 | |
| 45 | class PiperTtsFileProgress { |
| 46 | final String fileName; |
| 47 | final int receivedBytes; |
| 48 | final int totalBytes; |
| 49 | final bool isComplete; |
| 50 | |
| 51 | const PiperTtsFileProgress({ |
| 52 | required this.fileName, |
| 53 | required this.receivedBytes, |
| 54 | required this.totalBytes, |
| 55 | required this.isComplete, |
| 56 | }); |
| 57 | |
| 58 | double get fraction { |
| 59 | if (totalBytes <= 0) return 0; |
| 60 | return (receivedBytes / totalBytes).clamp(0.0, 1.0); |
| 61 | } |
| 62 | } |