Search code examples
iosvoiceoverlanguage-detection

iOS voiceOver/accessibility foreign words pronuncation


Some of the texts I assign to accessibilityLabel(s) in my iOS app contain "mixed language".

For example, in German the text would be "Bier und guter Sound". The word "Sound" spoken with German VoiceOver language doesn't make sense (it should say "saund", but sounds like "sund").

Is there a way to give voice over information about a word's language?


Solution

  • Yep, assign an attributed string to the accessibilityLabel (even though it is of type String, it will accept AttributedString), and use UIAccessibilitySpeechAttributeLanguage to set language information for parts of the string that differ from the UI language. E.g. in your case, you would set range (start=15, length=5) to have UIAccessibilitySpeechAttributeLanguage with value "en" (or try "en-US" or "en_US" if that does not work, not sure right now which one it will accept, it should be the BCP 47 language code according to the docs).

    If you are using Swift, then its type safety will not allow you to assign an AttributedString to property accessibilityLabel of type String, you can work around this by using label.setValue(attributedString, forKey: "accessibilityLabel"). A bit of a hack (or workaround), but works.