0
# Tencent Cloud Machine Translation SDK
1
2
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.
3
4
## Package Information
5
6
- **Package Name**: tencentcloud-sdk-python-tmt
7
- **Language**: Python
8
- **Installation**: `pip install tencentcloud-sdk-python`
9
10
## Core Imports
11
12
```python
13
from tencentcloud.tmt.v20180321.tmt_client import TmtClient
14
from tencentcloud.tmt.v20180321 import models
15
```
16
17
Common credential and configuration imports:
18
19
```python
20
from tencentcloud.common import credential
21
from tencentcloud.common.profile.client_profile import ClientProfile
22
from tencentcloud.common.profile.http_profile import HttpProfile
23
```
24
25
## Basic Usage
26
27
```python
28
from tencentcloud.common import credential
29
from tencentcloud.tmt.v20180321.tmt_client import TmtClient
30
from tencentcloud.tmt.v20180321 import models
31
32
# Initialize credentials and client
33
cred = credential.Credential("SecretId", "SecretKey")
34
client = TmtClient(cred, "ap-beijing")
35
36
# Basic text translation
37
req = models.TextTranslateRequest()
38
req.SourceText = "Hello, world!"
39
req.Source = "en"
40
req.Target = "zh"
41
42
resp = client.TextTranslate(req)
43
print(resp.TargetText) # 你好,世界!
44
```
45
46
## Architecture
47
48
The TMT SDK follows Tencent Cloud's standard architecture pattern:
49
50
- **TmtClient**: Main service client handling API calls and authentication
51
- **Request Models**: Strongly-typed parameter objects for each API operation
52
- **Response Models**: Structured response objects with result data and metadata
53
- **Error Handling**: Comprehensive error codes and exception handling via TencentCloudSDKException
54
55
The SDK supports multiple translation modes (synchronous/asynchronous), extensive language combinations, and various content types through a unified client interface.
56
57
## Capabilities
58
59
### Text Translation
60
61
Core text translation functionality supporting 20+ languages with automatic language detection, batch processing, and customizable translation parameters.
62
63
```python { .api }
64
def TextTranslate(self, request: models.TextTranslateRequest) -> models.TextTranslateResponse: ...
65
def TextTranslateBatch(self, request: models.TextTranslateBatchRequest) -> models.TextTranslateBatchResponse: ...
66
def LanguageDetect(self, request: models.LanguageDetectRequest) -> models.LanguageDetectResponse: ...
67
```
68
69
[Text Translation](./text-translation.md)
70
71
### File Translation
72
73
Document translation supporting multiple formats (PDF, DOCX, PPTX, XLSX, TXT, XML, HTML, Markdown, Properties) with asynchronous processing and progress tracking.
74
75
```python { .api }
76
def FileTranslate(self, request: models.FileTranslateRequest) -> models.FileTranslateResponse: ...
77
def GetFileTranslate(self, request: models.GetFileTranslateRequest) -> models.GetFileTranslateResponse: ...
78
```
79
80
[File Translation](./file-translation.md)
81
82
### Image Translation
83
84
OCR-based image translation for 13-18 languages with support for document scanning, line-by-line translation, and enhanced LLM-powered processing.
85
86
```python { .api }
87
def ImageTranslate(self, request: models.ImageTranslateRequest) -> models.ImageTranslateResponse: ...
88
def ImageTranslateLLM(self, request: models.ImageTranslateLLMRequest) -> models.ImageTranslateLLMResponse: ...
89
```
90
91
[Image Translation](./image-translation.md)
92
93
### Speech Translation
94
95
Audio translation combining speech recognition and translation for Chinese-English bidirectional processing, supporting streaming and batch modes.
96
97
```python { .api }
98
def SpeechTranslate(self, request: models.SpeechTranslateRequest) -> models.SpeechTranslateResponse: ...
99
```
100
101
[Speech Translation](./speech-translation.md)
102
103
## Common Types
104
105
### Language Codes
106
107
```python { .api }
108
# Major supported languages (varies by capability)
109
zh = "zh" # Simplified Chinese
110
zh_TW = "zh-TW" # Traditional Chinese
111
zh_HK = "zh-HK" # Traditional Chinese (Hong Kong)
112
zh_TR = "zh-TR" # Traditional Chinese (Traditional)
113
en = "en" # English
114
ja = "ja" # Japanese
115
ko = "ko" # Korean
116
fr = "fr" # French
117
de = "de" # German
118
es = "es" # Spanish
119
it = "it" # Italian
120
pt = "pt" # Portuguese
121
ru = "ru" # Russian
122
ar = "ar" # Arabic
123
tr = "tr" # Turkish
124
vi = "vi" # Vietnamese
125
th = "th" # Thai
126
ms = "ms" # Malay
127
id = "id" # Indonesian
128
hi = "hi" # Hindi
129
```
130
131
### Error Handling
132
133
```python { .api }
134
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
135
136
try:
137
response = client.TextTranslate(request)
138
except TencentCloudSDKException as e:
139
error_code = e.code
140
error_message = e.message
141
```
142
143
Common error codes include service limits, authentication failures, unsupported languages, and quota exhaustion. See the [Error Codes Reference](https://cloud.tencent.com/document/product/551/15619) for complete details.