Skip to main content

Gpyts is a library for Google translation and gTTS using Google Translation API.

Project description

Gpyts

Gpyts is a library for Google translation and gTTS using Google Translation (API unofficially).

  • Its fast, easy and has both async/sync version.
  • Supports both Translation and Text to Speech.
  • Option for using both api and web scrap.
  • Allows multiple endpoint configurations and proxy.

Installation

Use the package manager pip to install Gpyts.

pip install Gpyts

Usage Async

from gpyts.asyncGpyts import Gpyts

gpyts = Gpyts()

# Using full translation api. Returns all supported parameters listed.
translation = await gpyts.translate("hey, how are you?", to_lang = 'fr')
print("Text is : " + translation.text)

# Convert Text to Speech.
speech = await gpyts.tts("Fine, What about you?", lang = 'fr', slow = True, download = 'tts.mp3')
print("Saved as :" + speech.file)

Usage Sync

Simply import :

from gpyts.syncGpyts import Gpyts

and remove await(s), thats it!

Gpyts

There are various configurations available (all Optional)

  • tld - Custom tld's you can provide like com or co.uk or a list ['tl', 'com']. (Random choosed if list provided).
  • proxy - Proxy to be used like http://user:pass@ip:port.
  • endpoint - Custom endpoint url to be used. (Random choosed if list provided).
  • client - Custom client to be used.
  • minimal - Make result simply a translated text, default False.
  • labled - Custom return method to be used than default True.
gpyts = Gpyts(tld = ['tl', 'co.uk'], proxy = 'http://user:pass@ip:port')

Note : Provide endpoint, client only if you know valid combination of values. Either use tld or endpoint, it wont work together. Just tld and proxy is required for most part even that is Optional too.

Gpyts.translate

Parameters that could be passed

  • text - Text to be translated.
  • to_lang - Target language code.
  • from_lang (Optional) - Source language code.
  • i_enc (Optional) - Input encoding.
  • o_enc (Optional) - Output encoding.
  • web (Optional) - To use web scrap version.

Translating any text with provided language code to be converted

# Using full translation api. Returns all supported parameters listed.
translation = await gpyts.translate("hey, how are you?", to_lang = 'fr')

print("Text is : " + translation.text)

You can also use web scrap mini version by passing gpyts.translate(..., web = True)

# Using web mini translation (Scrapped). Returns only translated text.
translation = await gpyts.translate("hey, how are you?", to_lang = 'fr', web = True)
print("Text is : " + translation.text)

Result Translation object may contain attributes

  • src - Detected source language code.
  • text - Translated text.
  • origin - Original text.
  • translit - Transliteration if available.
  • alternative - Alternative translation list.
  • confidence - Confidence value of translation.

Gpyts.tts

Parameters that could be passed

  • text - Text to be converted.
  • lang - Target language code.
  • slow - Slow down the speech speed. Default False.
  • i_enc (Optional) - Input encoding.
  • download(Optional) - Could be either a file path or BytesIO object. Default creates text2speech.mp3 file.

Convert given text to speech

# Same folder as default text2speech.mp3
text2speech = await gpyts.tts("hey, how are you?", lang = 'ja')
print("Saved as : " + translation.file) 

# Different folder (creates if not exists) as default text2speech.mp3
text2speech = await gpyts.tts("hey, how are you?", lang = 'ja', download = './saves/tts/')
print("Saved as : " + translation.file) 

# Custom name
text2speech = await gpyts.tts("hey, how are you?", lang = 'ja', download = './tts.mp3')
print("Saved as : " + translation.file)

You can also provide a BytesIO buffer object

# Create a ByteIO buffer
from io import BytesIO
buffer = BytesIO()
text2speech = await gpyts.tts("hey, how are you?", lang = 'ja', download = buffer)

# ... Later save it
with open('text2speech.mp3', 'wb') as file:
    file.write(text2speech.file)

Result TextToSpeech object may contain attributes

  • lang - Language to which it was converted.
  • text - Provided original text.
  • file - File path where it was saved or BytesIO buffer.

Gpyts.iso

Return lists of language iso code for both gts and tts.

lang = await gpyts.iso()
print('All supported transaltion iso code ', ' '.join(lang['gts']))
print('All supported text2speech iso code ', ' '.join(lang['tts']))

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Gpyts-1.0.3.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Gpyts-1.0.3-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file Gpyts-1.0.3.tar.gz.

File metadata

  • Download URL: Gpyts-1.0.3.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.2

File hashes

Hashes for Gpyts-1.0.3.tar.gz
Algorithm Hash digest
SHA256 07e61b013f9577b3349f5584eda7fcf608f3938130c1a309abef70a26fb7fc38
MD5 3a16e104524fb271293775ddda15d9fd
BLAKE2b-256 f31daef9d04f2546984f405f2d60393bc0f925b86f74605d5eefb990a107a444

See more details on using hashes here.

File details

Details for the file Gpyts-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: Gpyts-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.2

File hashes

Hashes for Gpyts-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9d027f7f1923abe5bcb6788b9df9f023657b819d0a226ab99cf375f7ba3a04e5
MD5 1dcef2ba06d765bee41073d9db89f664
BLAKE2b-256 183681d503e61bcec8913cde7f0890a72711869478e498013c00837c32a2ee29

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page