Search code examples
swiftmachine-learningaugmented-realitycoremlapple-vision

Which languages are available for text recognition in Vision framework?


I'm trying to add the option to my app to allow for different languages when using Apple's Vision framework for recognising text.

There seems to be a function for programmatically returning the supported languages but I'm not sure if I'm calling it correctly because I'm only getting "en-US" back which I'm fairly sure isn't the only supported language?

Here's what I currently have:

// current revision number of Vision
let revision = VNRecognizeTextRequest.currentRevision
var possibleLanguages: Array<String> = []

do {
    possibleLanguages = try VNRecognizeTextRequest.supportedRecognitionLanguages(for: .accurate, 
                                                                            revision: revision)
} catch {
    print("Error getting the supported languages.")
}

print("Possible languages for revision \(revision):\n(possibleLanguages.joined(separator: "\n"))")

Any help would be much appreciated, thank you.


Solution

  • iOS 15

    In iOS 15 you can call the following instance method that returns the identifiers of the languages that the request (VNRecognizeTextRequest) supports:

    func supportedRecognitionLanguages() throws -> [String]
    

    You can use it this way:

    print(try! request.supportedRecognitionLanguages())
    

    A. Result (if you use .accurate recognitionLevel):

    // ["en-US", "fr-FR", "it-IT", "de-DE", "es-ES", "pt-BR", "zh-Hans", "zh-Hant"]
    

    B. Result (if you use .fast recognitionLevel):

    // ["en-US", "fr-FR", "it-IT", "de-DE", "es-ES", "pt-BR"]
    


    recognitionLanguages property

    You can easily tell Vision framework which languages are needed for text recognition using recognitionLanguages instance property:

    var recognitionLanguages: [String] { get set }
    

    According to Apple documentation: recognitionLanguages defines the order in which languages are used during language processing and text recognition.Specify the languages as ISO language codes.

    A real code may look like this:

    import Vision
    
    let recognizeTextRequest = VNRecognizeTextRequest()
    recognizeTextRequest.minimumTextHeight = 0.05
    recognizeTextRequest.recognitionLevel = .accurate
    
    recognizeTextRequest.recognitionLanguages = ["en-US", "fr-FR", "zh-Hans"]
    

    P.S.

    In the beginning of 2020, Vision supported only English.