使用 Aspose.Words for Python via .NET 結合 Google Gemini AI 模型來自動化文件翻譯。將 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 和 EPUB 檔案翻譯成超過 300 種語言,同時保留原始版面配置與格式。AI 引擎會自動偵測來源語言——即使是在多語言文件中——並且只保留無法識別的片段不予翻譯。
驗證需要 Google API 金鑰。如需支援的 AI 模型完整列表,請參閱 API 參考文件。
立即開始在 Python 中翻譯文件——試試上方的即時展示。
pip install aspose-words
複製
doc = aw.Document("Document.docx")
api_key = os.getenv("API_KEY")
# 使用 Google 生成式語言模型。
model = aw.ai.AiModel.create(aw.ai.AiModelType.GEMINI_FLASH_LATEST).with_api_key(api_key)
translated_doc = model.translate(doc, aw.ai.Language.ARABIC)
translated_doc.save("Output.docx")
doc = aw.Document("Document.docx")
# Pass an empty string if the self-hosted model does not require an API key.
model = CustomAiModel("my-model-24b", "https://your-server.com/v1").with_api_key("")
translated_doc = model.translate(doc, aw.ai.Language.ARABIC)
translated_doc.save("Output.docx")
class CustomAiModel(aw.ai.OpenAiModel):
def __init__(self, name, url):
super().__init__(name)
self._url = url
@property
def url(self):
return self._url
我們在PyPi存儲庫中託管我們的 Python 請按照有關如何 "Aspose.Words for Python via .NET" 安裝到您的開發人員環境的分步說明進行操作。
這個包與 Python ≥3.5 和 <3.12 兼容。如果您為 Linux 開發軟件,請查看產品文檔中對 gcc 和 libpython 的附加要求。