Esempio n. 1
0
 def translate(self, client, lang_code):
     # the lang_code here still needs conversion from cmn to zh for example
     target_language = get_lang_code(lang_code)
     original_language = get_lang_code(self.input_locale)
     raw_translation = client.get_translation(
         unescape(self.original_text),
         original_language,
         target_language,
         with_eval=False,
     )
     # Languages like french have apostrophes.
     # gCloud translate uses HTML character references.
     self.translated_sentences[lang_code] = TranslatedSentence(
         lang_code, unescape(raw_translation))
Esempio n. 2
0
    def __init__(
        self,
        start_time,
        end_time,
        input_locale,
        original_text,
    ):
        self.start_time = start_time
        self.end_time = end_time
        self.input_locale = input_locale
        self.original_text = original_text
        self.duration = round(end_time - start_time, 1)
        # Map of (target_language,TranslatedSentence)
        self.translated_sentences = {}
        self.translated_sentences[get_lang_code(
            input_locale)] = TranslatedSentence(get_lang_code(input_locale),
                                                original_text)

        # Map of (target_locale,SynthesizedSentence)
        self.synthesized_sentences = {}
Esempio n. 3
0
    def __init__(self,
                 start_time,
                 end_time,
                 input_locale,
                 original_text,
                 speaker=1,
                 gender=1):
        self.start_time = start_time
        self.end_time = end_time
        self.input_locale = input_locale
        self.original_text = original_text
        self.speaker = speaker
        self.gender = gender  # note that sentence genders are stored as ints not strings
        self.duration = round(end_time - start_time, 1)
        # Map of (target_language,TranslatedSentence)
        self.translated_sentences = {}
        self.translated_sentences[get_lang_code(
            input_locale)] = TranslatedSentence(get_lang_code(input_locale),
                                                original_text)

        # Map of (target_locale,SynthesizedSentence)
        self.synthesized_sentences = {}
Esempio n. 4
0
 def get_translated_sentence(self, locale):
     lang_code = get_lang_code(locale)
     return self.translated_sentences[lang_code]
Esempio n. 5
0
    def validate_args(self):
        if not self.is_video():
            # beckham on videos only [warning]
            if self.beckham:
                print("[Warning] Beckham flag set on non video")
            # watermarks on videos only [warning]
            if self.include_watermarks:
                print("[Warning] Include watermarks flag set on non video")
            # export_fps on videos only [warning]
            if self.export_fps:
                print("[Warning] Export fps flag set on non video")

        # self.production_path exists
        if not os.path.isdir(self.prod_path):
            raise FileNotFoundError(
                f"Production path {self.prod_path} does not exist")

        # self.development_path exists [create if it doesn't]
        if not os.path.isdir(self.dev_path):
            os.makedirs(self.dev_path)

        # if we want all available langs, get those now
        # availability depends on tts provider (gender must match)
        if self.target_locales == ["all"]:
            voices = self.client.get_all_matching_voices()
            self.target_locales = list(set([v.locale for v in voices]))

        self.target_locales = sorted(self.target_locales)
        self.target_languages = list(
            set(map(get_lang_code, self.target_locales)))
        self.input_language = get_lang_code(self.input_locale)

        # create beckham directories
        if self.beckham:
            if not os.path.isdir(os.path.join(self.dev_path, "beckham")):
                os.mkdir(os.path.join(self.dev_path, "beckham"))
            if not os.path.isdir(os.path.join(self.prod_path, "beckham")):
                os.mkdir(os.path.join(self.prod_path, "beckham"))

        # all target_locales should be directories in dev to store tmp files
        for locale in self.target_locales + [self.input_locale]:
            # mkdirs in /dev
            if not os.path.isdir(os.path.join(self.dev_path, locale)):
                os.mkdir(os.path.join(self.dev_path, locale))

            # mkdirs in /prod if we are not a beckham video
            if not self.beckham and not os.path.isdir(
                    os.path.join(self.prod_path, locale)):
                os.mkdir(os.path.join(self.prod_path, locale))

        # remove the input_locale from targets so we don't translate/synthesize
        if self.input_locale in self.target_locales:
            self.target_locales.remove(self.input_locale)
            self.target_languages.remove(self.input_language)

        # input_media_file exists
        self.input_media_path = os.path.join(self.prod_path,
                                             self.input_media_file)
        if not os.path.isfile(self.input_media_path):
            raise FileNotFoundError(
                f"Media file {self.input_media_path} does not exist")

        # set best_voices_path
        if self.use_best_voices:
            self.best_voices_path = os.path.join(REPO_PATH,
                                                 self.best_voices_file)
            if not os.path.isfile(self.best_voices_path):
                with open(self.best_voices_path, 'w') as w:
                    w.write('{}')

        # set background_music_path
        if self.use_background_music:
            self.background_music_path = os.path.join(
                REPO_PATH, MUSIC_DIRECTORY, self.background_music_file)
            if not os.path.isfile(self.background_music_path):
                raise FileNotFoundError(
                    f"Background music file {self.background_music_path} does not exist"
                )

        if self.use_background_music and self.use_original_bg:
            raise ValueError(
                "Cannot use background music and original background")

        return 0