Does Speech Framework recognize only English?

I spent a few hours looking for a solution to get all the supported languages in a human-readable form and that's what worked for me. First, create a model for a Language:

struct SupportedLanguage {
    let code: String?
    let name: String?
}

Next run a "for" loop in the SFSpeechRecognizer.supportedLocales(), create SupportedLanguage instances and add them to an array availableLanguages:

var availableLanguages: [SupportedLanguage] = []
for locale in SFSpeechRecognizer.supportedLocales() {
    let language = SupportedLanguage (
        code: locale.languageCode,
        name: Locale.init(identifier: "en").localizedString(forIdentifier: locale.identifier)
    )
    availableLanguages.append(language)
}

And that's it - you have an array of SupportedLanguage instances for every Speech framework supported language. Work's neatly for language selection.


Try this :

SFSpeechRecognizer(locale: Locale.init(identifier: "vi"))

The identifier is the language you want to work with. Language designator examples :

//English : en
//French : fr
//Japanese : ja
//VietNamese : vi

Just run print(SFSpeechRecognizer.supportedLocales()) and you will get

[es-419 (fixed), th-TH (fixed), ca-ES (fixed), fr-BE (fixed), de-CH (fixed), sk-SK (fixed), en-ZA (fixed), es-CL (fixed), hi-IN (fixed), zh-CN (fixed), zh-TW (fixed), da-DK (fixed), hi-IN-translit (fixed), el-GR (fixed), he-IL (fixed), pt-BR (fixed), en-AE (fixed), pt-PT (fixed), fr-CH (fixed), ro-RO (fixed), vi-VN (fixed), en-SA (fixed), pl-PL (fixed), es-US (fixed), hi-Latn (fixed), en-SG (fixed), tr-TR (fixed), hr-HR (fixed), ko-KR (fixed), uk-UA (fixed), it-CH (fixed), ar-SA (fixed), id-ID (fixed), en-IN (fixed), es-ES (fixed), de-AT (fixed), en-IE (fixed), cs-CZ (fixed), es-CO (fixed), zh-HK (fixed), sv-SE (fixed), en-PH (fixed), en-ID (fixed), en-CA (fixed), nl-NL (fixed), yue-CN (fixed), en-NZ (fixed), en-GB (fixed), ja-JP (fixed), it-IT (fixed), ru-RU (fixed), en-US (fixed), ms-MY (fixed), es-MX (fixed), hu-HU (fixed), fr-CA (fixed), wuu-CN (fixed), de-DE (fixed), fr-FR (fixed), fi-FI (fixed), nb-NO (fixed), nl-BE (fixed), en-AU (fixed)]


Does Speech Framework recognize only English?

No it doesn't, as mentioned in the Apple Speech Recognition API Session (02:55):

"iOS 10 supports over 50 languages and dialects ..."

Also, adapted from the Speech Framework Documentation:

The Speech APIs perform speech recognition by communicating with Apple's servers or using an on-device speech recognizer, if available. To find out if a speech recognizer is available for a specific language, you adopt the SFSpeechRecognizerDelegate protocol.

The SFSpeechRecognizerDelegate protocol contains only one optional method:

speechRecognizer(_:availabilityDidChange:):

Tells the delegate when the availability of the speech recognizer has changed.

You could implement -for example- as:

func speechRecognizer(_ speechRecognizer: SFSpeechRecognizer, availabilityDidChange available: Bool) {
    if available {
        // you could display is as enabled in the app
    } else {
        // you could display is as disabled in the app
    }
}

The actual purpose of implementing this method is to trace the availability changing and if speech recognition is available, available would be set as true.