Search code examples
iosapispeech

Speech to text in multiple languages (support Persian and Arabic languages)


Does anyone know that in Convert Speech to text in multiple languages API in iOS support Persian and Arabic languages? I use Swift language


Solution

  • You can check that speech recognition is available for a certain locale using the isAvailable property :

    let recognier = SFSpeechRecognizer(locale: Locale(identifier: "fa_IR"))
    
    print(recognier?.isAvailable)   //nil
    

    Sadly it's not available for Farsi.

    But it is available for Arabic and most of its variants :

    let recognier = SFSpeechRecognizer(locale: Locale(identifier: "ar_SA"))
    
    print(recognier?.isAvailable)  //Optional(true)
    

    To get all the supported locales use the type method supportedLocales() :

    print(SFSpeechRecognizer.supportedLocales().sorted {
        $0.description < $1.description
    })
    

    Which outputs :

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