mp.tasks.text.LanguageDetector
Class that predicts the language of an input text.
mp.tasks.text.LanguageDetector(
lib: mp.tasks.vision.drawing_styles.face_landmarker.serial_dispatcher.SerialDispatcher,
handle: ctypes.c_void_p
)
This API expects a TFLite model with TFLite Model Metadata that contains the
mandatory (described below) input tensors, output tensor, and the language
codes in an AssociatedFile.
|
(kTfLiteString)
- 1 input tensor that is scalar or has shape [1] containing the input
string.
|
Output tensor |
(kTfLiteFloat32)
- 1 output tensor of shape
[1 x N] where N is the number of languages.
|
Methods
close
View source
close()
Shuts down the MediaPipe task instance.
create_from_model_path
View source
@classmethod
create_from_model_path(
model_path: str
) -> 'LanguageDetector'
Creates an LanguageDetector object from a TensorFlow Lite model and the default LanguageDetectorOptions.
| Args |
model_path
|
Path to the model.
|
| Returns |
LanguageDetector object that's created from the model file and the
default LanguageDetectorOptions.
|
| Raises |
ValueError
|
If failed to create LanguageDetector object from the
provided
file such as invalid file path.
|
RuntimeError
|
If other types of error occurred.
|
create_from_options
View source
@classmethod
create_from_options(
options: mp.tasks.text.LanguageDetectorOptions
) -> 'LanguageDetector'
Creates the LanguageDetector object from language detector options.
| Args |
options
|
Options for the language detector task.
|
| Returns |
LanguageDetector object that's created from options.
|
| Raises |
ValueError
|
If failed to create LanguageDetector object from
LanguageDetectorOptions such as missing the model.
|
RuntimeError
|
If other types of error occurred.
|
detect
View source
detect(
text: str
) -> mp.tasks.text.LanguageDetectorResult
Predicts the language of the input text.
| Args |
text
|
The input text.
|
| Returns |
A LanguageDetectorResult object that contains a list of languages and
scores.
|
| Raises |
ValueError
|
If any of the input arguments is invalid.
|
RuntimeError
|
If language detection failed to run.
|
__enter__
View source
__enter__()
Returns self upon entering the runtime context.
__exit__
View source
__exit__(
unused_exc_type, unused_exc_value, unused_traceback
)
Shuts down the MediaPipe task instance on exit of the context manager.
| Raises |
RuntimeError
|
If the MediaPipe LanguageDetector task failed to close.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-06-05 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-06-05 UTC."],[],[]]