A Python3 library for translating text using Google Translate API.
Project description
gpytranslate
A Python3 library for translating text using Google Translate API.
Features
- Both Synchronous and Asynchronous
- Dot accessible values
- Supports emoji
- Type hinted
- Free to use
- Easy
Quick Start
Installation
Requirements:
- Python 3.6 or higher.
$ python3 -m pip install -U gpytranslate
Usage
from gpytranslate import Translator
import asyncio
async def main():
t = Translator()
translation = await t.translate("Ciao come stai? Io bene ahah.", targetlang="en")
language = await t.detect(translation.text)
print(f"Translation: {translation.text}\nDetected language: {language}")
if __name__ == "__main__":
asyncio.run(main())
from gpytranslate import SyncTranslator
t = SyncTranslator()
translation = t.translate("Ciao come stai? Io bene ahah.", targetlang="en")
language = t.detect(translation.text)
print(f"Translation: {translation.text}\nDetected language: {language}")
❓ Note: you could also check tests folder for extra examples.
Output:
Translation: Hello how are you? I'm fine, haha.
Detected language: en
Text to Speech
import asyncio, aiofiles
from gpytranslate import Translator
async def main():
translator = Translator()
async with aiofiles.open("test.mp3", "wb") as file:
await translator.tts("Hello world!", file=file)
if __name__ == "__main__":
asyncio.run(main())
from gpytranslate import SyncTranslator
translator = SyncTranslator()
with open("test.mp3", "wb") as file:
translator.tts("Hello world!", file=file)
Useful Resources
https://danpetrov.xyz/programming/2021/12/30/telegram-google-translate.html https://vielhuber.de/en/blog/google-translation-api-hacking/
Development
Want to contribute? Pull requests are accepted!
License
Licensed under the MIT License.
Click here for further information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file gpytranslate-1.4.0-py3-none-any.whl
.
File metadata
- Download URL: gpytranslate-1.4.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2a7d0673b08e696b2efe66adc192c55a485cd2786c2dff73afcb1eddaf64726 |
|
MD5 | 1d6b659405f97a51dca9d8bcb1b977bb |
|
BLAKE2b-256 | 11c0e35cdb12a9c56fe3cc35b098951910a843de343fb77df177b2d02e457cc1 |