flutter_heyteacher_text_to_speech 4.0.2+161
flutter_heyteacher_text_to_speech: ^4.0.2+161 copied to clipboard
The flutter heyteacher text-to-speech (TTS) utilities localized in six languages
flutter_heyteacher_text_to_speech #
A Flutter package based on flutter_tts for managing Text-to-Speech (TTS) functionalities, specifically designed for the Flutter HeyTeacher ecosystem. This package provides view models for controlling TTS output and UI components for user settings.
Features #
- TTS Management: Control text-to-speech output using
TTSViewModelwithThrottling / Threshold logiclogic - UI Components: Ready-to-use widgets like
EnableTTSChoiceCardfor enabling/disabling TTS. - Localization: Integrated localization support via
FlutterHeyteacherTextToSpeechLocalizations.
The components in this packages are implemented following Model-View-ViewModel (MVVM) architecture and Singleton pattern.
Getting started #
Add the package to your pubspec.yaml:
dependencies:
flutter_heyteacher_text_to_speech: any
Usage #
Parameters #
Configuration is set during TTSViewModel.instance(bool? defaultEnabled, int? thresholdInSeconds) initialization.
defaultEnabled: if is enabled by default (trueby default)thresholdInSeconds: the minimum interval in seconds between messages speaked (5by default)
TTS Control #
Use TTSViewModel to handle speech operations.
import 'package:flutter_heyteacher_text_to_speech/text_to_speech.dart';
void main() async {
// Example: Speak a sentence
await TTSViewModel.instance().speak('Hello, welcome to HeyTeacher!', checkTTSThreshold: true);
}
Throttling / Threshold logic #
In order to avoid message repeats and overlaps, a threshold logic is implemented.
-
speaks of same message are ignored regardless
thresholdInSecondsspeak(Hello) yes -> speak(Hello) no -> await `thresholdInSeconds` seconds -> speak(Hello) no -
speak of different message after
thresholdInSecondsis passedspeak(Hello) yes -> await `thresholdInSeconds` seconds -> speak(goodbye) yes -
speak of message within
thresholdInSecondsare delayed ofthresholdInSecondssecondsspeak(hello) yes -> speak(goodbye) -> await `thresholdInSeconds` seconds -> true -
speak of message within
thresholdInSecondsonly if last message changes'speak(hello) yes -> speak(hello) no -> speak(goodbye) -> await `thresholdInSeconds` seconds -> yes' 'speak(hello) yes -> speak(goodbye) no -> speak(hello) no -> speak(goodbye) -> await `thresholdInSeconds` seconds -> yes'
Invoking speak setting parameter checkTTSThreshold to false, skip threshold logic and the text is always spoken.
await TTSViewModel.instance().speak('Hello, welcome to HeyTeacher!', checkTTSThreshold: false);
UI Components #
Use EnableTTSChoiceCard to allow users to toggle TTS settings within your application.
import 'package:flutter/material.dart';
import 'package:flutter_heyteacher_text_to_speech/text_to_speech.dart';
class SettingsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: EnableTTSChoiceListTile(),
),
);
}
}