|
| 1 | +import 'package:runanywhere/core/protocols/component/component_configuration.dart'; |
| 2 | +import 'package:runanywhere/core/types/model_types.dart'; |
| 3 | +import 'package:runanywhere/foundation/error_types/sdk_error.dart'; |
| 4 | + |
| 5 | +/// Configuration for the STT component. |
| 6 | +/// |
| 7 | +/// Mirrors the validation contract used by the Swift and Kotlin SDKs so |
| 8 | +/// invalid parameters fail in Dart before crossing the FFI boundary. |
| 9 | +class STTConfiguration implements ComponentConfiguration { |
| 10 | + final String? modelId; |
| 11 | + final InferenceFramework? preferredFramework; |
| 12 | + final String language; |
| 13 | + final int sampleRate; |
| 14 | + final bool enablePunctuation; |
| 15 | + final bool enableDiarization; |
| 16 | + final List<String> vocabularyList; |
| 17 | + final int maxAlternatives; |
| 18 | + final bool enableTimestamps; |
| 19 | + |
| 20 | + const STTConfiguration({ |
| 21 | + this.modelId, |
| 22 | + this.preferredFramework, |
| 23 | + this.language = 'en-US', |
| 24 | + this.sampleRate = 16000, |
| 25 | + this.enablePunctuation = true, |
| 26 | + this.enableDiarization = false, |
| 27 | + this.vocabularyList = const <String>[], |
| 28 | + this.maxAlternatives = 1, |
| 29 | + this.enableTimestamps = true, |
| 30 | + }); |
| 31 | + |
| 32 | + @override |
| 33 | + void validate() { |
| 34 | + if (sampleRate <= 0 || sampleRate > 48000) { |
| 35 | + throw SDKError.validationFailed( |
| 36 | + 'Sample rate must be between 1 and 48000 Hz', |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + if (maxAlternatives <= 0 || maxAlternatives > 10) { |
| 41 | + throw SDKError.validationFailed( |
| 42 | + 'Max alternatives must be between 1 and 10', |
| 43 | + ); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments