From dbb0b8498e2f4eb5aa168c38c9e25a3edc0bf741 Mon Sep 17 00:00:00 2001 From: Sacha Chua Date: Sun, 30 Oct 2022 10:01:09 -0400 Subject: aeneas, caption updates --- roles/caption/tasks/aeneas.yml | 12 ++++++++++++ roles/caption/tasks/main.yml | 16 +++++++++------- roles/caption/templates/process-captions.py | 7 +++++-- 3 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 roles/caption/tasks/aeneas.yml (limited to 'roles') diff --git a/roles/caption/tasks/aeneas.yml b/roles/caption/tasks/aeneas.yml new file mode 100644 index 0000000..e280e7e --- /dev/null +++ b/roles/caption/tasks/aeneas.yml @@ -0,0 +1,12 @@ +- name: Install packages + package: + name: + - espeak + - python3-espeak + - ffmpeg + - libespeak-dev +- name: Install aeneas + ansible.builtin.pip: + name: + - numpy + - aeneas diff --git a/roles/caption/tasks/main.yml b/roles/caption/tasks/main.yml index 353b83b..3fa997c 100644 --- a/roles/caption/tasks/main.yml +++ b/roles/caption/tasks/main.yml @@ -17,6 +17,8 @@ - tqdm - torchaudio - num2words +- name: Set up aeneas + include: aeneas.yml - name: Create group group: name: "{{ emacsconf_group }}" @@ -31,7 +33,7 @@ path: "{{ emacsconf_caption_dir }}" state: directory - name: Copy the script for processing the files - tags: process-captions + tags: process-captions, wip template: src: process-captions.py dest: "{{ emacsconf_caption_dir }}/process-captions.py" @@ -63,9 +65,9 @@ group: "{{ emacsconf_group }}" mode: "g+rwX" recurse: true -- name: Restart caption monitoring service - become: true - service: - name: captions - enabled: true - state: started +# - name: Restart caption monitoring service +# become: true +# service: +# name: captions +# enabled: true +# state: started diff --git a/roles/caption/templates/process-captions.py b/roles/caption/templates/process-captions.py index f3f317d..6f6b013 100755 --- a/roles/caption/templates/process-captions.py +++ b/roles/caption/templates/process-captions.py @@ -47,6 +47,7 @@ TRIM_AUDIO = False MODEL = os.environ.get('MODEL', 'large') # Set to tiny for testing WORK_DIR = "{{ emacsconf_caption_dir }}" JSON_FILE = os.path.join(WORK_DIR, 'talks.json') +DO_SRV2 = False # ---------------------------------------------------------------- @@ -94,7 +95,7 @@ def get_files_to_work_on(directory): else: val['base'] = os.path.join(os.path.dirname(val['video'] or val['audio']), base_name(val['video'] or val['audio'])) - if ALWAYS or (not 'vtt' in val or not 'srv2' in val): + if ALWAYS or (not 'vtt' in val or (DO_SRV2 and not 'srv2' in val)): if not 'audio' in val and 'video' in val: # No audio, need to convert it val = extract_audio(val) @@ -141,6 +142,8 @@ def generate_captions(work): result = clean_up_timestamps(result) with open(new_file, 'w') as vtt: whisper.utils.write_vtt(result['segments'], file=vtt) + with open(work['base'] + '.txt') + whisper.utils.write_txt(result['segments'], file=txt) work['vtt'] = new_file if 'srv2' in work: del work['srv2'] return work @@ -209,7 +212,7 @@ if len(needs_work) > 0: if work['audio']: if ALWAYS or not 'vtt' in work: work = generate_captions(work) - if ALWAYS or not 'srv2' in work: + if DO_SRV2 and (ALWAYS or not 'srv2' in work): work = generate_srv2(work) # print("Aligning words", audio_file, datetime.datetime.now()) # word_cuts = align_words(cuts) -- cgit v1.2.3