26 lines
606 B
Dart
26 lines
606 B
Dart
import 'package:flutter_tts/flutter_tts.dart';
|
|
|
|
class TextToSpeech {
|
|
final FlutterTts tts = FlutterTts();
|
|
|
|
// Initialize the TTS engine with desired settings
|
|
Future initTts() async {
|
|
await tts.setLanguage('en-US'); // Set language
|
|
await tts.setSpeechRate(0.8); // Adjust speech rate
|
|
await tts.setVolume(1.0); // Set volume
|
|
}
|
|
|
|
// Speak the given text
|
|
Future speakText(String text) async {
|
|
await tts.speak(text);
|
|
}
|
|
|
|
// Stop speaking
|
|
Future stopSpeaking() async {
|
|
await tts.stop();
|
|
}
|
|
|
|
// Check if TTS is currently speaking
|
|
// bool isSpeaking() => tts.isSpeaking;
|
|
}
|