Tencent Cloud Machine Translation (TMT) SDK for Python providing comprehensive text, file, image, and speech translation capabilities
A comprehensive Python SDK for Tencent Cloud's Machine Translation (TMT) service, providing enterprise-grade translation capabilities across text, files, images, and speech. The SDK supports multiple language pairs, various content formats, and both synchronous and asynchronous translation workflows.
pip install tencentcloud-sdk-pythonfrom tencentcloud.tmt.v20180321.tmt_client import TmtClient
from tencentcloud.tmt.v20180321 import modelsCommon credential and configuration imports:
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfilefrom tencentcloud.common import credential
from tencentcloud.tmt.v20180321.tmt_client import TmtClient
from tencentcloud.tmt.v20180321 import models
# Initialize credentials and client
cred = credential.Credential("SecretId", "SecretKey")
client = TmtClient(cred, "ap-beijing")
# Basic text translation
req = models.TextTranslateRequest()
req.SourceText = "Hello, world!"
req.Source = "en"
req.Target = "zh"
resp = client.TextTranslate(req)
print(resp.TargetText) # 你好,世界!The TMT SDK follows Tencent Cloud's standard architecture pattern:
The SDK supports multiple translation modes (synchronous/asynchronous), extensive language combinations, and various content types through a unified client interface.
Core text translation functionality supporting 20+ languages with automatic language detection, batch processing, and customizable translation parameters.
def TextTranslate(self, request: models.TextTranslateRequest) -> models.TextTranslateResponse: ...
def TextTranslateBatch(self, request: models.TextTranslateBatchRequest) -> models.TextTranslateBatchResponse: ...
def LanguageDetect(self, request: models.LanguageDetectRequest) -> models.LanguageDetectResponse: ...Document translation supporting multiple formats (PDF, DOCX, PPTX, XLSX, TXT, XML, HTML, Markdown, Properties) with asynchronous processing and progress tracking.
def FileTranslate(self, request: models.FileTranslateRequest) -> models.FileTranslateResponse: ...
def GetFileTranslate(self, request: models.GetFileTranslateRequest) -> models.GetFileTranslateResponse: ...OCR-based image translation for 13-18 languages with support for document scanning, line-by-line translation, and enhanced LLM-powered processing.
def ImageTranslate(self, request: models.ImageTranslateRequest) -> models.ImageTranslateResponse: ...
def ImageTranslateLLM(self, request: models.ImageTranslateLLMRequest) -> models.ImageTranslateLLMResponse: ...Audio translation combining speech recognition and translation for Chinese-English bidirectional processing, supporting streaming and batch modes.
def SpeechTranslate(self, request: models.SpeechTranslateRequest) -> models.SpeechTranslateResponse: ...# Major supported languages (varies by capability)
zh = "zh" # Simplified Chinese
zh_TW = "zh-TW" # Traditional Chinese
zh_HK = "zh-HK" # Traditional Chinese (Hong Kong)
zh_TR = "zh-TR" # Traditional Chinese (Traditional)
en = "en" # English
ja = "ja" # Japanese
ko = "ko" # Korean
fr = "fr" # French
de = "de" # German
es = "es" # Spanish
it = "it" # Italian
pt = "pt" # Portuguese
ru = "ru" # Russian
ar = "ar" # Arabic
tr = "tr" # Turkish
vi = "vi" # Vietnamese
th = "th" # Thai
ms = "ms" # Malay
id = "id" # Indonesian
hi = "hi" # Hindifrom tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
try:
response = client.TextTranslate(request)
except TencentCloudSDKException as e:
error_code = e.code
error_message = e.messageCommon error codes include service limits, authentication failures, unsupported languages, and quota exhaustion. See the Error Codes Reference for complete details.
Install with Tessl CLI
npx tessl i tessl/pypi-tencentcloud-sdk-python-tmt@3.0.1