diff --git a/README.md b/README.md index 36ef3cf..a231360 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,8 @@ Most important: `pip install -r docs/requirements.txt` Also install rubberband -`brew install rubberband` +macOS: `brew install rubberband` +Linux: `sudo apt-get install -y rubberband-cli` And follow the instructions in `docs/` for `aws` and `gcloud` integration. Then make sure to setup the names of the s3 or gcloud bucket you will store your audio in. diff --git a/config.yaml b/config.yaml index 4d05472..60865b5 100644 --- a/config.yaml +++ b/config.yaml @@ -17,7 +17,7 @@ beckham: false export_fps: 0 # 0 is original video (or don't include the variable) gcloud_speedup: true # if true, will run through gcloud tts twice -# Provider enum: GCLOUD-1, AWS-2 +# Provider enum: GCLOUD-1, AWS-2, DEEPL-3 stt_provider: 1 translate_provider: 1 tts_provider: 1 diff --git a/docs/aws_setup_steps.md b/docs/aws_setup_steps.md index db8f4a5..77f08af 100644 --- a/docs/aws_setup_steps.md +++ b/docs/aws_setup_steps.md @@ -1,11 +1,33 @@ -Create AWS account. Get Security Access Keys from security info page +## AWS Setup -Run +Create AWS account. Get Security Access Keys from security info page and follow the below commands. + +#### Setup Run on OS::Mac ``` curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg" sudo installer -pkg AWSCLIV2.pkg -target / ``` Check with `aws` to see if the install succeeded. -Run `aws configure` to begin configuration. -Set Access key and secret key -Optionally set us-west-2 and json as the other parameters +- Run `aws configure` to begin configuration. +- Set Access key and secret key +- Optionally set us-west-2 and json as the other parameters + + +#### Setup Run on OS::Linux x86(64bit) + +This area portrays how to install the AWS CLI version 2 on Linux. The AWS CLI version 2 has no dependencies on other Python packages. It has a self-contained, embedded copy of Python included in the installer. +``` +curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" +unzip awscliv2.zip +sudo ./aws/install +``` +(Optional) Downloading from the URL - o download the installer with your browser, use the following URL: Click [(Download here)](https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip). You can verify the integrity and authenticity of your downloaded installation file before you extract (unzip) the package. + +Confirm your installation +``` +aws --version +``` +Check with `aws` to see if the install succeeded. +- Run `aws configure` to begin configuration. +- Set Access key and secret key +- Optionally set us-west-2/east-2 and json as the other parameters diff --git a/docs/deepl_setup_steps.md b/docs/deepl_setup_steps.md new file mode 100644 index 0000000..f0d084c --- /dev/null +++ b/docs/deepl_setup_steps.md @@ -0,0 +1,27 @@ +## DeepL Translator + +- Create an account in [(DeepL Pro)](https://www.deepl.com/pro?cta=menu-login-signup). +- For Free Trial (Click `Start Free Trial` and Select an Plan), follow the steps andelect the plan for one month. +- Once you verify your address and other details, Navigate to dashboard for DeepL API Key. +- Remember your DeepL API key (keep it safe!) and use URL [(https://api.deepl.com/v2/translate)](https://api.deepl.com/v2/translate). +- With this API key you can create a wrapper fucntion. +- API call will be through ```curl/network requests```. + +EXAMPLE REQUEST +``` +curl https://api.deepl.com/v2/translate \ + -d auth_key=[yourAuthKey] \ + -d "text=Hello, world" \ + -d "target_lang=DE" +``` +EXAMPLE RESPONSE +JSON Representation +``` +{ + "translations": [{ + "detected_source_language":"EN", + "text":"Hallo, Welt!" + }] +} +``` +For more details about DeepL translator request, response, authentication, etc. Refer to [(https://www.deepl.com/docs-api/)](https://www.deepl.com/docs-api/accessing-the-api/authentication/) \ No newline at end of file diff --git a/src/api/translate/aws_translate.py b/src/api/translate/aws_translate.py index 5b21a97..418ad3c 100644 --- a/src/api/translate/aws_translate.py +++ b/src/api/translate/aws_translate.py @@ -10,7 +10,7 @@ def get_client(): def get_translation(translate_client, text_to_translate, target_language): """Translates text into the target language. Target must be an ISO 639-1 language code. - See https://g.co/cloud/translate/v2/translate-reference#supported_languages + See https://docs.aws.amazon.com/translate/latest/dg/what-is.html#what-is-languages """ if isinstance(text_to_translate, six.binary_type): text_to_translate = text_to_translate.decode("utf-8") diff --git a/src/api/translate/deepl_translate.py b/src/api/translate/deepl_translate.py new file mode 100644 index 0000000..57e2476 --- /dev/null +++ b/src/api/translate/deepl_translate.py @@ -0,0 +1,42 @@ +# deepl translate +import six +import requests +from constants.constants import DEEPL_API_KEY + + +# returns None +def get_client(): + print("Using DeepL for translation client") + return None + + +def get_translation(translate_client, text_to_translate, target_language): + """Translates text into the target language. + Target must be an ISO 639-1 language code. + See https://www.deepl.com/docs-api/other-functions/listing-supported-languages/ + """ + if isinstance(text_to_translate, six.binary_type): + text_to_translate = text_to_translate.decode("utf-8") + + translated_lst, error = [], [] + # List of required parameters for response. + try: + parameters = { + "text": text_to_translate, + "target_lang": target_language, + "auth_key": DEEPL_API_KEY, + } + # making request to deepl translation API. + # returns a JSON representation of the translation in the order the text parameters have been specified. + response = requests.get("https://api.deepl.com/v2/translate", params=parameters) + responses = response.json() + for item in responses.values(): + for key in item: + translated_lst.append(key["text"]) + except Exception as e: + error.append(str(e)) + + print("\n".join(error)) + + print(responses) + return translated_lst[0] diff --git a/src/client.py b/src/client.py index 5472edd..9efb71b 100644 --- a/src/client.py +++ b/src/client.py @@ -7,6 +7,7 @@ class Provider(enum.Enum): GCLOUD = 1 AWS = 2 + DEEPL = 3 class Client: @@ -45,6 +46,9 @@ def setup_clients(self): if self.tts_provider == Provider.AWS: from api.tts import aws_tts as tts + if self.translate_provider == Provider.DEEPL: + from api.translate import deepl_translate as translate + self.storage = storage self.stt = stt self.translate = translate @@ -119,9 +123,14 @@ def get_audio_chunk_for_sentence(self, text, locale, speedup=1.0): if update_best_voices == "y": self.save_best_voices() - return self.tts.get_audio_chunk_for_sentence( - self.tts_client, text, self.target_voices[locale], speedup=speedup - ) + if self.tts_provider == Provider.GCLOUD: + return self.tts.get_audio_chunk_for_sentence( + self.tts_client, text, self.target_voices[locale], speedup=speedup + ) + else: + return self.tts.get_audio_chunk_for_sentence( + self.tts_client, text, self.target_voices[locale] + ) # Returns a list of voices which match the gender of the client def get_all_matching_voices(self): diff --git a/src/constants/constants.py b/src/constants/constants.py index df14b3b..cb2d92c 100644 --- a/src/constants/constants.py +++ b/src/constants/constants.py @@ -44,6 +44,7 @@ def build_repo_path(): AWS_UPLOAD_BUCKET_URL = f"https://{AWS_UPLOAD_BUCKET_NAME}.s3.{AWS_REGION}.com" GCLOUD_UPLOAD_BUCKET_NAME = "" # TODO Must be filled in GCLOUD_UPLOAD_BUCKET_URL = "gs://" + GCLOUD_UPLOAD_BUCKET_NAME +DEEPL_API_KEY = "" # TODO Must be filled in EOS_PUNCTUATION = [".", "?", "!"] diff --git a/tests/run_tests.py b/tests/run_tests.py index fa0bfa4..63f4691 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -1,5 +1,5 @@ import sys -import test_sentence, test_project, test_stt, test_translate, test_tts +import test_sentence, test_project, test_stt, test_translate, test_tts, test_deepl_translate # runs all the tests we have, should exit with 0 if __name__ == "__main__": @@ -9,4 +9,5 @@ err += test_stt.main() err += test_translate.main() err += test_tts.main() + err += test_deepl_translate.main() sys.exit(err) diff --git a/tests/test_config.yaml b/tests/test_config.yaml index e56ad39..b5d4990 100644 --- a/tests/test_config.yaml +++ b/tests/test_config.yaml @@ -8,7 +8,7 @@ gender: 1 # using one language as a test target_locales: -- fr-FR +- de-DE # Optional params production_dir: media/test/prod @@ -17,10 +17,10 @@ development_dir: media/test/dev # Video flags export_fps: 1 -# Provider enum: GCLOUD-1, AWS-2 -stt_provider: 1 -translate_provider: 1 -tts_provider: 1 +# Provider enum: GCLOUD-1, AWS-2, DEEPL-3 +stt_provider: 2 +translate_provider: 3 +tts_provider: 2 use_best_voices: true best_voices_file: best_voices.json diff --git a/tests/test_deepl_translate.py b/tests/test_deepl_translate.py new file mode 100644 index 0000000..9fe4906 --- /dev/null +++ b/tests/test_deepl_translate.py @@ -0,0 +1,24 @@ +# This file should be used to test app credentials +# once it runs successfully, you can be sure that +# DeepL translation is set up correctly on this machine +import __init__ +from api.translate import deepl_translate as translate +from test_framework import test + + +def test_translation(client): + result = translate.get_translation(client, "Hello, there, Let's Play Soccer", "fr") + return test(result.lower() == "Bonjour à tous, Jouons au football", "translation") + + +def main(): + err = 0 + print("Test DeepL Translations") + client = translate.get_client() + err += test_translation(client) + print("Translation testing done") + return err + + +if __name__ == "__main__": + main()