# LanguageDetector

    class LanguageDetector: NSObject

Predicts the language of an input text.

This API expects a TFLite model with \[TFLite Model Metadata\](https://www.tensorflow.org/lite/convert/metadata")that contains the mandatory (described below) input tensor, output tensor, and the language codes in an AssociatedFile.

Metadata is required for models with int32 input tensors because it contains the input process unit for the model's Tokenizer. No metadata is required for models with string input tensors.

Input tensor - One input tensor (`kTfLiteString`) of shape `[1]` containing the input string.

Output tensor - One output tensor (`kTfLiteFloat32`) of shape `[1 x N]` where `N` is the number of languages.
- `
  ### [init(modelPath:)](https://developers.google.com/edge/api/mediapipe/swift/text/Classes/LanguageDetector.md.txt#/c:objc(cs)MPPLanguageDetector(im)initWithModelPath:error:)

  ` Creates a new instance of `LanguageDetector` from an absolute path to a TensorFlow Lite model file stored locally on the device and the default `LanguageDetectorOptions`.

  #### Declaration

  Swift

      convenience init(modelPath: String) throws

  #### Parameters

  |---|---|
  | `modelPath` | An absolute path to a TensorFlow Lite model file stored locally on the device. |
  | `error` | An optional error parameter populated when there is an error in initializing the language detector. |

  #### Return Value

  A new instance of `LanguageDetector` with the given model path. `nil` if there is an error in initializing the language detector.
- `
  ### [init(options:)](https://developers.google.com/edge/api/mediapipe/swift/text/Classes/LanguageDetector.md.txt#/c:objc(cs)MPPLanguageDetector(im)initWithOptions:error:)

  ` Creates a new instance of `LanguageDetector` from the given `LanguageDetectorOptions`.

  #### Declaration

  Swift

      init(options: LanguageDetectorOptions) throws

  #### Parameters

  |---|---|
  | `options` | The options of type `LanguageDetectorOptions` to use for configuring the `LanguageDetector`. |
  | `error` | An optional error parameter populated when there is an error in initializing the language detector. |

  #### Return Value

  A new instance of `LanguageDetector` with the given options. `nil` if there is an error in initializing the language detector.
- `
  ### [detect(text:)](https://developers.google.com/edge/api/mediapipe/swift/text/Classes/LanguageDetector.md.txt#/c:objc(cs)MPPLanguageDetector(im)detectText:error:)

  ` Predicts the language of the input text.

  #### Declaration

  Swift

      func detect(text: String) throws -> LanguageDetectorResult

  #### Parameters

  |---|---|
  | `text` | The `NSString` for which language is to be predicted. |
  | `error` | An optional error parameter populated when there is an error in performing language prediction on the input text. |

  #### Return Value

  A `LanguageDetectorResult` object that contains a list of language predictions.