Skip to content

Commit c1244a0

Browse files
DevDesai444sanchitmonga22
authored andcommitted
Add Flutter TTS configuration validation
1 parent 348f9de commit c1244a0

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

sdk/runanywhere-flutter/packages/runanywhere/lib/features/tts/system_tts_service.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import 'dart:async';
88
import 'dart:typed_data';
99

1010
import 'package:flutter_tts/flutter_tts.dart';
11+
import 'package:runanywhere/core/protocols/component/component_configuration.dart';
12+
import 'package:runanywhere/foundation/error_types/sdk_error.dart';
1113

1214
/// Configuration for TTS synthesis
13-
class TTSConfiguration {
15+
class TTSConfiguration implements ComponentConfiguration {
1416
final String voice;
1517
final String language;
1618
final double speakingRate;
@@ -26,6 +28,27 @@ class TTSConfiguration {
2628
this.volume = 1.0,
2729
this.audioFormat = 'pcm',
2830
});
31+
32+
@override
33+
void validate() {
34+
if (!speakingRate.isFinite || speakingRate < 0.5 || speakingRate > 2.0) {
35+
throw SDKError.validationFailed(
36+
'Speaking rate must be between 0.5 and 2.0',
37+
);
38+
}
39+
40+
if (!pitch.isFinite || pitch < 0.5 || pitch > 2.0) {
41+
throw SDKError.validationFailed(
42+
'Pitch must be between 0.5 and 2.0',
43+
);
44+
}
45+
46+
if (!volume.isFinite || volume < 0.0 || volume > 1.0) {
47+
throw SDKError.validationFailed(
48+
'Volume must be between 0.0 and 1.0',
49+
);
50+
}
51+
}
2952
}
3053

3154
/// Input for TTS synthesis

0 commit comments

Comments
 (0)