ttsService static method
Implementation
static String ttsService() {
return '''
import 'package:flutter/foundation.dart';
import 'package:flutter_tts/flutter_tts.dart';
/// Text → Speech helper.
///
/// Usage:
/// final tts = TtsService();
/// await tts.speak("Hello there");
class TtsService {
final FlutterTts _tts = FlutterTts();
TtsService() {
_tts.setSpeechRate(0.5);
_tts.setPitch(1.0);
}
Future<void> speak(String text) async {
if (text.trim().isEmpty) return;
await _tts.stop();
await _tts.speak(text);
}
Future<void> stop() async {
await _tts.stop();
}
Future<void> dispose() async {
try {
await _tts.stop();
} catch (e) {
if (kDebugMode) {
debugPrint('TTS dispose error: \$e');
}
}
}
}
''';
}