正在显示
11 个修改的文件
包含
817 行增加
和
17 行删除
| @@ -8,11 +8,24 @@ import './sherpa_onnx_bindings.dart'; | @@ -8,11 +8,24 @@ import './sherpa_onnx_bindings.dart'; | ||
| 8 | class OfflineZipformerAudioTaggingModelConfig { | 8 | class OfflineZipformerAudioTaggingModelConfig { |
| 9 | const OfflineZipformerAudioTaggingModelConfig({this.model = ''}); | 9 | const OfflineZipformerAudioTaggingModelConfig({this.model = ''}); |
| 10 | 10 | ||
| 11 | + factory OfflineZipformerAudioTaggingModelConfig.fromJson( | ||
| 12 | + Map<String, dynamic> map) { | ||
| 13 | + return OfflineZipformerAudioTaggingModelConfig( | ||
| 14 | + model: map['model'] ?? '', | ||
| 15 | + ); | ||
| 16 | + } | ||
| 17 | + | ||
| 11 | @override | 18 | @override |
| 12 | String toString() { | 19 | String toString() { |
| 13 | return 'OfflineZipformerAudioTaggingModelConfig(model: $model)'; | 20 | return 'OfflineZipformerAudioTaggingModelConfig(model: $model)'; |
| 14 | } | 21 | } |
| 15 | 22 | ||
| 23 | + Map<String, dynamic> toJson() { | ||
| 24 | + return { | ||
| 25 | + 'model': model, | ||
| 26 | + }; | ||
| 27 | + } | ||
| 28 | + | ||
| 16 | final String model; | 29 | final String model; |
| 17 | } | 30 | } |
| 18 | 31 | ||
| @@ -24,11 +37,32 @@ class AudioTaggingModelConfig { | @@ -24,11 +37,32 @@ class AudioTaggingModelConfig { | ||
| 24 | this.provider = 'cpu', | 37 | this.provider = 'cpu', |
| 25 | this.debug = true}); | 38 | this.debug = true}); |
| 26 | 39 | ||
| 40 | + factory AudioTaggingModelConfig.fromJson(Map<String, dynamic> map) { | ||
| 41 | + return AudioTaggingModelConfig( | ||
| 42 | + zipformer: | ||
| 43 | + OfflineZipformerAudioTaggingModelConfig.fromJson(map['zipformer']), | ||
| 44 | + ced: map['ced'] ?? '', | ||
| 45 | + numThreads: map['numThreads'] ?? 1, | ||
| 46 | + provider: map['provider'] ?? 'cpu', | ||
| 47 | + debug: map['debug'] ?? true, | ||
| 48 | + ); | ||
| 49 | + } | ||
| 50 | + | ||
| 27 | @override | 51 | @override |
| 28 | String toString() { | 52 | String toString() { |
| 29 | return 'AudioTaggingModelConfig(zipformer: $zipformer, ced: $ced, numThreads: $numThreads, provider: $provider, debug: $debug)'; | 53 | return 'AudioTaggingModelConfig(zipformer: $zipformer, ced: $ced, numThreads: $numThreads, provider: $provider, debug: $debug)'; |
| 30 | } | 54 | } |
| 31 | 55 | ||
| 56 | + Map<String, dynamic> toJson() { | ||
| 57 | + return { | ||
| 58 | + 'zipformer': zipformer.toJson(), | ||
| 59 | + 'ced': ced, | ||
| 60 | + 'numThreads': numThreads, | ||
| 61 | + 'provider': provider, | ||
| 62 | + 'debug': debug, | ||
| 63 | + }; | ||
| 64 | + } | ||
| 65 | + | ||
| 32 | final OfflineZipformerAudioTaggingModelConfig zipformer; | 66 | final OfflineZipformerAudioTaggingModelConfig zipformer; |
| 33 | final String ced; | 67 | final String ced; |
| 34 | final int numThreads; | 68 | final int numThreads; |
| @@ -39,11 +73,25 @@ class AudioTaggingModelConfig { | @@ -39,11 +73,25 @@ class AudioTaggingModelConfig { | ||
| 39 | class AudioTaggingConfig { | 73 | class AudioTaggingConfig { |
| 40 | AudioTaggingConfig({required this.model, this.labels = ''}); | 74 | AudioTaggingConfig({required this.model, this.labels = ''}); |
| 41 | 75 | ||
| 76 | + factory AudioTaggingConfig.fromJson(Map<String, dynamic> map) { | ||
| 77 | + return AudioTaggingConfig( | ||
| 78 | + model: AudioTaggingModelConfig.fromJson(map['model']), | ||
| 79 | + labels: map['labels'] ?? '', | ||
| 80 | + ); | ||
| 81 | + } | ||
| 82 | + | ||
| 42 | @override | 83 | @override |
| 43 | String toString() { | 84 | String toString() { |
| 44 | return 'AudioTaggingConfig(model: $model, labels: $labels)'; | 85 | return 'AudioTaggingConfig(model: $model, labels: $labels)'; |
| 45 | } | 86 | } |
| 46 | 87 | ||
| 88 | + Map<String, dynamic> toJson() { | ||
| 89 | + return { | ||
| 90 | + 'model': model.toJson(), | ||
| 91 | + 'labels': labels, | ||
| 92 | + }; | ||
| 93 | + } | ||
| 94 | + | ||
| 47 | final AudioTaggingModelConfig model; | 95 | final AudioTaggingModelConfig model; |
| 48 | final String labels; | 96 | final String labels; |
| 49 | } | 97 | } |
| @@ -51,11 +99,27 @@ class AudioTaggingConfig { | @@ -51,11 +99,27 @@ class AudioTaggingConfig { | ||
| 51 | class AudioEvent { | 99 | class AudioEvent { |
| 52 | AudioEvent({required this.name, required this.index, required this.prob}); | 100 | AudioEvent({required this.name, required this.index, required this.prob}); |
| 53 | 101 | ||
| 102 | + factory AudioEvent.fromJson(Map<String, dynamic> map) { | ||
| 103 | + return AudioEvent( | ||
| 104 | + name: map['name'], | ||
| 105 | + index: map['index'], | ||
| 106 | + prob: map['prob'], | ||
| 107 | + ); | ||
| 108 | + } | ||
| 109 | + | ||
| 54 | @override | 110 | @override |
| 55 | String toString() { | 111 | String toString() { |
| 56 | return 'AudioEvent(name: $name, index: $index, prob: $prob)'; | 112 | return 'AudioEvent(name: $name, index: $index, prob: $prob)'; |
| 57 | } | 113 | } |
| 58 | 114 | ||
| 115 | + Map<String, dynamic> toJson() { | ||
| 116 | + return { | ||
| 117 | + 'name': name, | ||
| 118 | + 'index': index, | ||
| 119 | + 'prob': prob, | ||
| 120 | + }; | ||
| 121 | + } | ||
| 122 | + | ||
| 59 | final String name; | 123 | final String name; |
| 60 | final int index; | 124 | final int index; |
| 61 | final double prob; | 125 | final double prob; |
| @@ -3,11 +3,23 @@ | @@ -3,11 +3,23 @@ | ||
| 3 | class FeatureConfig { | 3 | class FeatureConfig { |
| 4 | const FeatureConfig({this.sampleRate = 16000, this.featureDim = 80}); | 4 | const FeatureConfig({this.sampleRate = 16000, this.featureDim = 80}); |
| 5 | 5 | ||
| 6 | + factory FeatureConfig.fromJson(Map<String, dynamic> json) { | ||
| 7 | + return FeatureConfig( | ||
| 8 | + sampleRate: json['sampleRate'] as int? ?? 16000, | ||
| 9 | + featureDim: json['featureDim'] as int? ?? 80, | ||
| 10 | + ); | ||
| 11 | + } | ||
| 12 | + | ||
| 6 | @override | 13 | @override |
| 7 | String toString() { | 14 | String toString() { |
| 8 | return 'FeatureConfig(sampleRate: $sampleRate, featureDim: $featureDim)'; | 15 | return 'FeatureConfig(sampleRate: $sampleRate, featureDim: $featureDim)'; |
| 9 | } | 16 | } |
| 10 | 17 | ||
| 18 | + Map<String, dynamic> toJson() => { | ||
| 19 | + 'sampleRate': sampleRate, | ||
| 20 | + 'featureDim': featureDim, | ||
| 21 | + }; | ||
| 22 | + | ||
| 11 | final int sampleRate; | 23 | final int sampleRate; |
| 12 | final int featureDim; | 24 | final int featureDim; |
| 13 | } | 25 | } |
| @@ -23,11 +23,40 @@ class KeywordSpotterConfig { | @@ -23,11 +23,40 @@ class KeywordSpotterConfig { | ||
| 23 | this.keywordsBufSize = 0, | 23 | this.keywordsBufSize = 0, |
| 24 | }); | 24 | }); |
| 25 | 25 | ||
| 26 | + factory KeywordSpotterConfig.fromJson(Map<String, dynamic> json) { | ||
| 27 | + return KeywordSpotterConfig( | ||
| 28 | + feat: json['feat'] != null | ||
| 29 | + ? FeatureConfig.fromJson(json['feat'] as Map<String, dynamic>) | ||
| 30 | + : const FeatureConfig(), | ||
| 31 | + model: OnlineModelConfig.fromJson(json['model'] as Map<String, dynamic>), | ||
| 32 | + maxActivePaths: json['maxActivePaths'] as int? ?? 4, | ||
| 33 | + numTrailingBlanks: json['numTrailingBlanks'] as int? ?? 1, | ||
| 34 | + keywordsScore: (json['keywordsScore'] as num?)?.toDouble() ?? 1.0, | ||
| 35 | + keywordsThreshold: | ||
| 36 | + (json['keywordsThreshold'] as num?)?.toDouble() ?? 0.25, | ||
| 37 | + keywordsFile: json['keywordsFile'] as String? ?? '', | ||
| 38 | + keywordsBuf: json['keywordsBuf'] as String? ?? '', | ||
| 39 | + keywordsBufSize: json['keywordsBufSize'] as int? ?? 0, | ||
| 40 | + ); | ||
| 41 | + } | ||
| 42 | + | ||
| 26 | @override | 43 | @override |
| 27 | String toString() { | 44 | String toString() { |
| 28 | return 'KeywordSpotterConfig(feat: $feat, model: $model, maxActivePaths: $maxActivePaths, numTrailingBlanks: $numTrailingBlanks, keywordsScore: $keywordsScore, keywordsThreshold: $keywordsThreshold, keywordsFile: $keywordsFile, keywordsBuf: $keywordsBuf, keywordsBufSize: $keywordsBufSize)'; | 45 | return 'KeywordSpotterConfig(feat: $feat, model: $model, maxActivePaths: $maxActivePaths, numTrailingBlanks: $numTrailingBlanks, keywordsScore: $keywordsScore, keywordsThreshold: $keywordsThreshold, keywordsFile: $keywordsFile, keywordsBuf: $keywordsBuf, keywordsBufSize: $keywordsBufSize)'; |
| 29 | } | 46 | } |
| 30 | 47 | ||
| 48 | + Map<String, dynamic> toJson() => { | ||
| 49 | + 'feat': feat.toJson(), | ||
| 50 | + 'model': model.toJson(), | ||
| 51 | + 'maxActivePaths': maxActivePaths, | ||
| 52 | + 'numTrailingBlanks': numTrailingBlanks, | ||
| 53 | + 'keywordsScore': keywordsScore, | ||
| 54 | + 'keywordsThreshold': keywordsThreshold, | ||
| 55 | + 'keywordsFile': keywordsFile, | ||
| 56 | + 'keywordsBuf': keywordsBuf, | ||
| 57 | + 'keywordsBufSize': keywordsBufSize, | ||
| 58 | + }; | ||
| 59 | + | ||
| 31 | final FeatureConfig feat; | 60 | final FeatureConfig feat; |
| 32 | final OnlineModelConfig model; | 61 | final OnlineModelConfig model; |
| 33 | 62 | ||
| @@ -44,11 +73,21 @@ class KeywordSpotterConfig { | @@ -44,11 +73,21 @@ class KeywordSpotterConfig { | ||
| 44 | class KeywordResult { | 73 | class KeywordResult { |
| 45 | KeywordResult({required this.keyword}); | 74 | KeywordResult({required this.keyword}); |
| 46 | 75 | ||
| 76 | + factory KeywordResult.fromJson(Map<String, dynamic> json) { | ||
| 77 | + return KeywordResult( | ||
| 78 | + keyword: json['keyword'] as String? ?? '', | ||
| 79 | + ); | ||
| 80 | + } | ||
| 81 | + | ||
| 47 | @override | 82 | @override |
| 48 | String toString() { | 83 | String toString() { |
| 49 | return 'KeywordResult(keyword: $keyword)'; | 84 | return 'KeywordResult(keyword: $keyword)'; |
| 50 | } | 85 | } |
| 51 | 86 | ||
| 87 | + Map<String, dynamic> toJson() => { | ||
| 88 | + 'keyword': keyword, | ||
| 89 | + }; | ||
| 90 | + | ||
| 52 | final String keyword; | 91 | final String keyword; |
| 53 | } | 92 | } |
| 54 | 93 |
| @@ -11,11 +11,27 @@ class OfflinePunctuationModelConfig { | @@ -11,11 +11,27 @@ class OfflinePunctuationModelConfig { | ||
| 11 | this.provider = 'cpu', | 11 | this.provider = 'cpu', |
| 12 | this.debug = true}); | 12 | this.debug = true}); |
| 13 | 13 | ||
| 14 | + factory OfflinePunctuationModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 15 | + return OfflinePunctuationModelConfig( | ||
| 16 | + ctTransformer: json['ctTransformer'] as String, | ||
| 17 | + numThreads: json['numThreads'] as int? ?? 1, | ||
| 18 | + provider: json['provider'] as String? ?? 'cpu', | ||
| 19 | + debug: json['debug'] as bool? ?? true, | ||
| 20 | + ); | ||
| 21 | + } | ||
| 22 | + | ||
| 14 | @override | 23 | @override |
| 15 | String toString() { | 24 | String toString() { |
| 16 | return 'OfflinePunctuationModelConfig(ctTransformer: $ctTransformer, numThreads: $numThreads, provider: $provider, debug: $debug)'; | 25 | return 'OfflinePunctuationModelConfig(ctTransformer: $ctTransformer, numThreads: $numThreads, provider: $provider, debug: $debug)'; |
| 17 | } | 26 | } |
| 18 | 27 | ||
| 28 | + Map<String, dynamic> toJson() => { | ||
| 29 | + 'ctTransformer': ctTransformer, | ||
| 30 | + 'numThreads': numThreads, | ||
| 31 | + 'provider': provider, | ||
| 32 | + 'debug': debug, | ||
| 33 | + }; | ||
| 34 | + | ||
| 19 | final String ctTransformer; | 35 | final String ctTransformer; |
| 20 | final int numThreads; | 36 | final int numThreads; |
| 21 | final String provider; | 37 | final String provider; |
| @@ -27,11 +43,22 @@ class OfflinePunctuationConfig { | @@ -27,11 +43,22 @@ class OfflinePunctuationConfig { | ||
| 27 | required this.model, | 43 | required this.model, |
| 28 | }); | 44 | }); |
| 29 | 45 | ||
| 46 | + factory OfflinePunctuationConfig.fromJson(Map<String, dynamic> json) { | ||
| 47 | + return OfflinePunctuationConfig( | ||
| 48 | + model: OfflinePunctuationModelConfig.fromJson( | ||
| 49 | + json['model'] as Map<String, dynamic>), | ||
| 50 | + ); | ||
| 51 | + } | ||
| 52 | + | ||
| 30 | @override | 53 | @override |
| 31 | String toString() { | 54 | String toString() { |
| 32 | return 'OfflinePunctuationConfig(model: $model)'; | 55 | return 'OfflinePunctuationConfig(model: $model)'; |
| 33 | } | 56 | } |
| 34 | 57 | ||
| 58 | + Map<String, dynamic> toJson() => { | ||
| 59 | + 'model': model.toJson(), | ||
| 60 | + }; | ||
| 61 | + | ||
| 35 | final OfflinePunctuationModelConfig model; | 62 | final OfflinePunctuationModelConfig model; |
| 36 | } | 63 | } |
| 37 | 64 |
| @@ -16,11 +16,25 @@ class OfflineTransducerModelConfig { | @@ -16,11 +16,25 @@ class OfflineTransducerModelConfig { | ||
| 16 | this.joiner = '', | 16 | this.joiner = '', |
| 17 | }); | 17 | }); |
| 18 | 18 | ||
| 19 | + factory OfflineTransducerModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 20 | + return OfflineTransducerModelConfig( | ||
| 21 | + encoder: json['encoder'] as String? ?? '', | ||
| 22 | + decoder: json['decoder'] as String? ?? '', | ||
| 23 | + joiner: json['joiner'] as String? ?? '', | ||
| 24 | + ); | ||
| 25 | + } | ||
| 26 | + | ||
| 19 | @override | 27 | @override |
| 20 | String toString() { | 28 | String toString() { |
| 21 | return 'OfflineTransducerModelConfig(encoder: $encoder, decoder: $decoder, joiner: $joiner)'; | 29 | return 'OfflineTransducerModelConfig(encoder: $encoder, decoder: $decoder, joiner: $joiner)'; |
| 22 | } | 30 | } |
| 23 | 31 | ||
| 32 | + Map<String, dynamic> toJson() => { | ||
| 33 | + 'encoder': encoder, | ||
| 34 | + 'decoder': decoder, | ||
| 35 | + 'joiner': joiner, | ||
| 36 | + }; | ||
| 37 | + | ||
| 24 | final String encoder; | 38 | final String encoder; |
| 25 | final String decoder; | 39 | final String decoder; |
| 26 | final String joiner; | 40 | final String joiner; |
| @@ -29,22 +43,42 @@ class OfflineTransducerModelConfig { | @@ -29,22 +43,42 @@ class OfflineTransducerModelConfig { | ||
| 29 | class OfflineParaformerModelConfig { | 43 | class OfflineParaformerModelConfig { |
| 30 | const OfflineParaformerModelConfig({this.model = ''}); | 44 | const OfflineParaformerModelConfig({this.model = ''}); |
| 31 | 45 | ||
| 46 | + factory OfflineParaformerModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 47 | + return OfflineParaformerModelConfig( | ||
| 48 | + model: json['model'] as String? ?? '', | ||
| 49 | + ); | ||
| 50 | + } | ||
| 51 | + | ||
| 32 | @override | 52 | @override |
| 33 | String toString() { | 53 | String toString() { |
| 34 | return 'OfflineParaformerModelConfig(model: $model)'; | 54 | return 'OfflineParaformerModelConfig(model: $model)'; |
| 35 | } | 55 | } |
| 36 | 56 | ||
| 57 | + Map<String, dynamic> toJson() => { | ||
| 58 | + 'model': model, | ||
| 59 | + }; | ||
| 60 | + | ||
| 37 | final String model; | 61 | final String model; |
| 38 | } | 62 | } |
| 39 | 63 | ||
| 40 | class OfflineNemoEncDecCtcModelConfig { | 64 | class OfflineNemoEncDecCtcModelConfig { |
| 41 | const OfflineNemoEncDecCtcModelConfig({this.model = ''}); | 65 | const OfflineNemoEncDecCtcModelConfig({this.model = ''}); |
| 42 | 66 | ||
| 67 | + factory OfflineNemoEncDecCtcModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 68 | + return OfflineNemoEncDecCtcModelConfig( | ||
| 69 | + model: json['model'] as String? ?? '', | ||
| 70 | + ); | ||
| 71 | + } | ||
| 72 | + | ||
| 43 | @override | 73 | @override |
| 44 | String toString() { | 74 | String toString() { |
| 45 | return 'OfflineNemoEncDecCtcModelConfig(model: $model)'; | 75 | return 'OfflineNemoEncDecCtcModelConfig(model: $model)'; |
| 46 | } | 76 | } |
| 47 | 77 | ||
| 78 | + Map<String, dynamic> toJson() => { | ||
| 79 | + 'model': model, | ||
| 80 | + }; | ||
| 81 | + | ||
| 48 | final String model; | 82 | final String model; |
| 49 | } | 83 | } |
| 50 | 84 | ||
| @@ -56,11 +90,29 @@ class OfflineWhisperModelConfig { | @@ -56,11 +90,29 @@ class OfflineWhisperModelConfig { | ||
| 56 | this.task = '', | 90 | this.task = '', |
| 57 | this.tailPaddings = -1}); | 91 | this.tailPaddings = -1}); |
| 58 | 92 | ||
| 93 | + factory OfflineWhisperModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 94 | + return OfflineWhisperModelConfig( | ||
| 95 | + encoder: json['encoder'] as String? ?? '', | ||
| 96 | + decoder: json['decoder'] as String? ?? '', | ||
| 97 | + language: json['language'] as String? ?? '', | ||
| 98 | + task: json['task'] as String? ?? '', | ||
| 99 | + tailPaddings: json['tailPaddings'] as int? ?? -1, | ||
| 100 | + ); | ||
| 101 | + } | ||
| 102 | + | ||
| 59 | @override | 103 | @override |
| 60 | String toString() { | 104 | String toString() { |
| 61 | return 'OfflineWhisperModelConfig(encoder: $encoder, decoder: $decoder, language: $language, task: $task, tailPaddings: $tailPaddings)'; | 105 | return 'OfflineWhisperModelConfig(encoder: $encoder, decoder: $decoder, language: $language, task: $task, tailPaddings: $tailPaddings)'; |
| 62 | } | 106 | } |
| 63 | 107 | ||
| 108 | + Map<String, dynamic> toJson() => { | ||
| 109 | + 'encoder': encoder, | ||
| 110 | + 'decoder': decoder, | ||
| 111 | + 'language': language, | ||
| 112 | + 'task': task, | ||
| 113 | + 'tailPaddings': tailPaddings, | ||
| 114 | + }; | ||
| 115 | + | ||
| 64 | final String encoder; | 116 | final String encoder; |
| 65 | final String decoder; | 117 | final String decoder; |
| 66 | final String language; | 118 | final String language; |
| @@ -69,15 +121,25 @@ class OfflineWhisperModelConfig { | @@ -69,15 +121,25 @@ class OfflineWhisperModelConfig { | ||
| 69 | } | 121 | } |
| 70 | 122 | ||
| 71 | class OfflineFireRedAsrModelConfig { | 123 | class OfflineFireRedAsrModelConfig { |
| 72 | - const OfflineFireRedAsrModelConfig( | ||
| 73 | - {this.encoder = '', | ||
| 74 | - this.decoder = ''}); | 124 | + const OfflineFireRedAsrModelConfig({this.encoder = '', this.decoder = ''}); |
| 125 | + | ||
| 126 | + factory OfflineFireRedAsrModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 127 | + return OfflineFireRedAsrModelConfig( | ||
| 128 | + encoder: json['encoder'] as String? ?? '', | ||
| 129 | + decoder: json['decoder'] as String? ?? '', | ||
| 130 | + ); | ||
| 131 | + } | ||
| 75 | 132 | ||
| 76 | @override | 133 | @override |
| 77 | String toString() { | 134 | String toString() { |
| 78 | return 'OfflineFireRedAsrModelConfig(encoder: $encoder, decoder: $decoder)'; | 135 | return 'OfflineFireRedAsrModelConfig(encoder: $encoder, decoder: $decoder)'; |
| 79 | } | 136 | } |
| 80 | 137 | ||
| 138 | + Map<String, dynamic> toJson() => { | ||
| 139 | + 'encoder': encoder, | ||
| 140 | + 'decoder': decoder, | ||
| 141 | + }; | ||
| 142 | + | ||
| 81 | final String encoder; | 143 | final String encoder; |
| 82 | final String decoder; | 144 | final String decoder; |
| 83 | } | 145 | } |
| @@ -89,11 +151,27 @@ class OfflineMoonshineModelConfig { | @@ -89,11 +151,27 @@ class OfflineMoonshineModelConfig { | ||
| 89 | this.uncachedDecoder = '', | 151 | this.uncachedDecoder = '', |
| 90 | this.cachedDecoder = ''}); | 152 | this.cachedDecoder = ''}); |
| 91 | 153 | ||
| 154 | + factory OfflineMoonshineModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 155 | + return OfflineMoonshineModelConfig( | ||
| 156 | + preprocessor: json['preprocessor'] as String? ?? '', | ||
| 157 | + encoder: json['encoder'] as String? ?? '', | ||
| 158 | + uncachedDecoder: json['uncachedDecoder'] as String? ?? '', | ||
| 159 | + cachedDecoder: json['cachedDecoder'] as String? ?? '', | ||
| 160 | + ); | ||
| 161 | + } | ||
| 162 | + | ||
| 92 | @override | 163 | @override |
| 93 | String toString() { | 164 | String toString() { |
| 94 | return 'OfflineMoonshineModelConfig(preprocessor: $preprocessor, encoder: $encoder, uncachedDecoder: $uncachedDecoder, cachedDecoder: $cachedDecoder)'; | 165 | return 'OfflineMoonshineModelConfig(preprocessor: $preprocessor, encoder: $encoder, uncachedDecoder: $uncachedDecoder, cachedDecoder: $cachedDecoder)'; |
| 95 | } | 166 | } |
| 96 | 167 | ||
| 168 | + Map<String, dynamic> toJson() => { | ||
| 169 | + 'preprocessor': preprocessor, | ||
| 170 | + 'encoder': encoder, | ||
| 171 | + 'uncachedDecoder': uncachedDecoder, | ||
| 172 | + 'cachedDecoder': cachedDecoder, | ||
| 173 | + }; | ||
| 174 | + | ||
| 97 | final String preprocessor; | 175 | final String preprocessor; |
| 98 | final String encoder; | 176 | final String encoder; |
| 99 | final String uncachedDecoder; | 177 | final String uncachedDecoder; |
| @@ -103,11 +181,21 @@ class OfflineMoonshineModelConfig { | @@ -103,11 +181,21 @@ class OfflineMoonshineModelConfig { | ||
| 103 | class OfflineTdnnModelConfig { | 181 | class OfflineTdnnModelConfig { |
| 104 | const OfflineTdnnModelConfig({this.model = ''}); | 182 | const OfflineTdnnModelConfig({this.model = ''}); |
| 105 | 183 | ||
| 184 | + factory OfflineTdnnModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 185 | + return OfflineTdnnModelConfig( | ||
| 186 | + model: json['model'] as String? ?? '', | ||
| 187 | + ); | ||
| 188 | + } | ||
| 189 | + | ||
| 106 | @override | 190 | @override |
| 107 | String toString() { | 191 | String toString() { |
| 108 | return 'OfflineTdnnModelConfig(model: $model)'; | 192 | return 'OfflineTdnnModelConfig(model: $model)'; |
| 109 | } | 193 | } |
| 110 | 194 | ||
| 195 | + Map<String, dynamic> toJson() => { | ||
| 196 | + 'model': model, | ||
| 197 | + }; | ||
| 198 | + | ||
| 111 | final String model; | 199 | final String model; |
| 112 | } | 200 | } |
| 113 | 201 | ||
| @@ -118,11 +206,26 @@ class OfflineSenseVoiceModelConfig { | @@ -118,11 +206,26 @@ class OfflineSenseVoiceModelConfig { | ||
| 118 | this.useInverseTextNormalization = false, | 206 | this.useInverseTextNormalization = false, |
| 119 | }); | 207 | }); |
| 120 | 208 | ||
| 209 | + factory OfflineSenseVoiceModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 210 | + return OfflineSenseVoiceModelConfig( | ||
| 211 | + model: json['model'] as String? ?? '', | ||
| 212 | + language: json['language'] as String? ?? '', | ||
| 213 | + useInverseTextNormalization: | ||
| 214 | + json['useInverseTextNormalization'] as bool? ?? false, | ||
| 215 | + ); | ||
| 216 | + } | ||
| 217 | + | ||
| 121 | @override | 218 | @override |
| 122 | String toString() { | 219 | String toString() { |
| 123 | return 'OfflineSenseVoiceModelConfig(model: $model, language: $language, useInverseTextNormalization: $useInverseTextNormalization)'; | 220 | return 'OfflineSenseVoiceModelConfig(model: $model, language: $language, useInverseTextNormalization: $useInverseTextNormalization)'; |
| 124 | } | 221 | } |
| 125 | 222 | ||
| 223 | + Map<String, dynamic> toJson() => { | ||
| 224 | + 'model': model, | ||
| 225 | + 'language': language, | ||
| 226 | + 'useInverseTextNormalization': useInverseTextNormalization, | ||
| 227 | + }; | ||
| 228 | + | ||
| 126 | final String model; | 229 | final String model; |
| 127 | final String language; | 230 | final String language; |
| 128 | final bool useInverseTextNormalization; | 231 | final bool useInverseTextNormalization; |
| @@ -131,11 +234,23 @@ class OfflineSenseVoiceModelConfig { | @@ -131,11 +234,23 @@ class OfflineSenseVoiceModelConfig { | ||
| 131 | class OfflineLMConfig { | 234 | class OfflineLMConfig { |
| 132 | const OfflineLMConfig({this.model = '', this.scale = 1.0}); | 235 | const OfflineLMConfig({this.model = '', this.scale = 1.0}); |
| 133 | 236 | ||
| 237 | + factory OfflineLMConfig.fromJson(Map<String, dynamic> json) { | ||
| 238 | + return OfflineLMConfig( | ||
| 239 | + model: json['model'] as String? ?? '', | ||
| 240 | + scale: (json['scale'] as num?)?.toDouble() ?? 1.0, | ||
| 241 | + ); | ||
| 242 | + } | ||
| 243 | + | ||
| 134 | @override | 244 | @override |
| 135 | String toString() { | 245 | String toString() { |
| 136 | return 'OfflineLMConfig(model: $model, scale: $scale)'; | 246 | return 'OfflineLMConfig(model: $model, scale: $scale)'; |
| 137 | } | 247 | } |
| 138 | 248 | ||
| 249 | + Map<String, dynamic> toJson() => { | ||
| 250 | + 'model': model, | ||
| 251 | + 'scale': scale, | ||
| 252 | + }; | ||
| 253 | + | ||
| 139 | final String model; | 254 | final String model; |
| 140 | final double scale; | 255 | final double scale; |
| 141 | } | 256 | } |
| @@ -160,11 +275,75 @@ class OfflineModelConfig { | @@ -160,11 +275,75 @@ class OfflineModelConfig { | ||
| 160 | this.telespeechCtc = '', | 275 | this.telespeechCtc = '', |
| 161 | }); | 276 | }); |
| 162 | 277 | ||
| 278 | + factory OfflineModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 279 | + return OfflineModelConfig( | ||
| 280 | + transducer: json['transducer'] != null | ||
| 281 | + ? OfflineTransducerModelConfig.fromJson( | ||
| 282 | + json['transducer'] as Map<String, dynamic>) | ||
| 283 | + : const OfflineTransducerModelConfig(), | ||
| 284 | + paraformer: json['paraformer'] != null | ||
| 285 | + ? OfflineParaformerModelConfig.fromJson( | ||
| 286 | + json['paraformer'] as Map<String, dynamic>) | ||
| 287 | + : const OfflineParaformerModelConfig(), | ||
| 288 | + nemoCtc: json['nemoCtc'] != null | ||
| 289 | + ? OfflineNemoEncDecCtcModelConfig.fromJson( | ||
| 290 | + json['nemoCtc'] as Map<String, dynamic>) | ||
| 291 | + : const OfflineNemoEncDecCtcModelConfig(), | ||
| 292 | + whisper: json['whisper'] != null | ||
| 293 | + ? OfflineWhisperModelConfig.fromJson( | ||
| 294 | + json['whisper'] as Map<String, dynamic>) | ||
| 295 | + : const OfflineWhisperModelConfig(), | ||
| 296 | + tdnn: json['tdnn'] != null | ||
| 297 | + ? OfflineTdnnModelConfig.fromJson( | ||
| 298 | + json['tdnn'] as Map<String, dynamic>) | ||
| 299 | + : const OfflineTdnnModelConfig(), | ||
| 300 | + senseVoice: json['senseVoice'] != null | ||
| 301 | + ? OfflineSenseVoiceModelConfig.fromJson( | ||
| 302 | + json['senseVoice'] as Map<String, dynamic>) | ||
| 303 | + : const OfflineSenseVoiceModelConfig(), | ||
| 304 | + moonshine: json['moonshine'] != null | ||
| 305 | + ? OfflineMoonshineModelConfig.fromJson( | ||
| 306 | + json['moonshine'] as Map<String, dynamic>) | ||
| 307 | + : const OfflineMoonshineModelConfig(), | ||
| 308 | + fireRedAsr: json['fireRedAsr'] != null | ||
| 309 | + ? OfflineFireRedAsrModelConfig.fromJson( | ||
| 310 | + json['fireRedAsr'] as Map<String, dynamic>) | ||
| 311 | + : const OfflineFireRedAsrModelConfig(), | ||
| 312 | + tokens: json['tokens'] as String, | ||
| 313 | + numThreads: json['numThreads'] as int? ?? 1, | ||
| 314 | + debug: json['debug'] as bool? ?? true, | ||
| 315 | + provider: json['provider'] as String? ?? 'cpu', | ||
| 316 | + modelType: json['modelType'] as String? ?? '', | ||
| 317 | + modelingUnit: json['modelingUnit'] as String? ?? '', | ||
| 318 | + bpeVocab: json['bpeVocab'] as String? ?? '', | ||
| 319 | + telespeechCtc: json['telespeechCtc'] as String? ?? '', | ||
| 320 | + ); | ||
| 321 | + } | ||
| 322 | + | ||
| 163 | @override | 323 | @override |
| 164 | String toString() { | 324 | String toString() { |
| 165 | return 'OfflineModelConfig(transducer: $transducer, paraformer: $paraformer, nemoCtc: $nemoCtc, whisper: $whisper, tdnn: $tdnn, senseVoice: $senseVoice, moonshine: $moonshine, fireRedAsr: $fireRedAsr, tokens: $tokens, numThreads: $numThreads, debug: $debug, provider: $provider, modelType: $modelType, modelingUnit: $modelingUnit, bpeVocab: $bpeVocab, telespeechCtc: $telespeechCtc)'; | 325 | return 'OfflineModelConfig(transducer: $transducer, paraformer: $paraformer, nemoCtc: $nemoCtc, whisper: $whisper, tdnn: $tdnn, senseVoice: $senseVoice, moonshine: $moonshine, fireRedAsr: $fireRedAsr, tokens: $tokens, numThreads: $numThreads, debug: $debug, provider: $provider, modelType: $modelType, modelingUnit: $modelingUnit, bpeVocab: $bpeVocab, telespeechCtc: $telespeechCtc)'; |
| 166 | } | 326 | } |
| 167 | 327 | ||
| 328 | + Map<String, dynamic> toJson() => { | ||
| 329 | + 'transducer': transducer.toJson(), | ||
| 330 | + 'paraformer': paraformer.toJson(), | ||
| 331 | + 'nemoCtc': nemoCtc.toJson(), | ||
| 332 | + 'whisper': whisper.toJson(), | ||
| 333 | + 'tdnn': tdnn.toJson(), | ||
| 334 | + 'senseVoice': senseVoice.toJson(), | ||
| 335 | + 'moonshine': moonshine.toJson(), | ||
| 336 | + 'fireRedAsr': fireRedAsr.toJson(), | ||
| 337 | + 'tokens': tokens, | ||
| 338 | + 'numThreads': numThreads, | ||
| 339 | + 'debug': debug, | ||
| 340 | + 'provider': provider, | ||
| 341 | + 'modelType': modelType, | ||
| 342 | + 'modelingUnit': modelingUnit, | ||
| 343 | + 'bpeVocab': bpeVocab, | ||
| 344 | + 'telespeechCtc': telespeechCtc, | ||
| 345 | + }; | ||
| 346 | + | ||
| 168 | final OfflineTransducerModelConfig transducer; | 347 | final OfflineTransducerModelConfig transducer; |
| 169 | final OfflineParaformerModelConfig paraformer; | 348 | final OfflineParaformerModelConfig paraformer; |
| 170 | final OfflineNemoEncDecCtcModelConfig nemoCtc; | 349 | final OfflineNemoEncDecCtcModelConfig nemoCtc; |
| @@ -198,11 +377,43 @@ class OfflineRecognizerConfig { | @@ -198,11 +377,43 @@ class OfflineRecognizerConfig { | ||
| 198 | this.blankPenalty = 0.0, | 377 | this.blankPenalty = 0.0, |
| 199 | }); | 378 | }); |
| 200 | 379 | ||
| 380 | + factory OfflineRecognizerConfig.fromJson(Map<String, dynamic> json) { | ||
| 381 | + return OfflineRecognizerConfig( | ||
| 382 | + feat: json['feat'] != null | ||
| 383 | + ? FeatureConfig.fromJson(json['feat'] as Map<String, dynamic>) | ||
| 384 | + : const FeatureConfig(), | ||
| 385 | + model: OfflineModelConfig.fromJson(json['model'] as Map<String, dynamic>), | ||
| 386 | + lm: json['lm'] != null | ||
| 387 | + ? OfflineLMConfig.fromJson(json['lm'] as Map<String, dynamic>) | ||
| 388 | + : const OfflineLMConfig(), | ||
| 389 | + decodingMethod: json['decodingMethod'] as String? ?? 'greedy_search', | ||
| 390 | + maxActivePaths: json['maxActivePaths'] as int? ?? 4, | ||
| 391 | + hotwordsFile: json['hotwordsFile'] as String? ?? '', | ||
| 392 | + hotwordsScore: (json['hotwordsScore'] as num?)?.toDouble() ?? 1.5, | ||
| 393 | + ruleFsts: json['ruleFsts'] as String? ?? '', | ||
| 394 | + ruleFars: json['ruleFars'] as String? ?? '', | ||
| 395 | + blankPenalty: (json['blankPenalty'] as num?)?.toDouble() ?? 0.0, | ||
| 396 | + ); | ||
| 397 | + } | ||
| 398 | + | ||
| 201 | @override | 399 | @override |
| 202 | String toString() { | 400 | String toString() { |
| 203 | return 'OfflineRecognizerConfig(feat: $feat, model: $model, lm: $lm, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ruleFsts: $ruleFsts, ruleFars: $ruleFars, blankPenalty: $blankPenalty)'; | 401 | return 'OfflineRecognizerConfig(feat: $feat, model: $model, lm: $lm, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ruleFsts: $ruleFsts, ruleFars: $ruleFars, blankPenalty: $blankPenalty)'; |
| 204 | } | 402 | } |
| 205 | 403 | ||
| 404 | + Map<String, dynamic> toJson() => { | ||
| 405 | + 'feat': feat.toJson(), | ||
| 406 | + 'model': model.toJson(), | ||
| 407 | + 'lm': lm.toJson(), | ||
| 408 | + 'decodingMethod': decodingMethod, | ||
| 409 | + 'maxActivePaths': maxActivePaths, | ||
| 410 | + 'hotwordsFile': hotwordsFile, | ||
| 411 | + 'hotwordsScore': hotwordsScore, | ||
| 412 | + 'ruleFsts': ruleFsts, | ||
| 413 | + 'ruleFars': ruleFars, | ||
| 414 | + 'blankPenalty': blankPenalty, | ||
| 415 | + }; | ||
| 416 | + | ||
| 206 | final FeatureConfig feat; | 417 | final FeatureConfig feat; |
| 207 | final OfflineModelConfig model; | 418 | final OfflineModelConfig model; |
| 208 | final OfflineLMConfig lm; | 419 | final OfflineLMConfig lm; |
| @@ -229,11 +440,34 @@ class OfflineRecognizerResult { | @@ -229,11 +440,34 @@ class OfflineRecognizerResult { | ||
| 229 | required this.emotion, | 440 | required this.emotion, |
| 230 | required this.event}); | 441 | required this.event}); |
| 231 | 442 | ||
| 443 | + factory OfflineRecognizerResult.fromJson(Map<String, dynamic> json) { | ||
| 444 | + return OfflineRecognizerResult( | ||
| 445 | + text: json['text'] as String? ?? '', | ||
| 446 | + tokens: (json['tokens'] as List?)?.map((e) => e as String).toList() ?? [], | ||
| 447 | + timestamps: (json['timestamps'] as List?) | ||
| 448 | + ?.map((e) => (e as num).toDouble()) | ||
| 449 | + .toList() ?? | ||
| 450 | + [], | ||
| 451 | + lang: json['lang'] as String? ?? '', | ||
| 452 | + emotion: json['emotion'] as String? ?? '', | ||
| 453 | + event: json['event'] as String? ?? '', | ||
| 454 | + ); | ||
| 455 | + } | ||
| 456 | + | ||
| 232 | @override | 457 | @override |
| 233 | String toString() { | 458 | String toString() { |
| 234 | return 'OfflineRecognizerResult(text: $text, tokens: $tokens, timestamps: $timestamps, lang: $lang, emotion: $emotion, event: $event)'; | 459 | return 'OfflineRecognizerResult(text: $text, tokens: $tokens, timestamps: $timestamps, lang: $lang, emotion: $emotion, event: $event)'; |
| 235 | } | 460 | } |
| 236 | 461 | ||
| 462 | + Map<String, dynamic> toJson() => { | ||
| 463 | + 'text': text, | ||
| 464 | + 'tokens': tokens, | ||
| 465 | + 'timestamps': timestamps, | ||
| 466 | + 'lang': lang, | ||
| 467 | + 'emotion': emotion, | ||
| 468 | + 'event': event, | ||
| 469 | + }; | ||
| 470 | + | ||
| 237 | final String text; | 471 | final String text; |
| 238 | final List<String> tokens; | 472 | final List<String> tokens; |
| 239 | final List<double> timestamps; | 473 | final List<double> timestamps; |
| @@ -305,8 +539,10 @@ class OfflineRecognizer { | @@ -305,8 +539,10 @@ class OfflineRecognizer { | ||
| 305 | config.model.moonshine.cachedDecoder.toNativeUtf8(); | 539 | config.model.moonshine.cachedDecoder.toNativeUtf8(); |
| 306 | 540 | ||
| 307 | // FireRedAsr | 541 | // FireRedAsr |
| 308 | - c.ref.model.fireRedAsr.encoder = config.model.fireRedAsr.encoder.toNativeUtf8(); | ||
| 309 | - c.ref.model.fireRedAsr.decoder = config.model.fireRedAsr.decoder.toNativeUtf8(); | 542 | + c.ref.model.fireRedAsr.encoder = |
| 543 | + config.model.fireRedAsr.encoder.toNativeUtf8(); | ||
| 544 | + c.ref.model.fireRedAsr.decoder = | ||
| 545 | + config.model.fireRedAsr.decoder.toNativeUtf8(); | ||
| 310 | 546 | ||
| 311 | c.ref.model.tokens = config.model.tokens.toNativeUtf8(); | 547 | c.ref.model.tokens = config.model.tokens.toNativeUtf8(); |
| 312 | 548 |
| @@ -14,11 +14,25 @@ class OfflineSpeakerDiarizationSegment { | @@ -14,11 +14,25 @@ class OfflineSpeakerDiarizationSegment { | ||
| 14 | required this.speaker, | 14 | required this.speaker, |
| 15 | }); | 15 | }); |
| 16 | 16 | ||
| 17 | + factory OfflineSpeakerDiarizationSegment.fromJson(Map<String, dynamic> json) { | ||
| 18 | + return OfflineSpeakerDiarizationSegment( | ||
| 19 | + start: (json['start'] as num).toDouble(), | ||
| 20 | + end: (json['end'] as num).toDouble(), | ||
| 21 | + speaker: json['speaker'] as int, | ||
| 22 | + ); | ||
| 23 | + } | ||
| 24 | + | ||
| 17 | @override | 25 | @override |
| 18 | String toString() { | 26 | String toString() { |
| 19 | return 'OfflineSpeakerDiarizationSegment(start: $start, end: $end, speaker: $speaker)'; | 27 | return 'OfflineSpeakerDiarizationSegment(start: $start, end: $end, speaker: $speaker)'; |
| 20 | } | 28 | } |
| 21 | 29 | ||
| 30 | + Map<String, dynamic> toJson() => { | ||
| 31 | + 'start': start, | ||
| 32 | + 'end': end, | ||
| 33 | + 'speaker': speaker, | ||
| 34 | + }; | ||
| 35 | + | ||
| 22 | final double start; | 36 | final double start; |
| 23 | final double end; | 37 | final double end; |
| 24 | final int speaker; | 38 | final int speaker; |
| @@ -29,11 +43,22 @@ class OfflineSpeakerSegmentationPyannoteModelConfig { | @@ -29,11 +43,22 @@ class OfflineSpeakerSegmentationPyannoteModelConfig { | ||
| 29 | this.model = '', | 43 | this.model = '', |
| 30 | }); | 44 | }); |
| 31 | 45 | ||
| 46 | + factory OfflineSpeakerSegmentationPyannoteModelConfig.fromJson( | ||
| 47 | + Map<String, dynamic> json) { | ||
| 48 | + return OfflineSpeakerSegmentationPyannoteModelConfig( | ||
| 49 | + model: json['model'] as String? ?? '', | ||
| 50 | + ); | ||
| 51 | + } | ||
| 52 | + | ||
| 32 | @override | 53 | @override |
| 33 | String toString() { | 54 | String toString() { |
| 34 | return 'OfflineSpeakerSegmentationPyannoteModelConfig(model: $model)'; | 55 | return 'OfflineSpeakerSegmentationPyannoteModelConfig(model: $model)'; |
| 35 | } | 56 | } |
| 36 | 57 | ||
| 58 | + Map<String, dynamic> toJson() => { | ||
| 59 | + 'model': model, | ||
| 60 | + }; | ||
| 61 | + | ||
| 37 | final String model; | 62 | final String model; |
| 38 | } | 63 | } |
| 39 | 64 | ||
| @@ -45,11 +70,31 @@ class OfflineSpeakerSegmentationModelConfig { | @@ -45,11 +70,31 @@ class OfflineSpeakerSegmentationModelConfig { | ||
| 45 | this.provider = 'cpu', | 70 | this.provider = 'cpu', |
| 46 | }); | 71 | }); |
| 47 | 72 | ||
| 73 | + factory OfflineSpeakerSegmentationModelConfig.fromJson( | ||
| 74 | + Map<String, dynamic> json) { | ||
| 75 | + return OfflineSpeakerSegmentationModelConfig( | ||
| 76 | + pyannote: json['pyannote'] != null | ||
| 77 | + ? OfflineSpeakerSegmentationPyannoteModelConfig.fromJson( | ||
| 78 | + json['pyannote'] as Map<String, dynamic>) | ||
| 79 | + : const OfflineSpeakerSegmentationPyannoteModelConfig(), | ||
| 80 | + numThreads: json['numThreads'] as int? ?? 1, | ||
| 81 | + debug: json['debug'] as bool? ?? true, | ||
| 82 | + provider: json['provider'] as String? ?? 'cpu', | ||
| 83 | + ); | ||
| 84 | + } | ||
| 85 | + | ||
| 48 | @override | 86 | @override |
| 49 | String toString() { | 87 | String toString() { |
| 50 | return 'OfflineSpeakerSegmentationModelConfig(pyannote: $pyannote, numThreads: $numThreads, debug: $debug, provider: $provider)'; | 88 | return 'OfflineSpeakerSegmentationModelConfig(pyannote: $pyannote, numThreads: $numThreads, debug: $debug, provider: $provider)'; |
| 51 | } | 89 | } |
| 52 | 90 | ||
| 91 | + Map<String, dynamic> toJson() => { | ||
| 92 | + 'pyannote': pyannote.toJson(), | ||
| 93 | + 'numThreads': numThreads, | ||
| 94 | + 'debug': debug, | ||
| 95 | + 'provider': provider, | ||
| 96 | + }; | ||
| 97 | + | ||
| 53 | final OfflineSpeakerSegmentationPyannoteModelConfig pyannote; | 98 | final OfflineSpeakerSegmentationPyannoteModelConfig pyannote; |
| 54 | 99 | ||
| 55 | final int numThreads; | 100 | final int numThreads; |
| @@ -63,11 +108,23 @@ class FastClusteringConfig { | @@ -63,11 +108,23 @@ class FastClusteringConfig { | ||
| 63 | this.threshold = 0.5, | 108 | this.threshold = 0.5, |
| 64 | }); | 109 | }); |
| 65 | 110 | ||
| 111 | + factory FastClusteringConfig.fromJson(Map<String, dynamic> json) { | ||
| 112 | + return FastClusteringConfig( | ||
| 113 | + numClusters: json['numClusters'] as int? ?? -1, | ||
| 114 | + threshold: (json['threshold'] as num?)?.toDouble() ?? 0.5, | ||
| 115 | + ); | ||
| 116 | + } | ||
| 117 | + | ||
| 66 | @override | 118 | @override |
| 67 | String toString() { | 119 | String toString() { |
| 68 | return 'FastClusteringConfig(numClusters: $numClusters, threshold: $threshold)'; | 120 | return 'FastClusteringConfig(numClusters: $numClusters, threshold: $threshold)'; |
| 69 | } | 121 | } |
| 70 | 122 | ||
| 123 | + Map<String, dynamic> toJson() => { | ||
| 124 | + 'numClusters': numClusters, | ||
| 125 | + 'threshold': threshold, | ||
| 126 | + }; | ||
| 127 | + | ||
| 71 | final int numClusters; | 128 | final int numClusters; |
| 72 | final double threshold; | 129 | final double threshold; |
| 73 | } | 130 | } |
| @@ -81,11 +138,38 @@ class OfflineSpeakerDiarizationConfig { | @@ -81,11 +138,38 @@ class OfflineSpeakerDiarizationConfig { | ||
| 81 | this.minDurationOff = 0.5, | 138 | this.minDurationOff = 0.5, |
| 82 | }); | 139 | }); |
| 83 | 140 | ||
| 141 | + factory OfflineSpeakerDiarizationConfig.fromJson(Map<String, dynamic> json) { | ||
| 142 | + return OfflineSpeakerDiarizationConfig( | ||
| 143 | + segmentation: json['segmentation'] != null | ||
| 144 | + ? OfflineSpeakerSegmentationModelConfig.fromJson( | ||
| 145 | + json['segmentation'] as Map<String, dynamic>) | ||
| 146 | + : const OfflineSpeakerSegmentationModelConfig(), | ||
| 147 | + embedding: json['embedding'] != null | ||
| 148 | + ? SpeakerEmbeddingExtractorConfig.fromJson( | ||
| 149 | + json['embedding'] as Map<String, dynamic>) | ||
| 150 | + : const SpeakerEmbeddingExtractorConfig(model: ''), | ||
| 151 | + clustering: json['clustering'] != null | ||
| 152 | + ? FastClusteringConfig.fromJson( | ||
| 153 | + json['clustering'] as Map<String, dynamic>) | ||
| 154 | + : const FastClusteringConfig(), | ||
| 155 | + minDurationOn: (json['minDurationOn'] as num?)?.toDouble() ?? 0.2, | ||
| 156 | + minDurationOff: (json['minDurationOff'] as num?)?.toDouble() ?? 0.5, | ||
| 157 | + ); | ||
| 158 | + } | ||
| 159 | + | ||
| 84 | @override | 160 | @override |
| 85 | String toString() { | 161 | String toString() { |
| 86 | return 'OfflineSpeakerDiarizationConfig(segmentation: $segmentation, embedding: $embedding, clustering: $clustering, minDurationOn: $minDurationOn, minDurationOff: $minDurationOff)'; | 162 | return 'OfflineSpeakerDiarizationConfig(segmentation: $segmentation, embedding: $embedding, clustering: $clustering, minDurationOn: $minDurationOn, minDurationOff: $minDurationOff)'; |
| 87 | } | 163 | } |
| 88 | 164 | ||
| 165 | + Map<String, dynamic> toJson() => { | ||
| 166 | + 'segmentation': segmentation.toJson(), | ||
| 167 | + 'embedding': embedding.toJson(), | ||
| 168 | + 'clustering': clustering.toJson(), | ||
| 169 | + 'minDurationOn': minDurationOn, | ||
| 170 | + 'minDurationOff': minDurationOff, | ||
| 171 | + }; | ||
| 172 | + | ||
| 89 | final OfflineSpeakerSegmentationModelConfig segmentation; | 173 | final OfflineSpeakerSegmentationModelConfig segmentation; |
| 90 | final SpeakerEmbeddingExtractorConfig embedding; | 174 | final SpeakerEmbeddingExtractorConfig embedding; |
| 91 | final FastClusteringConfig clustering; | 175 | final FastClusteringConfig clustering; |
| @@ -11,6 +11,16 @@ class OnlinePunctuationModelConfig { | @@ -11,6 +11,16 @@ class OnlinePunctuationModelConfig { | ||
| 11 | this.provider = 'cpu', | 11 | this.provider = 'cpu', |
| 12 | this.debug = true}); | 12 | this.debug = true}); |
| 13 | 13 | ||
| 14 | + factory OnlinePunctuationModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 15 | + return OnlinePunctuationModelConfig( | ||
| 16 | + cnnBiLstm: json['cnnBiLstm'], | ||
| 17 | + bpeVocab: json['bpeVocab'], | ||
| 18 | + numThreads: json['numThreads'], | ||
| 19 | + provider: json['provider'], | ||
| 20 | + debug: json['debug'], | ||
| 21 | + ); | ||
| 22 | + } | ||
| 23 | + | ||
| 14 | @override | 24 | @override |
| 15 | String toString() { | 25 | String toString() { |
| 16 | return 'OnlinePunctuationModelConfig(cnnBiLstm: $cnnBiLstm, ' | 26 | return 'OnlinePunctuationModelConfig(cnnBiLstm: $cnnBiLstm, ' |
| @@ -18,6 +28,16 @@ class OnlinePunctuationModelConfig { | @@ -18,6 +28,16 @@ class OnlinePunctuationModelConfig { | ||
| 18 | 'provider: $provider, debug: $debug)'; | 28 | 'provider: $provider, debug: $debug)'; |
| 19 | } | 29 | } |
| 20 | 30 | ||
| 31 | + Map<String, dynamic> toJson() { | ||
| 32 | + return { | ||
| 33 | + 'cnnBiLstm': cnnBiLstm, | ||
| 34 | + 'bpeVocab': bpeVocab, | ||
| 35 | + 'numThreads': numThreads, | ||
| 36 | + 'provider': provider, | ||
| 37 | + 'debug': debug, | ||
| 38 | + }; | ||
| 39 | + } | ||
| 40 | + | ||
| 21 | final String cnnBiLstm; | 41 | final String cnnBiLstm; |
| 22 | final String bpeVocab; | 42 | final String bpeVocab; |
| 23 | final int numThreads; | 43 | final int numThreads; |
| @@ -30,11 +50,23 @@ class OnlinePunctuationConfig { | @@ -30,11 +50,23 @@ class OnlinePunctuationConfig { | ||
| 30 | required this.model, | 50 | required this.model, |
| 31 | }); | 51 | }); |
| 32 | 52 | ||
| 53 | + factory OnlinePunctuationConfig.fromJson(Map<String, dynamic> json) { | ||
| 54 | + return OnlinePunctuationConfig( | ||
| 55 | + model: OnlinePunctuationModelConfig.fromJson(json['model']), | ||
| 56 | + ); | ||
| 57 | + } | ||
| 58 | + | ||
| 33 | @override | 59 | @override |
| 34 | String toString() { | 60 | String toString() { |
| 35 | return 'OnlinePunctuationConfig(model: $model)'; | 61 | return 'OnlinePunctuationConfig(model: $model)'; |
| 36 | } | 62 | } |
| 37 | 63 | ||
| 64 | + Map<String, dynamic> toJson() { | ||
| 65 | + return { | ||
| 66 | + 'model': model.toJson(), | ||
| 67 | + }; | ||
| 68 | + } | ||
| 69 | + | ||
| 38 | final OnlinePunctuationModelConfig model; | 70 | final OnlinePunctuationModelConfig model; |
| 39 | } | 71 | } |
| 40 | 72 | ||
| @@ -90,7 +122,7 @@ class OnlinePunctuation { | @@ -90,7 +122,7 @@ class OnlinePunctuation { | ||
| 90 | final ans = p.toDartString(); | 122 | final ans = p.toDartString(); |
| 91 | 123 | ||
| 92 | SherpaOnnxBindings.sherpaOnnxOnlinePunctuationFreeText?.call(p); | 124 | SherpaOnnxBindings.sherpaOnnxOnlinePunctuationFreeText?.call(p); |
| 93 | - | 125 | + |
| 94 | return ans; | 126 | return ans; |
| 95 | } | 127 | } |
| 96 | 128 |
| @@ -16,11 +16,25 @@ class OnlineTransducerModelConfig { | @@ -16,11 +16,25 @@ class OnlineTransducerModelConfig { | ||
| 16 | this.joiner = '', | 16 | this.joiner = '', |
| 17 | }); | 17 | }); |
| 18 | 18 | ||
| 19 | + factory OnlineTransducerModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 20 | + return OnlineTransducerModelConfig( | ||
| 21 | + encoder: json['encoder'] as String? ?? '', | ||
| 22 | + decoder: json['decoder'] as String? ?? '', | ||
| 23 | + joiner: json['joiner'] as String? ?? '', | ||
| 24 | + ); | ||
| 25 | + } | ||
| 26 | + | ||
| 19 | @override | 27 | @override |
| 20 | String toString() { | 28 | String toString() { |
| 21 | return 'OnlineTransducerModelConfig(encoder: $encoder, decoder: $decoder, joiner: $joiner)'; | 29 | return 'OnlineTransducerModelConfig(encoder: $encoder, decoder: $decoder, joiner: $joiner)'; |
| 22 | } | 30 | } |
| 23 | 31 | ||
| 32 | + Map<String, dynamic> toJson() => { | ||
| 33 | + 'encoder': encoder, | ||
| 34 | + 'decoder': decoder, | ||
| 35 | + 'joiner': joiner, | ||
| 36 | + }; | ||
| 37 | + | ||
| 24 | final String encoder; | 38 | final String encoder; |
| 25 | final String decoder; | 39 | final String decoder; |
| 26 | final String joiner; | 40 | final String joiner; |
| @@ -29,11 +43,23 @@ class OnlineTransducerModelConfig { | @@ -29,11 +43,23 @@ class OnlineTransducerModelConfig { | ||
| 29 | class OnlineParaformerModelConfig { | 43 | class OnlineParaformerModelConfig { |
| 30 | const OnlineParaformerModelConfig({this.encoder = '', this.decoder = ''}); | 44 | const OnlineParaformerModelConfig({this.encoder = '', this.decoder = ''}); |
| 31 | 45 | ||
| 46 | + factory OnlineParaformerModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 47 | + return OnlineParaformerModelConfig( | ||
| 48 | + encoder: json['encoder'] as String? ?? '', | ||
| 49 | + decoder: json['decoder'] as String? ?? '', | ||
| 50 | + ); | ||
| 51 | + } | ||
| 52 | + | ||
| 32 | @override | 53 | @override |
| 33 | String toString() { | 54 | String toString() { |
| 34 | return 'OnlineParaformerModelConfig(encoder: $encoder, decoder: $decoder)'; | 55 | return 'OnlineParaformerModelConfig(encoder: $encoder, decoder: $decoder)'; |
| 35 | } | 56 | } |
| 36 | 57 | ||
| 58 | + Map<String, dynamic> toJson() => { | ||
| 59 | + 'encoder': encoder, | ||
| 60 | + 'decoder': decoder, | ||
| 61 | + }; | ||
| 62 | + | ||
| 37 | final String encoder; | 63 | final String encoder; |
| 38 | final String decoder; | 64 | final String decoder; |
| 39 | } | 65 | } |
| @@ -41,11 +67,21 @@ class OnlineParaformerModelConfig { | @@ -41,11 +67,21 @@ class OnlineParaformerModelConfig { | ||
| 41 | class OnlineZipformer2CtcModelConfig { | 67 | class OnlineZipformer2CtcModelConfig { |
| 42 | const OnlineZipformer2CtcModelConfig({this.model = ''}); | 68 | const OnlineZipformer2CtcModelConfig({this.model = ''}); |
| 43 | 69 | ||
| 70 | + factory OnlineZipformer2CtcModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 71 | + return OnlineZipformer2CtcModelConfig( | ||
| 72 | + model: json['model'] as String? ?? '', | ||
| 73 | + ); | ||
| 74 | + } | ||
| 75 | + | ||
| 44 | @override | 76 | @override |
| 45 | String toString() { | 77 | String toString() { |
| 46 | return 'OnlineZipformer2CtcModelConfig(model: $model)'; | 78 | return 'OnlineZipformer2CtcModelConfig(model: $model)'; |
| 47 | } | 79 | } |
| 48 | 80 | ||
| 81 | + Map<String, dynamic> toJson() => { | ||
| 82 | + 'model': model, | ||
| 83 | + }; | ||
| 84 | + | ||
| 49 | final String model; | 85 | final String model; |
| 50 | } | 86 | } |
| 51 | 87 | ||
| @@ -63,11 +99,42 @@ class OnlineModelConfig { | @@ -63,11 +99,42 @@ class OnlineModelConfig { | ||
| 63 | this.bpeVocab = '', | 99 | this.bpeVocab = '', |
| 64 | }); | 100 | }); |
| 65 | 101 | ||
| 102 | + factory OnlineModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 103 | + return OnlineModelConfig( | ||
| 104 | + transducer: OnlineTransducerModelConfig.fromJson( | ||
| 105 | + json['transducer'] as Map<String, dynamic>? ?? const {}), | ||
| 106 | + paraformer: OnlineParaformerModelConfig.fromJson( | ||
| 107 | + json['paraformer'] as Map<String, dynamic>? ?? const {}), | ||
| 108 | + zipformer2Ctc: OnlineZipformer2CtcModelConfig.fromJson( | ||
| 109 | + json['zipformer2Ctc'] as Map<String, dynamic>? ?? const {}), | ||
| 110 | + tokens: json['tokens'] as String, | ||
| 111 | + numThreads: json['numThreads'] as int? ?? 1, | ||
| 112 | + provider: json['provider'] as String? ?? 'cpu', | ||
| 113 | + debug: json['debug'] as bool? ?? true, | ||
| 114 | + modelType: json['modelType'] as String? ?? '', | ||
| 115 | + modelingUnit: json['modelingUnit'] as String? ?? '', | ||
| 116 | + bpeVocab: json['bpeVocab'] as String? ?? '', | ||
| 117 | + ); | ||
| 118 | + } | ||
| 119 | + | ||
| 66 | @override | 120 | @override |
| 67 | String toString() { | 121 | String toString() { |
| 68 | return 'OnlineModelConfig(transducer: $transducer, paraformer: $paraformer, zipformer2Ctc: $zipformer2Ctc, tokens: $tokens, numThreads: $numThreads, provider: $provider, debug: $debug, modelType: $modelType, modelingUnit: $modelingUnit, bpeVocab: $bpeVocab)'; | 122 | return 'OnlineModelConfig(transducer: $transducer, paraformer: $paraformer, zipformer2Ctc: $zipformer2Ctc, tokens: $tokens, numThreads: $numThreads, provider: $provider, debug: $debug, modelType: $modelType, modelingUnit: $modelingUnit, bpeVocab: $bpeVocab)'; |
| 69 | } | 123 | } |
| 70 | 124 | ||
| 125 | + Map<String, dynamic> toJson() => { | ||
| 126 | + 'transducer': transducer.toJson(), | ||
| 127 | + 'paraformer': paraformer.toJson(), | ||
| 128 | + 'zipformer2Ctc': zipformer2Ctc.toJson(), | ||
| 129 | + 'tokens': tokens, | ||
| 130 | + 'numThreads': numThreads, | ||
| 131 | + 'provider': provider, | ||
| 132 | + 'debug': debug, | ||
| 133 | + 'modelType': modelType, | ||
| 134 | + 'modelingUnit': modelingUnit, | ||
| 135 | + 'bpeVocab': bpeVocab, | ||
| 136 | + }; | ||
| 137 | + | ||
| 71 | final OnlineTransducerModelConfig transducer; | 138 | final OnlineTransducerModelConfig transducer; |
| 72 | final OnlineParaformerModelConfig paraformer; | 139 | final OnlineParaformerModelConfig paraformer; |
| 73 | final OnlineZipformer2CtcModelConfig zipformer2Ctc; | 140 | final OnlineZipformer2CtcModelConfig zipformer2Ctc; |
| @@ -90,11 +157,23 @@ class OnlineModelConfig { | @@ -90,11 +157,23 @@ class OnlineModelConfig { | ||
| 90 | class OnlineCtcFstDecoderConfig { | 157 | class OnlineCtcFstDecoderConfig { |
| 91 | const OnlineCtcFstDecoderConfig({this.graph = '', this.maxActive = 3000}); | 158 | const OnlineCtcFstDecoderConfig({this.graph = '', this.maxActive = 3000}); |
| 92 | 159 | ||
| 160 | + factory OnlineCtcFstDecoderConfig.fromJson(Map<String, dynamic> json) { | ||
| 161 | + return OnlineCtcFstDecoderConfig( | ||
| 162 | + graph: json['graph'] as String? ?? '', | ||
| 163 | + maxActive: json['maxActive'] as int? ?? 3000, | ||
| 164 | + ); | ||
| 165 | + } | ||
| 166 | + | ||
| 93 | @override | 167 | @override |
| 94 | String toString() { | 168 | String toString() { |
| 95 | return 'OnlineCtcFstDecoderConfig(graph: $graph, maxActive: $maxActive)'; | 169 | return 'OnlineCtcFstDecoderConfig(graph: $graph, maxActive: $maxActive)'; |
| 96 | } | 170 | } |
| 97 | 171 | ||
| 172 | + Map<String, dynamic> toJson() => { | ||
| 173 | + 'graph': graph, | ||
| 174 | + 'maxActive': maxActive, | ||
| 175 | + }; | ||
| 176 | + | ||
| 98 | final String graph; | 177 | final String graph; |
| 99 | final int maxActive; | 178 | final int maxActive; |
| 100 | } | 179 | } |
| @@ -117,11 +196,52 @@ class OnlineRecognizerConfig { | @@ -117,11 +196,52 @@ class OnlineRecognizerConfig { | ||
| 117 | this.blankPenalty = 0.0, | 196 | this.blankPenalty = 0.0, |
| 118 | }); | 197 | }); |
| 119 | 198 | ||
| 199 | + factory OnlineRecognizerConfig.fromJson(Map<String, dynamic> json) { | ||
| 200 | + return OnlineRecognizerConfig( | ||
| 201 | + feat: FeatureConfig.fromJson( | ||
| 202 | + json['feat'] as Map<String, dynamic>? ?? const {}), | ||
| 203 | + model: OnlineModelConfig.fromJson(json['model'] as Map<String, dynamic>), | ||
| 204 | + decodingMethod: json['decodingMethod'] as String? ?? 'greedy_search', | ||
| 205 | + maxActivePaths: json['maxActivePaths'] as int? ?? 4, | ||
| 206 | + enableEndpoint: json['enableEndpoint'] as bool? ?? true, | ||
| 207 | + rule1MinTrailingSilence: | ||
| 208 | + (json['rule1MinTrailingSilence'] as num?)?.toDouble() ?? 2.4, | ||
| 209 | + rule2MinTrailingSilence: | ||
| 210 | + (json['rule2MinTrailingSilence'] as num?)?.toDouble() ?? 1.2, | ||
| 211 | + rule3MinUtteranceLength: | ||
| 212 | + (json['rule3MinUtteranceLength'] as num?)?.toDouble() ?? 20.0, | ||
| 213 | + hotwordsFile: json['hotwordsFile'] as String? ?? '', | ||
| 214 | + hotwordsScore: (json['hotwordsScore'] as num?)?.toDouble() ?? 1.5, | ||
| 215 | + ctcFstDecoderConfig: OnlineCtcFstDecoderConfig.fromJson( | ||
| 216 | + json['ctcFstDecoderConfig'] as Map<String, dynamic>? ?? const {}), | ||
| 217 | + ruleFsts: json['ruleFsts'] as String? ?? '', | ||
| 218 | + ruleFars: json['ruleFars'] as String? ?? '', | ||
| 219 | + blankPenalty: (json['blankPenalty'] as num?)?.toDouble() ?? 0.0, | ||
| 220 | + ); | ||
| 221 | + } | ||
| 222 | + | ||
| 120 | @override | 223 | @override |
| 121 | String toString() { | 224 | String toString() { |
| 122 | return 'OnlineRecognizerConfig(feat: $feat, model: $model, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, enableEndpoint: $enableEndpoint, rule1MinTrailingSilence: $rule1MinTrailingSilence, rule2MinTrailingSilence: $rule2MinTrailingSilence, rule3MinUtteranceLength: $rule3MinUtteranceLength, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ctcFstDecoderConfig: $ctcFstDecoderConfig, ruleFsts: $ruleFsts, ruleFars: $ruleFars, blankPenalty: $blankPenalty)'; | 225 | return 'OnlineRecognizerConfig(feat: $feat, model: $model, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, enableEndpoint: $enableEndpoint, rule1MinTrailingSilence: $rule1MinTrailingSilence, rule2MinTrailingSilence: $rule2MinTrailingSilence, rule3MinUtteranceLength: $rule3MinUtteranceLength, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ctcFstDecoderConfig: $ctcFstDecoderConfig, ruleFsts: $ruleFsts, ruleFars: $ruleFars, blankPenalty: $blankPenalty)'; |
| 123 | } | 226 | } |
| 124 | 227 | ||
| 228 | + Map<String, dynamic> toJson() => { | ||
| 229 | + 'feat': feat.toJson(), | ||
| 230 | + 'model': model.toJson(), | ||
| 231 | + 'decodingMethod': decodingMethod, | ||
| 232 | + 'maxActivePaths': maxActivePaths, | ||
| 233 | + 'enableEndpoint': enableEndpoint, | ||
| 234 | + 'rule1MinTrailingSilence': rule1MinTrailingSilence, | ||
| 235 | + 'rule2MinTrailingSilence': rule2MinTrailingSilence, | ||
| 236 | + 'rule3MinUtteranceLength': rule3MinUtteranceLength, | ||
| 237 | + 'hotwordsFile': hotwordsFile, | ||
| 238 | + 'hotwordsScore': hotwordsScore, | ||
| 239 | + 'ctcFstDecoderConfig': ctcFstDecoderConfig.toJson(), | ||
| 240 | + 'ruleFsts': ruleFsts, | ||
| 241 | + 'ruleFars': ruleFars, | ||
| 242 | + 'blankPenalty': blankPenalty, | ||
| 243 | + }; | ||
| 244 | + | ||
| 125 | final FeatureConfig feat; | 245 | final FeatureConfig feat; |
| 126 | final OnlineModelConfig model; | 246 | final OnlineModelConfig model; |
| 127 | final String decodingMethod; | 247 | final String decodingMethod; |
| @@ -151,11 +271,27 @@ class OnlineRecognizerResult { | @@ -151,11 +271,27 @@ class OnlineRecognizerResult { | ||
| 151 | OnlineRecognizerResult( | 271 | OnlineRecognizerResult( |
| 152 | {required this.text, required this.tokens, required this.timestamps}); | 272 | {required this.text, required this.tokens, required this.timestamps}); |
| 153 | 273 | ||
| 274 | + factory OnlineRecognizerResult.fromJson(Map<String, dynamic> json) { | ||
| 275 | + return OnlineRecognizerResult( | ||
| 276 | + text: json['text'] as String, | ||
| 277 | + tokens: List<String>.from(json['tokens'] as List), | ||
| 278 | + timestamps: (json['timestamps'] as List) | ||
| 279 | + .map<double>((e) => (e as num).toDouble()) | ||
| 280 | + .toList(), | ||
| 281 | + ); | ||
| 282 | + } | ||
| 283 | + | ||
| 154 | @override | 284 | @override |
| 155 | String toString() { | 285 | String toString() { |
| 156 | return 'OnlineRecognizerResult(text: $text, tokens: $tokens, timestamps: $timestamps)'; | 286 | return 'OnlineRecognizerResult(text: $text, tokens: $tokens, timestamps: $timestamps)'; |
| 157 | } | 287 | } |
| 158 | 288 | ||
| 289 | + Map<String, dynamic> toJson() => { | ||
| 290 | + 'text': text, | ||
| 291 | + 'tokens': tokens, | ||
| 292 | + 'timestamps': timestamps, | ||
| 293 | + }; | ||
| 294 | + | ||
| 159 | final String text; | 295 | final String text; |
| 160 | final List<String> tokens; | 296 | final List<String> tokens; |
| 161 | final List<double> timestamps; | 297 | final List<double> timestamps; |
| @@ -13,11 +13,27 @@ class SpeakerEmbeddingExtractorConfig { | @@ -13,11 +13,27 @@ class SpeakerEmbeddingExtractorConfig { | ||
| 13 | this.debug = true, | 13 | this.debug = true, |
| 14 | this.provider = 'cpu'}); | 14 | this.provider = 'cpu'}); |
| 15 | 15 | ||
| 16 | + factory SpeakerEmbeddingExtractorConfig.fromJson(Map<String, dynamic> json) { | ||
| 17 | + return SpeakerEmbeddingExtractorConfig( | ||
| 18 | + model: json['model'] as String, | ||
| 19 | + numThreads: json['numThreads'] as int? ?? 1, | ||
| 20 | + debug: json['debug'] as bool? ?? true, | ||
| 21 | + provider: json['provider'] as String? ?? 'cpu', | ||
| 22 | + ); | ||
| 23 | + } | ||
| 24 | + | ||
| 16 | @override | 25 | @override |
| 17 | String toString() { | 26 | String toString() { |
| 18 | return 'SpeakerEmbeddingExtractorConfig(model: $model, numThreads: $numThreads, debug: $debug, provider: $provider)'; | 27 | return 'SpeakerEmbeddingExtractorConfig(model: $model, numThreads: $numThreads, debug: $debug, provider: $provider)'; |
| 19 | } | 28 | } |
| 20 | 29 | ||
| 30 | + Map<String, dynamic> toJson() => { | ||
| 31 | + 'model': model, | ||
| 32 | + 'numThreads': numThreads, | ||
| 33 | + 'debug': debug, | ||
| 34 | + 'provider': provider, | ||
| 35 | + }; | ||
| 36 | + | ||
| 21 | final String model; | 37 | final String model; |
| 22 | final int numThreads; | 38 | final int numThreads; |
| 23 | final bool debug; | 39 | final bool debug; |
| @@ -18,11 +18,35 @@ class OfflineTtsVitsModelConfig { | @@ -18,11 +18,35 @@ class OfflineTtsVitsModelConfig { | ||
| 18 | this.dictDir = '', | 18 | this.dictDir = '', |
| 19 | }); | 19 | }); |
| 20 | 20 | ||
| 21 | + factory OfflineTtsVitsModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 22 | + return OfflineTtsVitsModelConfig( | ||
| 23 | + model: json['model'] as String? ?? '', | ||
| 24 | + lexicon: json['lexicon'] as String? ?? '', | ||
| 25 | + tokens: json['tokens'] as String? ?? '', | ||
| 26 | + dataDir: json['dataDir'] as String? ?? '', | ||
| 27 | + noiseScale: (json['noiseScale'] as num?)?.toDouble() ?? 0.667, | ||
| 28 | + noiseScaleW: (json['noiseScaleW'] as num?)?.toDouble() ?? 0.8, | ||
| 29 | + lengthScale: (json['lengthScale'] as num?)?.toDouble() ?? 1.0, | ||
| 30 | + dictDir: json['dictDir'] as String? ?? '', | ||
| 31 | + ); | ||
| 32 | + } | ||
| 33 | + | ||
| 21 | @override | 34 | @override |
| 22 | String toString() { | 35 | String toString() { |
| 23 | return 'OfflineTtsVitsModelConfig(model: $model, lexicon: $lexicon, tokens: $tokens, dataDir: $dataDir, noiseScale: $noiseScale, noiseScaleW: $noiseScaleW, lengthScale: $lengthScale, dictDir: $dictDir)'; | 36 | return 'OfflineTtsVitsModelConfig(model: $model, lexicon: $lexicon, tokens: $tokens, dataDir: $dataDir, noiseScale: $noiseScale, noiseScaleW: $noiseScaleW, lengthScale: $lengthScale, dictDir: $dictDir)'; |
| 24 | } | 37 | } |
| 25 | 38 | ||
| 39 | + Map<String, dynamic> toJson() => { | ||
| 40 | + 'model': model, | ||
| 41 | + 'lexicon': lexicon, | ||
| 42 | + 'tokens': tokens, | ||
| 43 | + 'dataDir': dataDir, | ||
| 44 | + 'noiseScale': noiseScale, | ||
| 45 | + 'noiseScaleW': noiseScaleW, | ||
| 46 | + 'lengthScale': lengthScale, | ||
| 47 | + 'dictDir': dictDir, | ||
| 48 | + }; | ||
| 49 | + | ||
| 26 | final String model; | 50 | final String model; |
| 27 | final String lexicon; | 51 | final String lexicon; |
| 28 | final String tokens; | 52 | final String tokens; |
| @@ -45,11 +69,35 @@ class OfflineTtsMatchaModelConfig { | @@ -45,11 +69,35 @@ class OfflineTtsMatchaModelConfig { | ||
| 45 | this.dictDir = '', | 69 | this.dictDir = '', |
| 46 | }); | 70 | }); |
| 47 | 71 | ||
| 72 | + factory OfflineTtsMatchaModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 73 | + return OfflineTtsMatchaModelConfig( | ||
| 74 | + acousticModel: json['acousticModel'] as String? ?? '', | ||
| 75 | + vocoder: json['vocoder'] as String? ?? '', | ||
| 76 | + lexicon: json['lexicon'] as String? ?? '', | ||
| 77 | + tokens: json['tokens'] as String? ?? '', | ||
| 78 | + dataDir: json['dataDir'] as String? ?? '', | ||
| 79 | + noiseScale: (json['noiseScale'] as num?)?.toDouble() ?? 0.667, | ||
| 80 | + lengthScale: (json['lengthScale'] as num?)?.toDouble() ?? 1.0, | ||
| 81 | + dictDir: json['dictDir'] as String? ?? '', | ||
| 82 | + ); | ||
| 83 | + } | ||
| 84 | + | ||
| 48 | @override | 85 | @override |
| 49 | String toString() { | 86 | String toString() { |
| 50 | return 'OfflineTtsMatchaModelConfig(acousticModel: $acousticModel, vocoder: $vocoder, lexicon: $lexicon, tokens: $tokens, dataDir: $dataDir, noiseScale: $noiseScale, lengthScale: $lengthScale, dictDir: $dictDir)'; | 87 | return 'OfflineTtsMatchaModelConfig(acousticModel: $acousticModel, vocoder: $vocoder, lexicon: $lexicon, tokens: $tokens, dataDir: $dataDir, noiseScale: $noiseScale, lengthScale: $lengthScale, dictDir: $dictDir)'; |
| 51 | } | 88 | } |
| 52 | 89 | ||
| 90 | + Map<String, dynamic> toJson() => { | ||
| 91 | + 'acousticModel': acousticModel, | ||
| 92 | + 'vocoder': vocoder, | ||
| 93 | + 'lexicon': lexicon, | ||
| 94 | + 'tokens': tokens, | ||
| 95 | + 'dataDir': dataDir, | ||
| 96 | + 'noiseScale': noiseScale, | ||
| 97 | + 'lengthScale': lengthScale, | ||
| 98 | + 'dictDir': dictDir, | ||
| 99 | + }; | ||
| 100 | + | ||
| 53 | final String acousticModel; | 101 | final String acousticModel; |
| 54 | final String vocoder; | 102 | final String vocoder; |
| 55 | final String lexicon; | 103 | final String lexicon; |
| @@ -71,11 +119,33 @@ class OfflineTtsKokoroModelConfig { | @@ -71,11 +119,33 @@ class OfflineTtsKokoroModelConfig { | ||
| 71 | this.lexicon = '', | 119 | this.lexicon = '', |
| 72 | }); | 120 | }); |
| 73 | 121 | ||
| 122 | + factory OfflineTtsKokoroModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 123 | + return OfflineTtsKokoroModelConfig( | ||
| 124 | + model: json['model'] as String? ?? '', | ||
| 125 | + voices: json['voices'] as String? ?? '', | ||
| 126 | + tokens: json['tokens'] as String? ?? '', | ||
| 127 | + dataDir: json['dataDir'] as String? ?? '', | ||
| 128 | + lengthScale: (json['lengthScale'] as num?)?.toDouble() ?? 1.0, | ||
| 129 | + dictDir: json['dictDir'] as String? ?? '', | ||
| 130 | + lexicon: json['lexicon'] as String? ?? '', | ||
| 131 | + ); | ||
| 132 | + } | ||
| 133 | + | ||
| 74 | @override | 134 | @override |
| 75 | String toString() { | 135 | String toString() { |
| 76 | return 'OfflineTtsKokoroModelConfig(model: $model, voices: $voices, tokens: $tokens, dataDir: $dataDir, lengthScale: $lengthScale, dictDir: $dictDir, lexicon: $lexicon)'; | 136 | return 'OfflineTtsKokoroModelConfig(model: $model, voices: $voices, tokens: $tokens, dataDir: $dataDir, lengthScale: $lengthScale, dictDir: $dictDir, lexicon: $lexicon)'; |
| 77 | } | 137 | } |
| 78 | 138 | ||
| 139 | + Map<String, dynamic> toJson() => { | ||
| 140 | + 'model': model, | ||
| 141 | + 'voices': voices, | ||
| 142 | + 'tokens': tokens, | ||
| 143 | + 'dataDir': dataDir, | ||
| 144 | + 'lengthScale': lengthScale, | ||
| 145 | + 'dictDir': dictDir, | ||
| 146 | + 'lexicon': lexicon, | ||
| 147 | + }; | ||
| 148 | + | ||
| 79 | final String model; | 149 | final String model; |
| 80 | final String voices; | 150 | final String voices; |
| 81 | final String tokens; | 151 | final String tokens; |
| @@ -95,11 +165,34 @@ class OfflineTtsModelConfig { | @@ -95,11 +165,34 @@ class OfflineTtsModelConfig { | ||
| 95 | this.provider = 'cpu', | 165 | this.provider = 'cpu', |
| 96 | }); | 166 | }); |
| 97 | 167 | ||
| 168 | + factory OfflineTtsModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 169 | + return OfflineTtsModelConfig( | ||
| 170 | + vits: OfflineTtsVitsModelConfig.fromJson( | ||
| 171 | + json['vits'] as Map<String, dynamic>? ?? const {}), | ||
| 172 | + matcha: OfflineTtsMatchaModelConfig.fromJson( | ||
| 173 | + json['matcha'] as Map<String, dynamic>? ?? const {}), | ||
| 174 | + kokoro: OfflineTtsKokoroModelConfig.fromJson( | ||
| 175 | + json['kokoro'] as Map<String, dynamic>? ?? const {}), | ||
| 176 | + numThreads: json['numThreads'] as int? ?? 1, | ||
| 177 | + debug: json['debug'] as bool? ?? true, | ||
| 178 | + provider: json['provider'] as String? ?? 'cpu', | ||
| 179 | + ); | ||
| 180 | + } | ||
| 181 | + | ||
| 98 | @override | 182 | @override |
| 99 | String toString() { | 183 | String toString() { |
| 100 | return 'OfflineTtsModelConfig(vits: $vits, matcha: $matcha, kokoro: $kokoro, numThreads: $numThreads, debug: $debug, provider: $provider)'; | 184 | return 'OfflineTtsModelConfig(vits: $vits, matcha: $matcha, kokoro: $kokoro, numThreads: $numThreads, debug: $debug, provider: $provider)'; |
| 101 | } | 185 | } |
| 102 | 186 | ||
| 187 | + Map<String, dynamic> toJson() => { | ||
| 188 | + 'vits': vits.toJson(), | ||
| 189 | + 'matcha': matcha.toJson(), | ||
| 190 | + 'kokoro': kokoro.toJson(), | ||
| 191 | + 'numThreads': numThreads, | ||
| 192 | + 'debug': debug, | ||
| 193 | + 'provider': provider, | ||
| 194 | + }; | ||
| 195 | + | ||
| 103 | final OfflineTtsVitsModelConfig vits; | 196 | final OfflineTtsVitsModelConfig vits; |
| 104 | final OfflineTtsMatchaModelConfig matcha; | 197 | final OfflineTtsMatchaModelConfig matcha; |
| 105 | final OfflineTtsKokoroModelConfig kokoro; | 198 | final OfflineTtsKokoroModelConfig kokoro; |
| @@ -117,11 +210,30 @@ class OfflineTtsConfig { | @@ -117,11 +210,30 @@ class OfflineTtsConfig { | ||
| 117 | this.silenceScale = 0.2, | 210 | this.silenceScale = 0.2, |
| 118 | }); | 211 | }); |
| 119 | 212 | ||
| 213 | + factory OfflineTtsConfig.fromJson(Map<String, dynamic> json) { | ||
| 214 | + return OfflineTtsConfig( | ||
| 215 | + model: | ||
| 216 | + OfflineTtsModelConfig.fromJson(json['model'] as Map<String, dynamic>), | ||
| 217 | + ruleFsts: json['ruleFsts'] as String? ?? '', | ||
| 218 | + maxNumSenetences: json['maxNumSenetences'] as int? ?? 1, | ||
| 219 | + ruleFars: json['ruleFars'] as String? ?? '', | ||
| 220 | + silenceScale: (json['silenceScale'] as num?)?.toDouble() ?? 0.2, | ||
| 221 | + ); | ||
| 222 | + } | ||
| 223 | + | ||
| 120 | @override | 224 | @override |
| 121 | String toString() { | 225 | String toString() { |
| 122 | return 'OfflineTtsConfig(model: $model, ruleFsts: $ruleFsts, maxNumSenetences: $maxNumSenetences, ruleFars: $ruleFars, silenceScale: $silenceScale)'; | 226 | return 'OfflineTtsConfig(model: $model, ruleFsts: $ruleFsts, maxNumSenetences: $maxNumSenetences, ruleFars: $ruleFars, silenceScale: $silenceScale)'; |
| 123 | } | 227 | } |
| 124 | 228 | ||
| 229 | + Map<String, dynamic> toJson() => { | ||
| 230 | + 'model': model.toJson(), | ||
| 231 | + 'ruleFsts': ruleFsts, | ||
| 232 | + 'maxNumSenetences': maxNumSenetences, | ||
| 233 | + 'ruleFars': ruleFars, | ||
| 234 | + 'silenceScale': silenceScale, | ||
| 235 | + }; | ||
| 236 | + | ||
| 125 | final OfflineTtsModelConfig model; | 237 | final OfflineTtsModelConfig model; |
| 126 | final String ruleFsts; | 238 | final String ruleFsts; |
| 127 | final int maxNumSenetences; | 239 | final int maxNumSenetences; |
| @@ -14,11 +14,33 @@ class SileroVadModelConfig { | @@ -14,11 +14,33 @@ class SileroVadModelConfig { | ||
| 14 | this.windowSize = 512, | 14 | this.windowSize = 512, |
| 15 | this.maxSpeechDuration = 5.0}); | 15 | this.maxSpeechDuration = 5.0}); |
| 16 | 16 | ||
| 17 | + factory SileroVadModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 18 | + return SileroVadModelConfig( | ||
| 19 | + model: json['model'] as String? ?? '', | ||
| 20 | + threshold: (json['threshold'] as num?)?.toDouble() ?? 0.5, | ||
| 21 | + minSilenceDuration: | ||
| 22 | + (json['minSilenceDuration'] as num?)?.toDouble() ?? 0.5, | ||
| 23 | + minSpeechDuration: | ||
| 24 | + (json['minSpeechDuration'] as num?)?.toDouble() ?? 0.25, | ||
| 25 | + windowSize: json['windowSize'] as int? ?? 512, | ||
| 26 | + maxSpeechDuration: (json['maxSpeechDuration'] as num?)?.toDouble() ?? 5.0, | ||
| 27 | + ); | ||
| 28 | + } | ||
| 29 | + | ||
| 17 | @override | 30 | @override |
| 18 | String toString() { | 31 | String toString() { |
| 19 | return 'SileroVadModelConfig(model: $model, threshold: $threshold, minSilenceDuration: $minSilenceDuration, minSpeechDuration: $minSpeechDuration, windowSize: $windowSize, maxSpeechDuration: $maxSpeechDuration)'; | 32 | return 'SileroVadModelConfig(model: $model, threshold: $threshold, minSilenceDuration: $minSilenceDuration, minSpeechDuration: $minSpeechDuration, windowSize: $windowSize, maxSpeechDuration: $maxSpeechDuration)'; |
| 20 | } | 33 | } |
| 21 | 34 | ||
| 35 | + Map<String, dynamic> toJson() => { | ||
| 36 | + 'model': model, | ||
| 37 | + 'threshold': threshold, | ||
| 38 | + 'minSilenceDuration': minSilenceDuration, | ||
| 39 | + 'minSpeechDuration': minSpeechDuration, | ||
| 40 | + 'windowSize': windowSize, | ||
| 41 | + 'maxSpeechDuration': maxSpeechDuration, | ||
| 42 | + }; | ||
| 43 | + | ||
| 22 | final String model; | 44 | final String model; |
| 23 | final double threshold; | 45 | final double threshold; |
| 24 | final double minSilenceDuration; | 46 | final double minSilenceDuration; |
| @@ -28,23 +50,43 @@ class SileroVadModelConfig { | @@ -28,23 +50,43 @@ class SileroVadModelConfig { | ||
| 28 | } | 50 | } |
| 29 | 51 | ||
| 30 | class VadModelConfig { | 52 | class VadModelConfig { |
| 31 | - VadModelConfig( | ||
| 32 | - {this.sileroVad = const SileroVadModelConfig(), | ||
| 33 | - this.sampleRate = 16000, | ||
| 34 | - this.numThreads = 1, | ||
| 35 | - this.provider = 'cpu', | ||
| 36 | - this.debug = true}); | ||
| 37 | - | ||
| 38 | - @override | ||
| 39 | - String toString() { | ||
| 40 | - return 'VadModelConfig(sileroVad: $sileroVad, sampleRate: $sampleRate, numThreads: $numThreads, provider: $provider, debug: $debug)'; | ||
| 41 | - } | 53 | + VadModelConfig({ |
| 54 | + this.sileroVad = const SileroVadModelConfig(), | ||
| 55 | + this.sampleRate = 16000, | ||
| 56 | + this.numThreads = 1, | ||
| 57 | + this.provider = 'cpu', | ||
| 58 | + this.debug = true, | ||
| 59 | + }); | ||
| 42 | 60 | ||
| 43 | final SileroVadModelConfig sileroVad; | 61 | final SileroVadModelConfig sileroVad; |
| 44 | final int sampleRate; | 62 | final int sampleRate; |
| 45 | final int numThreads; | 63 | final int numThreads; |
| 46 | final String provider; | 64 | final String provider; |
| 47 | final bool debug; | 65 | final bool debug; |
| 66 | + | ||
| 67 | + factory VadModelConfig.fromJson(Map<String, dynamic> json) { | ||
| 68 | + return VadModelConfig( | ||
| 69 | + sileroVad: SileroVadModelConfig.fromJson( | ||
| 70 | + json['sileroVad'] as Map<String, dynamic>? ?? const {}), | ||
| 71 | + sampleRate: json['sampleRate'] as int? ?? 16000, | ||
| 72 | + numThreads: json['numThreads'] as int? ?? 1, | ||
| 73 | + provider: json['provider'] as String? ?? 'cpu', | ||
| 74 | + debug: json['debug'] as bool? ?? true, | ||
| 75 | + ); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + Map<String, dynamic> toJson() => { | ||
| 79 | + 'sileroVad': sileroVad.toJson(), | ||
| 80 | + 'sampleRate': sampleRate, | ||
| 81 | + 'numThreads': numThreads, | ||
| 82 | + 'provider': provider, | ||
| 83 | + 'debug': debug, | ||
| 84 | + }; | ||
| 85 | + | ||
| 86 | + @override | ||
| 87 | + String toString() { | ||
| 88 | + return 'VadModelConfig(sileroVad: $sileroVad, sampleRate: $sampleRate, numThreads: $numThreads, provider: $provider, debug: $debug)'; | ||
| 89 | + } | ||
| 48 | } | 90 | } |
| 49 | 91 | ||
| 50 | class SpeechSegment { | 92 | class SpeechSegment { |
-
请 注册 或 登录 后发表评论