Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 27 additions & 5 deletions docs/aws_setup_steps.md
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions docs/deepl_setup_steps.md
Original file line number Diff line number Diff line change
@@ -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/)
2 changes: 1 addition & 1 deletion src/api/translate/aws_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
42 changes: 42 additions & 0 deletions src/api/translate/deepl_translate.py
Original file line number Diff line number Diff line change
@@ -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]
15 changes: 12 additions & 3 deletions src/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class Provider(enum.Enum):
GCLOUD = 1
AWS = 2
DEEPL = 3


class Client:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions src/constants/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [".", "?", "!"]

Expand Down
3 changes: 2 additions & 1 deletion tests/run_tests.py
Original file line number Diff line number Diff line change
@@ -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__":
Expand All @@ -9,4 +9,5 @@
err += test_stt.main()
err += test_translate.main()
err += test_tts.main()
err += test_deepl_translate.main()
sys.exit(err)
10 changes: 5 additions & 5 deletions tests/test_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/test_deepl_translate.py
Original file line number Diff line number Diff line change
@@ -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()