CoolFace
Apppublic

darwhite/force-alignment-api

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
align.py27 linesDownload Raw Back to root
1import os2import subprocess3from aeneas.executetask import ExecuteTask4from aeneas.task import Task5 6def convert_to_wav(input_path, output_path):7    subprocess.run([8        "ffmpeg", "-y", "-i", input_path,9        "-ac", "1", "-ar", "16000", output_path10    ], check=True)11 12def force_align(audio_path, text_path, output_path):13    # Convert to WAV 16kHz mono14    wav_path = audio_path.rsplit(".", 1)[0] + ".wav"15    convert_to_wav(audio_path, wav_path)16 17    config = "task_language=eng|is_text_type=plain|os_task_file_format=json"18    task = Task(config_string=config)19    task.audio_file_path_absolute = os.path.abspath(wav_path)20    task.text_file_path_absolute = os.path.abspath(text_path)21    task.sync_map_file_path_absolute = os.path.abspath(output_path)22 23    ExecuteTask(task).execute()24    task.output_sync_map_file()25 26    return output_path27