Prefer natural voices for read aloud
Rank platform voice quality and select the most natural automatic voice while keeping explicit voice choices intact. Surface natural labels, hide novelty voices in the picker, and guide Apple users to download enhanced voices when needed.
This commit is contained in:
@@ -9,15 +9,31 @@ import 'package:pipelines_app/features/chat/speech/speech.dart';
|
||||
void installSpeechFixture(Map<String, String> params) {
|
||||
if (params['speech'] != 'fake') return;
|
||||
final step = int.tryParse(params['speechStep'] ?? '') ?? 600;
|
||||
final hint = params['speechHint'] == '1';
|
||||
final empty = params['speechEmpty'] == '1';
|
||||
final failure = params['speechFailure'] == '1';
|
||||
debugSpeechController = SpeechController(
|
||||
engine: _ScriptedSpeechEngine(Duration(milliseconds: step)),
|
||||
engine: _ScriptedSpeechEngine(
|
||||
Duration(milliseconds: step),
|
||||
appleHint: hint,
|
||||
empty: empty,
|
||||
failure: failure,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _ScriptedSpeechEngine extends SpeechEngine {
|
||||
_ScriptedSpeechEngine(this.step);
|
||||
_ScriptedSpeechEngine(
|
||||
this.step, {
|
||||
this.appleHint = false,
|
||||
this.empty = false,
|
||||
this.failure = false,
|
||||
});
|
||||
|
||||
final Duration step;
|
||||
final bool appleHint;
|
||||
final bool empty;
|
||||
final bool failure;
|
||||
Timer? _timer;
|
||||
String _text = '';
|
||||
List<Match> _words = const [];
|
||||
@@ -27,6 +43,9 @@ class _ScriptedSpeechEngine extends SpeechEngine {
|
||||
@override
|
||||
bool get supported => true;
|
||||
|
||||
@override
|
||||
bool get supportsVoiceDownloadHint => appleHint;
|
||||
|
||||
@override
|
||||
Future<void> speak(String text) async {
|
||||
if (_paused && text == _text) {
|
||||
@@ -81,12 +100,32 @@ class _ScriptedSpeechEngine extends SpeechEngine {
|
||||
Future<void> setVoice(SpeechVoice? voice) async {}
|
||||
|
||||
@override
|
||||
Future<List<SpeechVoice>> voices() async => const [
|
||||
SpeechVoice(name: 'Samantha', locale: 'en-US'),
|
||||
SpeechVoice(name: 'Daniel', locale: 'en-GB'),
|
||||
SpeechVoice(name: 'Karen', locale: 'en-AU'),
|
||||
SpeechVoice(name: 'Thomas', locale: 'fr-FR'),
|
||||
SpeechVoice(name: 'Anna', locale: 'de-DE'),
|
||||
SpeechVoice(name: 'Kyoko', locale: 'ja-JP'),
|
||||
];
|
||||
Future<List<SpeechVoice>> voices() async {
|
||||
if (failure) throw StateError('fixture voice inventory failed');
|
||||
if (empty) return const [];
|
||||
return [
|
||||
const SpeechVoice(
|
||||
name: 'Samantha Compact',
|
||||
locale: 'en-US',
|
||||
qualityRank: 1,
|
||||
),
|
||||
if (!appleHint)
|
||||
const SpeechVoice(
|
||||
name: 'Samantha Enhanced',
|
||||
locale: 'en-US',
|
||||
qualityRank: 2,
|
||||
),
|
||||
if (!appleHint)
|
||||
const SpeechVoice(
|
||||
name: 'Microsoft Aria Online (Natural)',
|
||||
locale: 'en-US',
|
||||
qualityRank: 3,
|
||||
),
|
||||
const SpeechVoice(name: 'Bells', locale: 'en-US', qualityRank: 1),
|
||||
const SpeechVoice(name: 'Daniel', locale: 'en-GB', qualityRank: 1),
|
||||
const SpeechVoice(name: 'Thomas', locale: 'fr-FR', qualityRank: 1),
|
||||
const SpeechVoice(name: 'Anna', locale: 'de-DE', qualityRank: 1),
|
||||
const SpeechVoice(name: 'Kyoko', locale: 'ja-JP', qualityRank: 1),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user