3164b7c8df
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.
60 lines
1.6 KiB
Dart
60 lines
1.6 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/chat/speech/speech.dart';
|
|
|
|
void main() {
|
|
test('parses Apple quality and identifier without changing identity', () {
|
|
final voice = SpeechVoice.fromPlatform({
|
|
'name': 'Samantha',
|
|
'locale': 'en-US',
|
|
'quality': 'premium',
|
|
'identifier': 'com.apple.voice.premium.en-US.Samantha',
|
|
});
|
|
|
|
expect(voice.qualityRank, 3);
|
|
expect(voice.isNatural, isTrue);
|
|
expect(voice, const SpeechVoice(name: 'Samantha', locale: 'en-US'));
|
|
});
|
|
|
|
test('parses Android quality and prefers offline on a quality tie', () {
|
|
final online = SpeechVoice.fromPlatform({
|
|
'name': 'English online',
|
|
'locale': 'en-US',
|
|
'quality': 'very high',
|
|
'network_required': '1',
|
|
});
|
|
final offline = SpeechVoice.fromPlatform({
|
|
'name': 'English local',
|
|
'locale': 'en-US',
|
|
'quality': 'very high',
|
|
'network_required': '0',
|
|
});
|
|
|
|
expect(bestSpeechVoice([online, offline], 'en'), offline);
|
|
});
|
|
|
|
test('recognises natural web voice names', () {
|
|
final voice = SpeechVoice.fromPlatform({
|
|
'name': 'Microsoft Aria Online (Natural)',
|
|
'locale': 'en-US',
|
|
});
|
|
|
|
expect(voice.qualityRank, 3);
|
|
expect(voice.isNatural, isTrue);
|
|
});
|
|
|
|
test('picker ranking buries compact novelty voices', () {
|
|
final natural = const SpeechVoice(
|
|
name: 'Samantha Enhanced',
|
|
locale: 'en-US',
|
|
qualityRank: 2,
|
|
);
|
|
final novelty = const SpeechVoice(
|
|
name: 'Zarvox',
|
|
locale: 'en-US',
|
|
qualityRank: 1,
|
|
);
|
|
|
|
expect(compareSpeechVoices(natural, novelty), lessThan(0));
|
|
});
|
|
}
|