Skip to content

Commit

Permalink
Complete the changes for supporting CSS.
Browse files Browse the repository at this point in the history
  • Loading branch information
ty274 committed May 15, 2020
1 parent 0df8552 commit b6c0406
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
22 changes: 15 additions & 7 deletions asr/python/gen_asrinput_raw_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,22 @@ def main(args):
# Create an ASR script.
with open(os.path.join(decoding_cmd, 'decode.sh'),'w') as f:
cmd = 'sh {} {} {} . {}'.format(os.path.join(tool_path, 'run_asr_continuous.sh'),
os.path.join(decoding_cmd, 'meeting_list.scp'),
decoding_result,
am_path)
os.path.join(decoding_cmd, 'meeting_list.scp'),
decoding_result,
am_path)
f.write(cmd+'\n')
cmd = 'python {} --inputdir {} --outputdir {}'.format(os.path.normpath(os.path.join(tool_path, '../python/sortctm.py')),
decoding_result,
decoding_result + '.sorted')
if args.multi_stream:
cmd = 'python {} --with_channel --inputdir {} --outputdir {}'.format(os.path.normpath(os.path.join(tool_path, '../python/sortctm.py')),
decoding_result,
decoding_result + '.sorted')
else:
cmd = 'python {} --inputdir {} --outputdir {}'.format(os.path.normpath(os.path.join(tool_path, '../python/sortctm.py')),
decoding_result,
decoding_result + '.sorted')
f.write(cmd+'\n')
cmd = 'chown -R {}:{} {}'.format(os.getuid(), os.getgid(), decoding_result)
f.write(cmd+'\n')
cmd = 'chown -R {}:{} {}'.format(os.getuid(), os.getgid(), decoding_result + '.sort')
cmd = 'chown -R {}:{} {}'.format(os.getuid(), os.getgid(), decoding_result + '.sorted')
f.write(cmd+'\n')


Expand All @@ -134,6 +139,9 @@ def make_argparse():
parser.add_argument('--merge_margin', default=1, metavar='<float>', type=float,
help='Segmentation parameter.')

parser.add_argument('--multi_stream', action='store_true',
help='Set this flag when processing CSS (or multi-stream) outputs.')

return parser


Expand Down
31 changes: 10 additions & 21 deletions asr/python/sortctm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
from collections import defaultdict


def sortout_results(ctmfile, tgtdir):
def sortout_results(ctmfile, tgtdir, with_channel=False):
print('')
print('{}'.format(ctmfile))
print(' -> {}'.format(tgtdir))

os.makedirs(tgtdir, exist_ok=True)

# overlap_ratio_0.0_sil2.9_3.0_session0_actual0.0_segment_5_195199_384160 1 1.770 0.420 REMEMBER
ptrn = re.compile('^overlap_ratio_([\d\.]+)_sil([\d\.]+)_([\d\.]+)_session(\d+)_actual([\d\.]+)_segment_(\d+)_(\d+)_(\d+)$')
if with_channel:
# overlap_ratio_0.0_sil0.1_0.5_session0_actual0.0_segment_6_1_399200_556960 1 7.330 0.550 SPEAKING
ptrn = re.compile('^overlap_ratio_([\d\.]+)_sil([\d\.]+)_([\d\.]+)_session(\d+)_actual([\d\.]+)_[A-Za-z]+_(\d+)_\d+_(\d+)_(\d+)$')
else:
# overlap_ratio_0.0_sil2.9_3.0_session0_actual0.0_segment_5_195199_384160 1 1.770 0.420 REMEMBER
ptrn = re.compile('^overlap_ratio_([\d\.]+)_sil([\d\.]+)_([\d\.]+)_session(\d+)_actual([\d\.]+)_[A-Za-z]+_(\d+)_(\d+)_(\d+)$')

results = defaultdict(list)

Expand Down Expand Up @@ -72,24 +76,7 @@ def main(args):
cfg = os.path.splitext(os.path.basename(ctmfile))[0]
tgtdir = os.path.join(args.outputdir, cfg, cond)

sortout_results(ctmfile, tgtdir)




# # Write the sorted version to the output CTM file.
# for segment in hyps:
# outputdir = os.path.join(args.outputdir, os.path.splitext(os.path.basename(args.inputfile))[0])
# outputfile = os.path.join(outputdir, segment + '.ctm')

# os.makedirs(outputdir, exist_ok=True)

# curhyps = sorted(hyps[segment], key=lambda hyp: hyp[2])

# with open(outputfile, 'w') as f:
# for mtg, ch, start, dur, wrd, conf in curhyps:
# print('{} {} {:.2f} {} {} {}'.format(mtg, ch, start, dur, wrd, conf), file=f)

sortout_results(ctmfile, tgtdir, with_channel=args.with_channel)



Expand All @@ -101,6 +88,8 @@ def make_argparse():
help='Raw ASR result directory.')
parser.add_argument('--outputdir', metavar='<path>', required=True,
help='Output directory.')
parser.add_argument('--with_channel', action='store_true',
help='Has a channel index in each CTM line.')

return parser

Expand Down
11 changes: 6 additions & 5 deletions asr/scripts/gen_asrinput_raw_continuous.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

PYTHON=python

curdir=`dirname $0`
curdir=`realpath $curdir`

# args
prep_script=../python/gen_asrinput_raw_continuous.py
prep_script=$curdir/../python/gen_asrinput_raw_continuous.py
libricss_path=$EXPROOT/data
script_path=../scripts
script_path=$curdir/../scripts
asr_path=$AMPATH

echo "$prep_script --data_path $libricss_path --tool_path $script_path --asr_path $asr_path"

$PYTHON $prep_script --data_path $libricss_path --tool_path $script_path --asr_path $asr_path
$PYTHON $prep_script --input_path $libricss_path/monaural/segments --decode_path $libricss_path/baseline/segments --tool_path $script_path --am_path $asr_path
10 changes: 6 additions & 4 deletions asr/scripts/gen_asrinput_separated_continuous.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

PYTHON=python

curdir=`dirname $0`
curdir=`realpath $curdir`

# args
prep_script=../python/gen_asrinput_separated_continuous.py
prep_script=$curdir/../python/gen_asrinput_raw_continuous.py
libricss_path=$EXPROOT/data
script_path=../scripts
script_path=$curdir/../scripts
asr_path=$AMPATH

echo "$prep_script --data_path $libricss_path --tool_path $script_path --asr_path $asr_path"
$PYTHON $prep_script --multi_stream --input_path $libricss_path/separation_result/continuous_separation --decode_path $libricss_path/separation_baseline --tool_path $script_path --am_path $asr_path

$PYTHON $prep_script --data_path $libricss_path --tool_path $script_path --asr_path $asr_path

0 comments on commit b6c0406

Please sign in to comment.