Skip to content

A Python3 library for translating text using Google Translate API.

License

Notifications You must be signed in to change notification settings

simbadmorehod/gpytranslate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Async Example:

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())

Sync Example:

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

Async Example:

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())

Sync Example:

from gpytranslate import SyncTranslator

translator = SyncTranslator()

with open("test.mp3", "wb") as file:
    translator.tts("Hello world!", file=file)

Development

Want to contribute? Pull requests are accepted!


License

Licensed under the MIT License.

Click here for further information.

About

A Python3 library for translating text using Google Translate API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%