feat: Add Text-to-Speech settings and customization options

- Introduced new preference keys for TTS settings: voice, speech rate, pitch, and volume.
- Updated SettingsService to handle TTS settings and persist them.
- Enhanced AppSettings to include TTS-related properties.
- Implemented TTS settings UI in AppCustomizationPage, allowing users to select voice and adjust speech parameters.
- Added localization support for TTS settings in multiple languages.
This commit is contained in:
cogwheel0
2025-10-17 14:40:44 +05:30
parent c6acfa68e1
commit 6c81d68e59
18 changed files with 1185 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../core/services/settings_service.dart';
import '../../../core/utils/markdown_to_text.dart';
import '../services/text_to_speech_service.dart';
@@ -58,6 +59,7 @@ class TextToSpeechController extends Notifier<TextToSpeechState> {
@override
TextToSpeechState build() {
_service = ref.watch(textToSpeechServiceProvider);
if (!_handlersBound) {
_handlersBound = true;
_service.bindHandlers(
@@ -73,6 +75,19 @@ class TextToSpeechController extends Notifier<TextToSpeechState> {
unawaited(_service.stop());
});
}
// Listen to settings changes and update TTS when initialized
ref.listen<AppSettings>(appSettingsProvider, (previous, next) {
if (_service.isInitialized && _service.isAvailable) {
_service.updateSettings(
voice: next.ttsVoice,
speechRate: next.ttsSpeechRate,
pitch: next.ttsPitch,
volume: next.ttsVolume,
);
}
}, fireImmediately: false);
return const TextToSpeechState();
}
@@ -87,8 +102,14 @@ class TextToSpeechController extends Notifier<TextToSpeechState> {
clearErrorMessage: true,
);
final settings = ref.read(appSettingsProvider);
final future = _service
.initialize()
.initialize(
voice: settings.ttsVoice,
speechRate: settings.ttsSpeechRate,
pitch: settings.ttsPitch,
volume: settings.ttsVolume,
)
.then((available) {
if (!ref.mounted) {
return available;