trengine package

Submodules

trengine.exceptions module

exception trengine.exceptions.ApiException[source]

Bases: Exception

trengine.google module

class trengine.google.AsyncGoogleTranslator[source]

Bases: object

async static translate(text: str, to_language: str = 'en', source_language: str = 'auto') GoogleTranslateResult[source]

Translate a text using google engine.

Parameters:
  • text (str) – the text to translate.

  • to_language (str, optional) – The lang code of target lang. Defaults to “en”.

  • source_language (str, optional) – Source lang of the text. Defaults to “auto”.

class trengine.google.GoogleTranslator[source]

Bases: object

static translate(text: str, to_language: str = 'en', source_language: str = 'auto') GoogleTranslateResult[source]

Translate a text using google engine.

Parameters:
  • text (str) – the text to translate.

  • to_language (str, optional) – The lang code of target lang. Defaults to “en”.

  • source_language (str, optional) – Source lang of the text. Defaults to “auto”.

trengine.hozory module

class trengine.hozory.AsyncHozoryTranslator[source]

Bases: object

async static translate(text: str, target: str = 'en') HozoryTranslateResult[source]

Translate a text using hozory engine.

Parameters:
  • text (str) – the text to translate.

  • target (str, optional) – The lang code of target lang. Defaults to “en”.

class trengine.hozory.HozoryTranslator[source]

Bases: object

static translate(text: str, target: str = 'en') HozoryTranslateResult[source]

Translate a text using hozory engine.

Parameters:
  • text (str) – the text to translate.

  • target (str, optional) – The lang code of target lang. Defaults to “en”.

trengine.identify_music module

class trengine.identify_music.AsyncIdentifyMusic[source]

Bases: object

async static identify(file_path: str) IdentifyMusicResult[source]

Identify music using shazam.

Parameters:

file_path (str) – The path to the audio file to be identified. This should be a valid path to an audio file

class trengine.identify_music.IdentifyMusic[source]

Bases: object

static identify(file_path: str) IdentifyMusicResult[source]

Identify music using shazam.

Parameters:

file_path (str) – The path to the audio file to be identified. This should be a valid path to an audio file

trengine.ocr module

class trengine.ocr.AsyncOCR[source]

Bases: object

async static from_image(path: str, language: str = 'eng') str[source]
class trengine.ocr.OCR[source]

Bases: object

static from_image(path: str, language: str = 'eng') str[source]

trengine.speech_to_text module

class trengine.speech_to_text.AsyncSpeechToText[source]

Bases: object

async static to_text(file_path: str, language: str = 'en') SpeechToTextResult[source]

Speech to text using google cloud.

Parameters:
  • file_path (str) – The path to the audio file to be transcribed into text. This should be a valid path to an audio file

  • language (str, optional) – the source language code of the audio file. Defaults to “en”. Supported languages are: en, ar

class trengine.speech_to_text.SpeechToText[source]

Bases: object

static to_text(file_path: str, language: str = 'en') SpeechToTextResult[source]

Speech to text using google cloud.

Parameters:
  • file_path (str) – The path to the audio file to be transcribed into text. This should be a valid path to an audio file

  • language (str, optional) – the source language code of the audio file. Defaults to “en”. Supported languages are: en, ar

trengine.tdict module

class trengine.tdict.AsyncTdictTranslator[source]

Bases: object

async static translate(text: str, to_language: str = 'en') str[source]

Translate a text using tdict engine.

Parameters:
  • text (str) – the text to translate.

  • to_language (str, optional) – The lang code of target lang. Defaults to “en”.

class trengine.tdict.TdictTranslator[source]

Bases: object

static translate(text: str, to_language: str = 'en') str[source]

Translate a text using tdict engine.

Parameters:
  • text (str) – the text to translate.

  • to_language (str, optional) – The lang code of target lang. Defaults to “en”.

trengine.text_to_speech module

class trengine.text_to_speech.AsyncTextToSpeech[source]

Bases: object

async static to_speech(text: str, output_path: str, language: str = 'en') TextToSpeechResult[source]

Text to speech using google translate.

Parameters:
  • text (str) – The text to be converted into speech

  • language (str, optional) – the source language code of the text. Defaults to “en”.

  • out_put_path (str) – The path to save the output audio file

class trengine.text_to_speech.TextToSpeech[source]

Bases: object

static to_speech(text: str, output_path: str, language: str = 'en') TextToSpeechResult[source]

Text to speech using google translate.

Parameters:
  • text (str) – The text to be converted into speech

  • language (str, optional) – the source language code of the text. Defaults to “en”.

  • out_put_path (str) – The path to save the output audio file

trengine.tr module

class trengine.tr.AsyncTranslator[source]

Bases: object

async static detect(text: str) str[source]

Detect language code from text.

Parameters:

text (str) – The text.

async static translate(text: str, translated_lang: str = 'en', source_lang: str | None = None) AjaxTranslateResult[source]

Translate a text using tr engine.

Parameters:
  • text (str) – the text to translate.

  • translated_lang (str, optional) – The lang code of target lang. Defaults to “en”.

  • source_lang (str, optional) – Source lang of the text. Defaults to None.

class trengine.tr.Translator[source]

Bases: object

static detect(text: str) str[source]

Detect language code from text.

Parameters:

text (str) – The text.

static translate(text: str, translated_lang: str = 'en', source_lang: str | None = None) AjaxTranslateResult[source]

Translate a text using tr engine.

Parameters:
  • text (str) – the text to translate.

  • translated_lang (str, optional) – The lang code of target lang. Defaults to “en”.

  • source_lang (str, optional) – Source lang of the text. Defaults to None.

trengine.types module

class trengine.types.AjaxTranslateResult(original_text: str, translated_text: str, translation_language: str, original_language: str)[source]

Bases: Base

original_language: str
original_text: str
static parse(d: dict, org: str) AjaxTranslateResult[source]
translated_text: str
translation_language: str
class trengine.types.Base[source]

Bases: object

static default(obj: Base)[source]
class trengine.types.GoogleTranslateResult(translated_text: str, original_language: str, dest_language: str)[source]

Bases: Base

dest_language: str
original_language: str
static parse(d: list, dest: str, source: str | None = None) GoogleTranslateResult[source]
translated_text: str
class trengine.types.HozoryTranslateResult(translated_text: str, translation_language: str, voice_link: str)[source]

Bases: Base

static parse(d: dict, dest: str) HozoryTranslateResult[source]
translated_text: str
translation_language: str
class trengine.types.IdentifyMusicResult(status: bool, file_path: str, tracks: list)[source]

Bases: Base

file_path: str
static parse(d: dict, p: str) IdentifyMusicResult[source]
status: bool
tracks: list
class trengine.types.SpeechToTextResult(status: bool, file_path: str, speech_text: str, language: str)[source]

Bases: Base

file_path: str
language: str
static parse(d: dict, p: str) SpeechToTextResult[source]
speech_text: str
status: bool
class trengine.types.TextToSpeechResult(status: bool, text: str, language: str, output_path: str)[source]

Bases: Base

language: str
output_path: str
static parse(d: dict, p: str) TextToSpeechResult[source]
status: bool
text: str

Module contents

class trengine.AsyncEngine[source]

Bases: object

property google: AsyncGoogleTranslator

Use google engine.

Returns:

Google Engine Class.

Return type:

google.AsyncGoogleTranslator

property hozory: AsyncHozoryTranslator

Use hozory engine.

Returns:

Hozory Engine Class.

Return type:

hozory.AsyncHozoryTranslator

property identify_music: AsyncIdentifyMusic

Use identify_music service.

Returns:

identify_music Engine Class.

Return type:

identify_music.AsyncIdentifyMusic

property ocr: AsyncOCR

Use OCR service.

Returns:

Ocr Class.

Return type:

ocr.AsyncOCR

property speech_to_text: AsyncSpeechToText

Use speech_to_text service.

Returns:

speech_to_text Engine Class.

Return type:

speech_to_text.AsyncSpeechToText

property tdict: AsyncTdictTranslator

Use tdict engine.

Returns:

tdict Engine Class.

Return type:

tdict.AsyncTdictTranslator

property text_to_speech: AsyncTextToSpeech

Use text_to_speech service.

Returns:

text_to_speech Engine Class.

Return type:

text_to_speech.AsyncTextToSpeech

property tr: AsyncTranslator

Use tr engine.

Returns:

Ajax Engine Class.

Return type:

ajax.AsyncAjaxTranslator

class trengine.Engine[source]

Bases: object

property google: GoogleTranslator

Use google engine.

Returns:

Google Engine Class.

Return type:

google.GoogleTranslator

property hozory: HozoryTranslator

Use hozory engine.

Returns:

Hozory Engine Class.

Return type:

hozory.HozoryTranslator

property identify_music: IdentifyMusic

Use identify_music service.

Returns:

identify_music Engine Class.

Return type:

identify_music.IdentifyMusic

property ocr: OCR

Use OCR service.

Returns:

Ocr Class.

Return type:

ocr.OCR

property speech_to_text: SpeechToText

Use speech_to_text service.

Returns:

speech_to_text Engine Class.

Return type:

speech_to_text.SpeechToText

property tdict: TdictTranslator

Use tdict engine.

Returns:

tdict Engine Class.

Return type:

tdict.TdictTranslator

property text_to_speech: TextToSpeech

Use text_to_speech service.

Returns:

text_to_speech Engine Class.

Return type:

text_to_speech.TextToSpeech

property tr: Translator

Use tr engine.

Returns:

Ajax Engine Class.

Return type:

ajax.AjaxTranslator