readbeyond / aeneas

aeneas is a Python/C library and a set of tools to automagically synchronize audio and text (aka forced alignment)
http://www.readbeyond.it/aeneas/
GNU Affero General Public License v3.0
2.49k stars 228 forks source link

allow_unlisted_languages=True works in CLI but not in python script #263

Closed tslater closed 3 years ago

tslater commented 3 years ago

I've tried setting the runtime configuration parameter allow_unlisted_languages=true 3 different ways, but it only seems to work when I use the cli:

def sync(event):
    print("event")
    print(event)
    # create Task object
    config_string = event["config_string"]
    rconf_string = event["rconf_string"]
    input_text = event["input_text"]
    audio_file_path = event["audio_file_path"]
    start_from = event["start_from"]
    end_at = event["end_at"]

    rconf = RuntimeConfiguration(rconf_string)
    rconf[RuntimeConfiguration.ALLOW_UNLISTED_LANGUAGES] = True
    rconf[RuntimeConfiguration.TTS] = "aws"
    print(rconf)
    input_text_file = tempfile.NamedTemporaryFile(
        delete=should_delete_temp_files).name

    with open(input_text_file, "w") as input_file:
        input_file.write(input_text)
    logger = Logger(tee=True)
    task = Task(config_string=config_string, rconf=rconf, logger=logger)
    task.audio_file_path_absolute = audio_file_path
    task.text_file_path_absolute = input_text_file

    ExecuteTask(task).execute()

    os.remove(input_text_file)
    return task.sync_map.json_string

def test():
    result = sync({
        "start_from": "26.5",
        "end_at": "28.1",
        "audio_file_path": "/var/task/cropped.mp3",
        "input_text": "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\" lang=\"en\" xml:lang=\"en\">  <head>    <meta charset=\"utf-8\"/>  </head>  <body>    <div id=\"divSonnet\">    <p class=\"stanza\" id=\"p000001\">      <span id=\"p000001s000001\">        <span id=\"p000001s000001w000001\">Its</span>        <span id=\"p000001s000001w000002\">an</span>        <span id=\"p000001s000001w000003\">impact</span>        <span id=\"p000001s000001w000004\">tremor</span>        <span id=\"p000001s000001w000005\">is</span>        <span id=\"p000001s000001w000006\">what</span>        <span id=\"p000001s000001w000007\">it</span>        <span id=\"p000001s000001w000008\">is</span>      </span>    </p>    </div>  </body>  </html>  ",
        "config_string": "task_language=Joey|allow_unlisted_languages=True|os_task_file_format=json|is_text_type=munparsed|is_text_munparsed_l1_id_regex=p[0-9]+|is_text_munparsed_l2_id_regex=p[0-9]+s[0-9]+|is_text_munparsed_l3_id_regex=p[0-9]+s[0-9]+w[0-9]+|is_text_unparsed_id_sort=numeric",
        "rconf_string": "tts=aws|tts_l1=aws|tts_l2=aws|tts_l3=aws|allow_unlisted_languages=True"
    })
    return result

Calling print(rconf) shows that the parameter is set, but then in the error:

[2020-11-21 04:42:19,940] ERROR in app: Exception on /test [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/aeneas/executetask.py", line 283, in _execute_multi_level_task
    text_files, sync_roots = self._execute_level(
  File "/usr/local/lib/python3.8/dist-packages/aeneas/executetask.py", line 345, in _execute_level
    self._execute_inner(
  File "/usr/local/lib/python3.8/dist-packages/aeneas/executetask.py", line 386, in _execute_inner
    synt_handler, synt_path, synt_anchors, synt_format = self._synthesize(text_file)
  File "/usr/local/lib/python3.8/dist-packages/aeneas/executetask.py", line 538, in _synthesize
    result = self.synthesizer.synthesize(text_file, path)
  File "/usr/local/lib/python3.8/dist-packages/aeneas/synthesizer.py", line 210, in synthesize
    result = self.tts_engine.synthesize_multiple(
  File "/usr/local/lib/python3.8/dist-packages/aeneas/ttswrappers/basettswrapper.py", line 403, in synthesize_multiple
    self.log_exc(u"Language '%s' is not supported by the selected TTS engine" % (fragment.language), None, True, ValueError)
  File "/usr/local/lib/python3.8/dist-packages/aeneas/logger.py", line 351, in log_exc
    raise raise_type(raise_message)
ValueError: Language 'Joey' is not supported by the selected TTS engine

During handling of the above exception, another exception occurred:

@readbeyond, I'd love your help. Am I missing something?

tslater commented 3 years ago

Ok, after reading a lot of source code i realized that I need to pass the runtime configuration to ExecuteTask. I'm wondering what the point of having it as an arg for Task() is?

readbeyond commented 3 years ago

@tslater RuntimeConfiguration was introduced to contain a "deploy time" configuration, not modifiable by end users in a multi-tenant deployment like the aeneas Web application. We wanted to allow the user to provide configurations for their Job/Task, but not e.g. changing some potentially dangerous settings of the application running on our servers. Clearly this distinction vanishes if you use aeneas in "single user mode" on a local machine.

readbeyond commented 3 years ago

@tslater See the documentation, specifically:

tslater commented 3 years ago

@readbeyond Thanks. That clarifies it. I appreciate you taking the time to explain.