A cross platform Audiobookshelf client for Android and iOS
Dart
Add a pitch slider to the equalizer so the narrator can sound lower or higher
Barnabasfcb0245de75e
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arbindex 5faefcd9..84673955 100644--- a/lib/l10n/app_en.arb+++ b/lib/l10n/app_en.arb@@ -2420,6 +2420,7 @@"bassBoost": "Bass Boost","surround": "Surround","loudness": "Loudness",+ "pitch": "Pitch","monoAudio": "Mono Audio","skipSilence": "Skip Silence","resetAll": "Reset All",diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dartindex 56474601..396bc09f 100644--- a/lib/l10n/app_localizations.dart+++ b/lib/l10n/app_localizations.dart@@ -8386,6 +8386,12 @@ abstract class AppLocalizations {/// **'Loudness'**String get loudness;+ /// No description provided for @pitch.+ ///+ /// In en, this message translates to:+ /// **'Pitch'**+ String get pitch;+/// No description provided for @monoAudio.////// In en, this message translates to:diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dartindex 066c1440..1d058dc6 100644--- a/lib/l10n/app_localizations_de.dart+++ b/lib/l10n/app_localizations_de.dart@@ -4776,6 +4776,9 @@ class AppLocalizationsDe extends AppLocalizations {@overrideString get loudness => 'Lautheit';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => 'Mono-Audio';diff --git a/lib/l10n/app_localizations_el.dart b/lib/l10n/app_localizations_el.dartindex 0262c57a..4da7bf0e 100644--- a/lib/l10n/app_localizations_el.dart+++ b/lib/l10n/app_localizations_el.dart@@ -4723,6 +4723,9 @@ class AppLocalizationsEl extends AppLocalizations {@overrideString get loudness => 'Loudness';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => 'Mono Audio';diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dartindex 76885ae8..5b26ea49 100644--- a/lib/l10n/app_localizations_en.dart+++ b/lib/l10n/app_localizations_en.dart@@ -4723,6 +4723,9 @@ class AppLocalizationsEn extends AppLocalizations {@overrideString get loudness => 'Loudness';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => 'Mono Audio';diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dartindex 224694a8..7cd06eac 100644--- a/lib/l10n/app_localizations_es.dart+++ b/lib/l10n/app_localizations_es.dart@@ -4725,6 +4725,9 @@ class AppLocalizationsEs extends AppLocalizations {@overrideString get loudness => 'Loudness';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => 'Mono Audio';diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dartindex b6a673b6..c33391e3 100644--- a/lib/l10n/app_localizations_fr.dart+++ b/lib/l10n/app_localizations_fr.dart@@ -4774,6 +4774,9 @@ class AppLocalizationsFr extends AppLocalizations {@overrideString get loudness => 'Volume';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => 'Audio mono';diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dartindex 049c24de..fbbe4166 100644--- a/lib/l10n/app_localizations_it.dart+++ b/lib/l10n/app_localizations_it.dart@@ -4723,6 +4723,9 @@ class AppLocalizationsIt extends AppLocalizations {@overrideString get loudness => 'Loudness';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => 'Mono Audio';diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dartindex e9dfea0c..1584f5af 100644--- a/lib/l10n/app_localizations_ja.dart+++ b/lib/l10n/app_localizations_ja.dart@@ -4723,6 +4723,9 @@ class AppLocalizationsJa extends AppLocalizations {@overrideString get loudness => 'Loudness';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => 'Mono Audio';diff --git a/lib/l10n/app_localizations_no.dart b/lib/l10n/app_localizations_no.dartindex cc72b9f3..c61bb1b4 100644--- a/lib/l10n/app_localizations_no.dart+++ b/lib/l10n/app_localizations_no.dart@@ -4723,6 +4723,9 @@ class AppLocalizationsNo extends AppLocalizations {@overrideString get loudness => 'Loudness';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => 'Mono Audio';diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dartindex 32527ad6..de7d87b2 100644--- a/lib/l10n/app_localizations_pt.dart+++ b/lib/l10n/app_localizations_pt.dart@@ -4723,6 +4723,9 @@ class AppLocalizationsPt extends AppLocalizations {@overrideString get loudness => 'Loudness';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => 'Mono Audio';diff --git a/lib/l10n/app_localizations_ro.dart b/lib/l10n/app_localizations_ro.dartindex cbf3d18c..2ad84fa6 100644--- a/lib/l10n/app_localizations_ro.dart+++ b/lib/l10n/app_localizations_ro.dart@@ -4723,6 +4723,9 @@ class AppLocalizationsRo extends AppLocalizations {@overrideString get loudness => 'Loudness';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => 'Mono Audio';diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dartindex 623fa099..e2b2d024 100644--- a/lib/l10n/app_localizations_ru.dart+++ b/lib/l10n/app_localizations_ru.dart@@ -4727,6 +4727,9 @@ class AppLocalizationsRu extends AppLocalizations {@overrideString get loudness => 'Loudness';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => 'Mono Audio';diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dartindex 498febe7..2bb57bc1 100644--- a/lib/l10n/app_localizations_zh.dart+++ b/lib/l10n/app_localizations_zh.dart@@ -4653,6 +4653,9 @@ class AppLocalizationsZh extends AppLocalizations {@overrideString get loudness => '响度';+ @override+ String get pitch => 'Pitch';+@overrideString get monoAudio => '单声道音频';diff --git a/lib/services/_audio_player.dart b/lib/services/_audio_player.dartindex 05ddfa65..2e085b35 100644--- a/lib/services/_audio_player.dart+++ b/lib/services/_audio_player.dart@@ -145,6 +145,10 @@ class AudioPlayer {_isNative ? _native!.setVolume(volume) : _ja!.setVolume(volume);Future<void> setSkipSilenceEnabled(bool enabled) =>_isNative ? _native!.setSkipSilenceEnabled(enabled) : _ja!.setSkipSilenceEnabled(enabled);+ // The native iOS engine ties pitch to speed, so only ExoPlayer takes it.+ Future<void> setPitch(double pitch) async {+ if (!_isNative) await _ja!.setPitch(pitch);+ }Future<Duration?> setAsset(String asset) =>_isNative ? _native!.setAsset(asset) : _ja!.setAsset(asset);Future<void> dispose() =>diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dartindex 01b7ce66..2eeea862 100644--- a/lib/services/audio_player_service.dart+++ b/lib/services/audio_player_service.dart@@ -3030,6 +3030,14 @@ class AudioPlayerService extends ChangeNotifier {debugPrint('[Player] setSkipSilenceEnabled failed: $e');}});+ // Pitch is a ratio to ExoPlayer; the slider is in semitones.+ EqualizerService().setPitchApplier((semitones) {+ try {+ _handler?.player.setPitch(math.pow(2.0, semitones / 12.0).toDouble());+ } catch (e) {+ debugPrint('[Player] setPitch failed: $e');+ }+ });}// iOS native engine: keep the processing tap attached whenever any// EQ/effect is active so effects work with the band EQ off.diff --git a/lib/services/equalizer_service.dart b/lib/services/equalizer_service.dartindex c5862e36..a757e363 100644--- a/lib/services/equalizer_service.dart+++ b/lib/services/equalizer_service.dart@@ -25,15 +25,23 @@ class EqualizerService extends ChangeNotifier {double _loudnessGain = 0.0; // 0.0–1.0bool _mono = false;bool _skipSilence = false;+ double _pitch = 0.0; // semitones, independent of speedbool _perItem = false;String? _currentItemId;+ static const double minPitch = -6.0;+ static const double maxPitch = 6.0;+/// Applied to the just_audio AudioPlayer whenever skipSilence changes/// (toggle, per-book switch, account reload). Registered by/// AudioPlayerService.init so the EQ service stays decoupled from/// just_audio.void Function(bool enabled)? _skipSilenceApplier;+ /// Applied to the player whenever the pitch changes, with the shift in+ /// semitones. Registered by AudioPlayerService like the skip-silence one.+ void Function(double semitones)? _pitchApplier;+/// Invoked when [anyProcessingActive] may have changed so the iOS engine can/// attach/detach its processing tap. Registered by AudioPlayerService.void Function(bool active)? _tapApplier;@@ -63,6 +71,7 @@ class EqualizerService extends ChangeNotifier {double get loudnessGain => _loudnessGain;bool get mono => _mono;bool get skipSilence => _skipSilence;+ double get pitch => _pitch;bool get perItem => _perItem;String? get currentItemId => _currentItemId;@@ -105,6 +114,7 @@ class EqualizerService extends ChangeNotifier {_setupSoftwareFallback();}_skipSilenceApplier?.call(_skipSilence);+ _pitchApplier?.call(_pitch);_tapApplier?.call(anyProcessingActive);notifyListeners();}@@ -213,6 +223,22 @@ class EqualizerService extends ChangeNotifier {fn(_skipSilence);}+ /// Shift the voice up or down in semitones without changing the speed.+ /// Android-only; the applier no-ops elsewhere.+ Future<void> setPitch(double semitones) async {+ _pitch = semitones.clamp(minPitch, maxPitch);+ _pitchApplier?.call(_pitch);+ await _saveSettings();+ notifyListeners();+ }++ /// Register the pitch applier. Called once immediately so the player picks+ /// up persisted state on app start.+ void setPitchApplier(void Function(double semitones) fn) {+ _pitchApplier = fn;+ fn(_pitch);+ }+/// Register the iOS processing-tap applier. Called once immediately so the/// engine reflects the current state.void setTapApplier(void Function(bool active) fn) {@@ -240,7 +266,9 @@ class EqualizerService extends ChangeNotifier {_loudnessGain = 0.0;_mono = false;_skipSilence = false;+ _pitch = 0.0;_skipSilenceApplier?.call(_skipSilence);+ _pitchApplier?.call(_pitch);if (_enabled) {_applyCurrentSettings();} else {@@ -328,6 +356,7 @@ class EqualizerService extends ChangeNotifier {_currentItemId = itemId;await _loadItemSettings(itemId);_skipSilenceApplier?.call(_skipSilence);+ _pitchApplier?.call(_pitch);if (_enabled) {_applyCurrentSettings();} else {@@ -355,6 +384,7 @@ class EqualizerService extends ChangeNotifier {'loudnessGain': 0.0,'mono': false,'skipSilence': false,+ 'pitch': 0.0,'bands': List<double>.filled(bandCount, 0.0),};}@@ -370,6 +400,7 @@ class EqualizerService extends ChangeNotifier {'loudnessGain': await ScopedPrefs.getDouble(_itemKey('loudnessGain', itemId)) ?? 0.0,'mono': await ScopedPrefs.getBool(_itemKey('mono', itemId)) ?? false,'skipSilence': await ScopedPrefs.getBool(_itemKey('skipSilence', itemId)) ?? false,+ 'pitch': await ScopedPrefs.getDouble(_itemKey('pitch', itemId)) ?? 0.0,'bands': bands,};}@@ -383,6 +414,7 @@ class EqualizerService extends ChangeNotifier {await ScopedPrefs.setDouble(_itemKey('loudnessGain', itemId), s['loudnessGain'] as double);await ScopedPrefs.setBool(_itemKey('mono', itemId), s['mono'] as bool);await ScopedPrefs.setBool(_itemKey('skipSilence', itemId), s['skipSilence'] as bool? ?? false);+ await ScopedPrefs.setDouble(_itemKey('pitch', itemId), s['pitch'] as double? ?? 0.0);final bands = (s['bands'] as List).cast<double>();await ScopedPrefs.setString(_itemKey('bands', itemId), bands.map((l) => l.toStringAsFixed(1)).join(','));}@@ -397,6 +429,7 @@ class EqualizerService extends ChangeNotifier {_loudnessGain = 0.0;_mono = false;_skipSilence = false;+ _pitch = 0.0;_bandLevels = List.filled(_bandLevels.length, 0.0);return;}@@ -407,6 +440,7 @@ class EqualizerService extends ChangeNotifier {_loudnessGain = await ScopedPrefs.getDouble(_itemKey('loudnessGain', itemId)) ?? 0.0;_mono = await ScopedPrefs.getBool(_itemKey('mono', itemId)) ?? false;_skipSilence = await ScopedPrefs.getBool(_itemKey('skipSilence', itemId)) ?? false;+ _pitch = await ScopedPrefs.getDouble(_itemKey('pitch', itemId)) ?? 0.0;final bandStr = await ScopedPrefs.getString(_itemKey('bands', itemId));if (bandStr != null) {_bandLevels = bandStr.split(',').map((s) => double.tryParse(s) ?? 0.0).toList();@@ -423,6 +457,7 @@ class EqualizerService extends ChangeNotifier {await ScopedPrefs.setDouble(_itemKey('loudnessGain', itemId), _loudnessGain);await ScopedPrefs.setBool(_itemKey('mono', itemId), _mono);await ScopedPrefs.setBool(_itemKey('skipSilence', itemId), _skipSilence);+ await ScopedPrefs.setDouble(_itemKey('pitch', itemId), _pitch);await ScopedPrefs.setString(_itemKey('bands', itemId), _bandLevels.map((l) => l.toStringAsFixed(1)).join(','));}@@ -435,6 +470,7 @@ class EqualizerService extends ChangeNotifier {_loudnessGain = await ScopedPrefs.getDouble('eq_loudnessGain') ?? 0.0;_mono = await ScopedPrefs.getBool('eq_mono') ?? false;_skipSilence = await ScopedPrefs.getBool('eq_skipSilence') ?? false;+ _pitch = await ScopedPrefs.getDouble('eq_pitch') ?? 0.0;final bandStr = await ScopedPrefs.getString('eq_bands');if (bandStr != null) {@@ -453,6 +489,7 @@ class EqualizerService extends ChangeNotifier {await _loadSettings();_currentItemId = null;_skipSilenceApplier?.call(_skipSilence);+ _pitchApplier?.call(_pitch);if (_enabled) {await _applyCurrentSettings();} else {@@ -470,6 +507,7 @@ class EqualizerService extends ChangeNotifier {await ScopedPrefs.setDouble('eq_loudnessGain', _loudnessGain);await ScopedPrefs.setBool('eq_mono', _mono);await ScopedPrefs.setBool('eq_skipSilence', _skipSilence);+ await ScopedPrefs.setDouble('eq_pitch', _pitch);await ScopedPrefs.setString('eq_bands', _bandLevels.map((l) => l.toStringAsFixed(1)).join(','));if (_perItem && _currentItemId != null) {await _saveItemSettings(_currentItemId!);diff --git a/lib/widgets/equalizer_sheet.dart b/lib/widgets/equalizer_sheet.dartindex 96ca4adb..4b053dd4 100644--- a/lib/widgets/equalizer_sheet.dart+++ b/lib/widgets/equalizer_sheet.dart@@ -55,7 +55,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {bool _pEnabled = false;String _pPreset = 'flat';List<double> _pBands = [];- double _pBass = 0.0, _pVirt = 0.0, _pLoud = 0.0;+ double _pBass = 0.0, _pVirt = 0.0, _pLoud = 0.0, _pPitch = 0.0;bool _pMono = false;bool _pSkipSilence = false;@@ -94,6 +94,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {_pBass = 0.0;_pVirt = 0.0;_pLoud = 0.0;+ _pPitch = 0.0;_pMono = false;_pSkipSilence = false;_loadPreview();@@ -113,6 +114,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {_pBass = snap['bassBoost'] as double;_pVirt = snap['virtualizer'] as double;_pLoud = snap['loudnessGain'] as double;+ _pPitch = snap['pitch'] as double? ?? 0.0;_pMono = snap['mono'] as bool;_pSkipSilence = snap['skipSilence'] as bool? ?? false;_pBands = List<double>.from((snap['bands'] as List).cast<double>());@@ -130,6 +132,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {'loudnessGain': _pLoud,'mono': _pMono,'skipSilence': _pSkipSilence,+ 'pitch': _pPitch,'bands': _pBands,});}@@ -141,6 +144,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {double get _vBass => _previewMode ? _pBass : _eq.bassBoost;double get _vVirt => _previewMode ? _pVirt : _eq.virtualizer;double get _vLoud => _previewMode ? _pLoud : _eq.loudnessGain;+ double get _vPitch => _previewMode ? _pPitch : _eq.pitch;bool get _vMono => _previewMode ? _pMono : _eq.mono;bool get _vSkipSilence => _previewMode ? _pSkipSilence : _eq.skipSilence;@@ -210,6 +214,15 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {}}+ void _setPitch(double v) {+ if (_previewMode) {+ setState(() => _pPitch = v.clamp(EqualizerService.minPitch, EqualizerService.maxPitch));+ _savePreview();+ } else {+ _eq.setPitch(v);+ }+ }+void _setMono(bool v) {if (_previewMode) {setState(() => _pMono = v);@@ -236,6 +249,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {_pBass = 0.0;_pVirt = 0.0;_pLoud = 0.0;+ _pPitch = 0.0;_pMono = false;_pSkipSilence = false;});@@ -503,6 +517,16 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {),const SizedBox(height: 8),+ // Pitch (Android only: the iOS player ties pitch to speed)+ if (AppPlatform.isAndroid)+ _PitchRow(+ label: l.pitch,+ value: _vPitch,+ accent: accent,+ onChanged: (v) => _setPitch(v),+ ),+ const SizedBox(height: 8),+// Mono toggleContainer(padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),@@ -663,6 +687,78 @@ class _EQBandSlider extends StatelessWidget {// ── Effect Row with slider ──+/// A centred slider in semitones, so the voice can go lower or higher+/// without the speed changing.+class _PitchRow extends StatelessWidget {+ final String label;+ final double value;+ final Color accent;+ final ValueChanged<double> onChanged;++ const _PitchRow({+ required this.label,+ required this.value,+ required this.accent,+ required this.onChanged,+ });++ @override+ Widget build(BuildContext context) {+ final cs = Theme.of(context).colorScheme;+ final steps = ((EqualizerService.maxPitch - EqualizerService.minPitch) * 2).round();+ final text = value == 0+ ? '0'+ : '${value > 0 ? '+' : ''}${value.toStringAsFixed(value == value.roundToDouble() ? 0 : 1)}';+ return Container(+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),+ decoration: BoxDecoration(+ color: cs.onSurface.withValues(alpha: 0.04),+ borderRadius: BorderRadius.circular(14),+ ),+ child: Row(+ children: [+ Icon(Icons.graphic_eq_rounded, size: 18, color: accent.withValues(alpha: 0.7)),+ const SizedBox(width: 10),+ SizedBox(+ width: 72,+ child: Text(label, style: TextStyle(+ color: cs.onSurface.withValues(alpha: 0.7),+ fontSize: 12, fontWeight: FontWeight.w500)),+ ),+ Expanded(+ child: SliderTheme(+ data: SliderThemeData(+ trackHeight: 3,+ thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 6),+ overlayShape: const RoundSliderOverlayShape(overlayRadius: 12),+ activeTrackColor: accent,+ inactiveTrackColor: cs.onSurface.withValues(alpha: 0.06),+ thumbColor: accent,+ overlayColor: accent.withValues(alpha: 0.15),+ ),+ child: Slider(+ value: value.clamp(EqualizerService.minPitch, EqualizerService.maxPitch),+ min: EqualizerService.minPitch,+ max: EqualizerService.maxPitch,+ divisions: steps,+ onChanged: onChanged,+ ),+ ),+ ),+ SizedBox(+ width: 32,+ child: Text(text,+ textAlign: TextAlign.right,+ style: TextStyle(+ color: cs.onSurfaceVariant,+ fontSize: 11, fontWeight: FontWeight.w600)),+ ),+ ],+ ),+ );+ }+}+class _EffectRow extends StatelessWidget {final IconData icon;final String label;