Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell which languages are available for text recognition in Apple's 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.

like image 957
mralexhay Avatar asked Oct 03 '19 13:10

mralexhay


1 Answers

As of iOS 14, VNRecognizeTextRequestRevision2 supports English, French, Italian, German, Spanish, Portuguese, and Chinese (both Simplified and Traditional) in the .accurate recognition level.

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

The .fast recognition level supports English, French, Italian, German, Spanish, and Portuguese.

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

You can check in Playground with this snippet:

try VNRecognizeTextRequest.supportedRecognitionLanguages(for: .fast, revision: 2)
like image 67
Pak Avatar answered Sep 30 '22 21:09

Pak