import 'package:flutter/foundation.dart'; /// One platform voice. [locale] is a BCP 47 tag such as `en-GB`. @immutable class SpeechVoice { const SpeechVoice({required this.name, required this.locale}); final String name; final String locale; /// The primary language subtag (`en` for `en-GB`), lower case. String get language => locale.split(RegExp('[-_]')).first.toLowerCase(); @override bool operator ==(Object other) => other is SpeechVoice && other.name == name && other.locale == locale; @override int get hashCode => Object.hash(name, locale); } /// The platform text-to-speech service the [SpeechController] drives. /// /// [setRate] takes a multiplier where 1.0 is the platform's normal speed; an /// implementation maps it onto its own scale. [onProgress] reports the word /// being spoken as offsets into [utterance], the text the platform is actually /// speaking (after a resume that can be a suffix of the text passed to /// [speak]). Platforms without word boundaries never call it. abstract class SpeechEngine { /// Whether this platform can speak at all; the UI hides read aloud if not. bool get supported; VoidCallback? onStart; VoidCallback? onPause; VoidCallback? onResume; VoidCallback? onCompletion; VoidCallback? onCancel; ValueChanged? onError; void Function(String utterance, int start, int end)? onProgress; /// Speaks [text]. Called with the same text while paused, it resumes. Future speak(String text); Future pause(); Future stop(); /// Selects [voice], or the platform default when null. Future setVoice(SpeechVoice? voice); Future setRate(double rate); Future> voices(); }