Essentials
Essentials copied to clipboard
[Bug] TextToSpeech issue when selecting a specific voice
Description
TextToSpeech doesnt allow to select a specific voices for IOS and Android
var locales = await TextToSpeech.GetLocalesAsync(); locale = locales.FirstOrDefault(w => w.Name.ToUpper().Contains("LEE"));
This code return the correct locale but this is not the one played but the default voice for the same language (in this case English)
Steps to Reproduce
- Download the "Lee" voice on iOS
- Run the below code
Expected Behavior
Actual Behavior
"Karen" is played instead of Lee
Basic Information
- Version with issue: Xamarin Form 5.0.0.2012 , Xamarin.Essentials 1.7.0
Looking at the source code, I suspect the issue comes from the following method in class TextToSpeech.ios.tvos.watchos.cs :
static AVSpeechUtterance GetSpeechUtterance(string text, SpeechOptions options)
{
var speechUtterance = new AVSpeechUtterance(text);
if (options != null)
{
// null voice if fine - it is the default
speechUtterance.Voice =
AVSpeechSynthesisVoice.FromLanguage(options.Locale?.Language)_ ??
//Should be replaced by the following method
**AVSpeechSynthesisVoice.FromIdentifier(options.Locale?.Id)??**
AVSpeechSynthesisVoice.FromLanguage(AVSpeechSynthesisVoice.CurrentLanguageCode);
// the platform has a range of 0.5 - 2.0
// anything lower than 0.5 is set to 0.5
if (options.Pitch.HasValue)
speechUtterance.PitchMultiplier = options.Pitch.Value;
if (options.Volume.HasValue)
speechUtterance.Volume = options.Volume.Value;
}
return speechUtterance;
}
Reproduction Link
so it always runs the default voice? in my case, it doesnt work like that.
i was filtering locales by language code. On my Iphone 54 locales are returned by var crossLocales = await TextToSpeech.GetLocalesAsync(); query. If i get the first english locale, it is usually the one with en-AU and since i dont have any default or downloaded for AU, it doesnt even work. Country property is always returned null