33The Batchalign command-line interface
44"""
55
6- import multiprocessing
76import rich_click as click
87import functools
98
109import os
11- from glob import glob
1210
13- from multiprocessing import Process , freeze_support
14-
15- from batchalign .pipelines import BatchalignPipeline
11+ from multiprocessing import freeze_support
1612
13+ from pathlib import Path
1714from rich .traceback import install
1815from rich .console import Console
19- from rich .panel import Panel
20- from pathlib import Path
21- from batchalign .document import *
22- from batchalign .formats .chat import CHATFile
23- from batchalign .utils import config
2416from rich .logging import RichHandler
2517
2618from batchalign .cli .dispatch import _dispatch
2719from batchalign .models .training .run import cli as train
2820
29- from enum import Enum
30-
31- import traceback
32-
3321import pyfiglet
34- from rich import pretty
35- import logging as L
36- baL = L .getLogger ('batchalign' )
22+ import logging as L
3723
3824C = Console ()
3925
@@ -62,7 +48,7 @@ def handle_verbosity(verbosity):
6248 L .getLogger ('stanza' ).handlers .clear ()
6349 L .getLogger ('transformers' ).handlers .clear ()
6450 L .getLogger ('nemo_logger' ).handlers .clear ()
65- L .getLogger ("stanza" ).setLevel (L .INFO )
51+ L .getLogger ("stanza" ).setLevel (L .WARN )
6652 L .getLogger ('nemo_logger' ).setLevel (L .CRITICAL )
6753 L .getLogger ('batchalign' ).setLevel (L .WARN )
6854 L .getLogger ('lightning.pytorch.utilities.migration.utils' ).setLevel (L .ERROR )
@@ -73,6 +59,7 @@ def handle_verbosity(verbosity):
7359 L .getLogger ('batchalign' ).setLevel (L .INFO )
7460 if verbosity >= 3 :
7561 L .getLogger ('batchalign' ).setLevel (L .DEBUG )
62+ L .getLogger ("stanza" ).setLevel (L .INFO )
7663 if verbosity >= 4 :
7764 L .getLogger ('batchalign' ).setLevel (L .DEBUG )
7865 L .getLogger ('transformers' ).setLevel (L .INFO )
@@ -81,7 +68,8 @@ def handle_verbosity(verbosity):
8168@click .pass_context
8269@click .version_option (VERSION_NUMBER )
8370@click .option ("-v" , "--verbose" , type = int , count = True , default = 0 , help = "How loquacious Batchalign should be." )
84- def batchalign (ctx , verbose ):
71+ @click .option ("--workers" , type = int , default = os .cpu_count (), help = "Number of worker processes to use." )
72+ def batchalign (ctx , verbose , workers ):
8573 """process .cha and/or audio files in IN_DIR and dumps them to OUT_DIR using recipe COMMAND"""
8674
8775 ## setup commands ##
@@ -93,7 +81,9 @@ def batchalign(ctx, verbose):
9381 handle_verbosity (verbose )
9482 # add to arguments
9583 ctx .obj ["verbose" ] = verbose
84+ ctx .obj ["workers" ] = workers
9685 # setup config
86+ from batchalign .utils import config
9787 ctx .obj ["config" ] = config .config_read (True )
9888 # make everything look better
9989 # pretty.install()
@@ -122,6 +112,7 @@ def batchalign(ctx, verbose):
122112@click .pass_context
123113def align (ctx , in_dir , out_dir , whisper , wav2vec , iic , wav2vec_yue , tencent , funaudio , ** kwargs ):
124114 """Align transcripts against corresponding media files."""
115+ from batchalign .formats .chat import CHATFile
125116 def loader (file ):
126117 return (
127118 CHATFile (path = os .path .abspath (file )).doc ,
@@ -180,6 +171,8 @@ def writer(doc, output):
180171@click .pass_context
181172def transcribe (ctx , in_dir , out_dir , lang , num_speakers , ** kwargs ):
182173 """Create a transcript from audio files."""
174+ from batchalign .document import CustomLine , CustomLineType
175+ from batchalign .formats .chat import CHATFile
183176 def loader (file ):
184177 return file
185178
@@ -229,6 +222,7 @@ def writer(doc, output):
229222@click .pass_context
230223def translate (ctx , in_dir , out_dir , ** kwargs ):
231224 """Translate the transcript to English."""
225+ from batchalign .formats .chat import CHATFile
232226
233227 def loader (file ):
234228 cf = CHATFile (path = os .path .abspath (file ), special_mor_ = True )
@@ -259,6 +253,7 @@ def writer(doc, output):
259253@click .pass_context
260254def morphotag (ctx , in_dir , out_dir , ** kwargs ):
261255 """Perform morphosyntactic analysis on transcripts."""
256+ from batchalign .formats .chat import CHATFile
262257
263258 def loader (file ):
264259 mwt = {}
@@ -285,7 +280,7 @@ def writer(doc, output):
285280
286281 _dispatch ("morphotag" , "eng" , 1 , ["cha" ], ctx ,
287282 in_dir , out_dir ,
288- loader , writer , C )
283+ loader , writer , C , ** kwargs )
289284
290285
291286#################### MORPHOTAG ################################
@@ -295,6 +290,7 @@ def writer(doc, output):
295290@click .pass_context
296291def coref (ctx , in_dir , out_dir , ** kwargs ):
297292 """Perform coreference analysis on transcripts."""
293+ from batchalign .formats .chat import CHATFile
298294
299295 def loader (file ):
300296 cf = CHATFile (path = os .path .abspath (file ))
@@ -322,6 +318,7 @@ def writer(doc, output):
322318@click .pass_context
323319def utseg (ctx , in_dir , out_dir , lang , num_speakers , ** kwargs ):
324320 """Perform morphosyntactic analysis on transcripts."""
321+ from batchalign .formats .chat import CHATFile
325322
326323 def loader (file ):
327324 return CHATFile (path = os .path .abspath (file )).doc
@@ -354,6 +351,7 @@ def writer(doc, output):
354351@click .pass_context
355352def benchmark (ctx , in_dir , out_dir , lang , num_speakers , whisper , tencent , funaudio , whisper_oai , ** kwargs ):
356353 """Benchmark ASR utilities for their word accuracy"""
354+ from batchalign .formats .chat import CHATFile
357355 def loader (file ):
358356 # try to find a .cha in the same directory
359357 p = Path (file )
@@ -397,6 +395,7 @@ def avqi(ctx, input_dir, output_dir, lang, **kwargs):
397395 """Calculate AVQI from paired .cs and .sv audio files in input directory."""
398396
399397 from batchalign .pipelines .avqi import AVQIEngine
398+ from batchalign .document import Document
400399 from pathlib import Path
401400 import os
402401
@@ -464,6 +463,7 @@ def avqi(ctx, input_dir, output_dir, lang, **kwargs):
464463@click .pass_context
465464def opensmile (ctx , input_dir , output_dir , feature_set , lang , ** kwargs ):
466465 """Extract openSMILE audio features from speech samples."""
466+ from batchalign .document import Document
467467
468468 def loader (file ):
469469 doc = Document .new (media_path = file , lang = lang )
@@ -491,6 +491,7 @@ def writer(results, output):
491491def setup (ctx ):
492492 """Reconfigure Batchalign settings, such as Rev.AI key."""
493493
494+ from batchalign .utils import config
494495 config .interactive_setup ()
495496
496497#################### VERSION ################################
@@ -503,5 +504,5 @@ def version(ctx, **kwargs):
503504 ptr = (pyfiglet .figlet_format ("Batchalign2" )+ "\n " +
504505 f"Version: [bold]{ VERSION_NUMBER .strip ()} [/bold], released { RELEASE_DATE .strip ()} \n " +
505506 f"[italic]{ RELEASE_NOTES .strip ()} [/italic]" + "\n " +
506- "\n Developed by Brian MacWhinney and Houjun Liu" )
507+ "\n Developed by Brian MacWhinney and Houjun Liu\n contributions from Sebastian Song and Franklin Chen " )
507508 C .print ("\n \n " + ptr + "\n \n " )
0 commit comments