Skip to content

Commit 2347fc5

Browse files
committed
Merge branch 'master' of github.com:TalkBank/batchalign2
2 parents 57533c2 + 51f91fc commit 2347fc5

File tree

7 files changed

+31
-14
lines changed

7 files changed

+31
-14
lines changed

batchalign/cli/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ def writer(doc, output):
298298
df.write(str(doc["wer"]))
299299
with open(Path(output).with_suffix(".diff"), 'w') as df:
300300
df.write(str(doc["diff"]))
301+
CHATFile(doc=doc["doc"]).write(str(Path(output).with_suffix(".asr.cha")))
301302

302303

303304
_dispatch("benchmark", lang, num_speakers, ["mp3", "mp4", "wav"], ctx,

batchalign/formats/chat/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def chat_parse_utterance(text, mor, gra, wor, additional):
120120
if wor == None:
121121
wor = [None for i in range(len(phonated_words))]
122122
else:
123-
words = re.findall(rf"[^{''.join(ENDING_PUNCT)} ]+ ?(\x15\d+_\d+\x15)?", wor)
123+
words = re.findall(rf"[^{''.join([i for i in ENDING_PUNCT if len(i) == 1])} ]+ ?(\x15\d+_\d+\x15)?", wor)
124124
wor = []
125125
for i in words:
126126
if i.strip() == "":

batchalign/pipelines/analysis/eval.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def analyze(self, doc, **kwargs):
148148

149149
return {
150150
"wer": wer,
151-
"diff": diff
151+
"diff": diff,
152+
"doc": doc
152153
}
153154

154155

batchalign/pipelines/asr/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
from batchalign.constants import ENDING_PUNCT
66

7+
from num2words import num2words
8+
import pycountry
9+
10+
711
def retokenize(intermediate_output):
812
"""Retokenize the output of the ASR system from one giant blob to utterances
913
@@ -153,6 +157,17 @@ def process_generation(output, lang="eng", utterance_engine=None):
153157
for part in word_parts:
154158
final_words.append([part.strip(), [cur, cur+div]])
155159
cur += div
160+
161+
lang_2 = pycountry.languages.get(alpha_3=lang).alpha_2
162+
def catched_num2words(i):
163+
if not i.isdigit():
164+
return i
165+
try:
166+
return num2words(i, lang=lang_2)
167+
except NotImplementedError:
168+
return i
169+
final_words = [[catched_num2words(i), j] for i,j in final_words]
170+
156171
# if the final words is > 300, split into n parts
157172
if len(final_words) > 300:
158173
# for each group, append

batchalign/pipelines/morphosyntax/ud.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,8 @@ def morphoanalyze(doc: Document, retokenize:bool, status_hook:callable = None, *
990990
content.dependency = form.dependency
991991

992992
except Exception as e:
993-
warnings.warn(f"Utterance failed parsing, skipping ud tagging... line='{line}', error='{e}'.\n")
993+
pass
994+
# warnings.warn(f"Utterance failed parsing, skipping ud tagging... line='{line}', error='{e}'.\n")
994995

995996
L.debug("Stanza done.")
996997
return doc

scratchpad.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767

6868

6969

70-
7170
# # ng = NgramRetraceEngine()
7271
# # # disf = DisfluencyReplacementEngine()
7372

@@ -264,16 +263,15 @@
264263
########### The Batchalign String Test Harness ###########
265264
# from batchalign.formats.chat.parser import chat_parse_utterance
266265

267-
# file = "/Users/houjun/Documents/Projects/talkbank-alignment/test_harness/input/Untitled.wav"
268-
269-
# function = "asr"
270-
# lang = "spa"
271-
# num_speakers = 1
272-
273-
# ut = Document.new(media_path=file, lang=lang)
274-
275-
# pipeline = BatchalignPipeline.new(function, lang=lang, num_speakers=num_speakers)
276-
# doc = pipeline(ut)
266+
file = "/Users/houjun/Documents/Projects/talkbank-alignment/input/spanish.mp3"
267+
function = "asr"
268+
lang = "spa"
269+
num_speakers = 1
270+
271+
ut = Document.new(media_path=file, lang=lang)
272+
pipeline = BatchalignPipeline.new(function, lang=lang, num_speakers=num_speakers, asr="rev")
273+
doc = pipeline(ut)
274+
doc
277275
# doc.content
278276
# # doc[0][-1]
279277
# # doc[0][-2].model_dump()

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def read(fname):
5151
"soundfile~=0.12.0",
5252
"rich-click>=1.7.0",
5353
"typing-extensions",
54+
"num2words",
5455
],
5556
extras_require={
5657
'dev': [

0 commit comments

Comments
 (0)