0

I am aware that it is probably grouped with some other similar entities into some enum. But searching Google, searching assemblies returned no answers. So, where is NSVoiceLocaleIdentifier on Xamarin.Mac?

Ivan Ičin
  • 9,672
  • 5
  • 36
  • 57

1 Answers1

2

Note: There are "no" defined constants for compile time validation as the NSVoiceLocaleIdentifier strings are dynamic based upon your OS install. If you want a complete list, you have to look them up at application runtime.

NSVoice​Locale​Identifier is available within the NSDictionary that is returned for a particular voice.

No Serbian (sv_SV) on my system, but there are 64 others...

i.e.

  • com.apple.speech.synthesis.voice.Zarvox is USA English based (en_US)
  • com.apple.speech.synthesis.voice.thomas is French (fr-FR)

Example:

foreach (var voice in NSSpeechSynthesizer.AvailableVoices)
{
    Console.WriteLine(voice);
    var attributes = NSSpeechSynthesizer.AttributesForVoice(voice);
    foreach (var item in attributes)
    {
        if (item.Key.ToString() == "VoiceIndividuallySpokenCharacters" ||
            item.Key.ToString() == "VoiceSupportedCharacters")
            continue;
        Console.WriteLine($"\t{item.Key}:{item.Value}");
    }
    Console.WriteLine();
}

Example Output:

com.apple.speech.synthesis.voice.Zarvox
    VoiceShowInFullListOnly:1
    VoiceGender:VoiceGenderNeuter
    VoiceIdentifier:com.apple.speech.synthesis.voice.Zarvox
    VoiceVersion:3.6
    VoiceDemoText:That looks like a peaceful planet.
    VoiceLanguage:en-US
    VoiceAge:1
    VoiceName:Zarvox
    VoiceLocaleIdentifier:en_US

com.apple.speech.synthesis.voice.thomas
    VoiceName:Thomas
    VoiceGroup:VoiceGroupCompact
    VoiceLocaleIdentifier:fr_FR
    VoiceShowInFullListOnly:0
    VoiceDemoText:Bonjour, je m’appelle Thomas. Je suis une voix française.
    VoiceGender:VoiceGenderMale
    VoiceNumericID:251973347
    VoiceAge:35
    VoiceIdentifier:com.apple.speech.synthesis.voice.thomas
    VoiceVersion:5.0.7
    VoiceNameRoot:Thomas
    VoiceSynthesizerNumericID:1886745202
    VoiceRelativeDesirability:3800
    VoiceLanguage:fr-FR
SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • Thanks, I was aware of that however I would avoid using strings instead of system defined constants if possible. – Ivan Ičin Mar 28 '17 at 14:28
  • @IvanIčin There are "no" defined constants for compile time validation as the `NSVoiceLocaleIdentifier` *strings* are dynamic based upon your OS install. If you want a complete list, you have to look them up at application runtime... – SushiHangover Mar 28 '17 at 14:30
  • if the last thing you say is true then basically it means you can't use NSSpeechSynthesizer in in Xamarin, unless the user picks up the voice among installed voices. It is not required in Xcode as you can use NSVoiceLocaleIdentifier as API, as far as I understand Xamarin missed this API? I am aware that they include many such keys on Xamarin.iOS as enums. – Ivan Ičin Mar 28 '17 at 20:16
  • Also thanks for trying to find the language for my locale, that was kind. It is 'rs-RS' though :). And I am not using that for my language, I have an app on several platform that uses this feature... – Ivan Ičin Mar 28 '17 at 20:18
  • @IvanIčin If you are looking for the user's default defined value (via Speech Preferences), use `NSSpeechSynthesizer.DefaultVoice` and then access the attributes of the voice via `NSSpeechSynthesizer.AttributesForVoice` and you can obtain the `VoiceLocaleIdentifier` – SushiHangover Mar 28 '17 at 20:34
  • @IvanIčin ? I think you misunderstand what `NSVoiceLocaleIdentifier` is, in Obj-C (or Swift) it is `APPKIT_EXTERN NSString * const NSVoiceLocaleIdentifier;` you can look it up in **`NSSpeechSynthesizer.h`**, thus there is no missing API, it is not a predefined set of values (`enum`). – SushiHangover Mar 28 '17 at 20:39
  • `APPKIT_EXTERN` is a macro for Obj-C/Swift for `extern` and is use to type check (*spellcheck* in Xcode terms) the fact that when you use `NSVoiceLocaleIdentifier` it is validated to an `NSString`. Xamarin auto-converts those `NSDictionary` NSString attributes to string... so you are not missing anything. – SushiHangover Mar 28 '17 at 20:44
  • I did misunderstood your comment (as you said that NSVoiceLocaleIdentifier strings are dynamically generated, which sounds like that it has possible string keys (not values) that can be dynamically generated. I didn't misunderstand the way it works because I wouldn't assume something like that (quite the opposite), I've just read the comment probably missed some hints in it. OK, then going back to my first comment... and also adding that I am not sure what a compiler generates, e.g. whether that use of the string can be considered as the use of the private API in the Mac App Store... – Ivan Ičin Mar 28 '17 at 21:53