sherpa-onnx icon indicating copy to clipboard operation
sherpa-onnx copied to clipboard

Enhance model config build logic with Strategy Pattern

Open SamYuan1990 opened this issue 1 month ago • 0 comments

ref https://github.com/k2-fsa/sherpa-onnx/blob/master/flutter-examples/streaming_asr/lib/online_model.dart#L6 or https://github.com/k2-fsa/sherpa-onnx/blob/master/flutter-examples/non_streaming_vad_asr/lib/offline_model.dart#L7

in fact we have implemented Strategy Pattern as line above, but to provide more convenience when using sdk or allow end user to select model by their wanted...

For example, developer using sherpa-onnx development an App, which allows end user to select model by their want. end user may want to use zipformer or zipformer2 or ... other models on demand.

in stead of a switch number logic, we may need using a model type instead and also impls model config init logic.... a dart logic with OfflineWhisperModelConfig as example:

Future<sherpa_onnx.OfflineModelConfig> getOfflineModelConfig(
encoder
decoder
tokens
modelType
joiner
model
...
) async {
switch (modelType)
   case whisper:
        return sherpa_onnx.OfflineModelConfig(
                whisper:sherpa_onnx.OfflineWhisperModelConfig(
                  encoder: await copyAssetFile('$modelDir/whisper/base-encoder.onnx'),
                  decoder: await copyAssetFile('$modelDir/whisper/base-decoder.onnx'),
                ),
                tokens: await copyAssetFile('$modelDir/whisper/base-tokens.txt'),
                modelType: 'whisper',
              );
   case ...
}

SamYuan1990 avatar Oct 27 '25 13:10 SamYuan1990