def _process_file(wav_dir, txt_dir, base_filename, root_dir):
    full_recording_path = os.path.join(root_dir, base_filename)
    assert (os.path.exists(full_recording_path) and os.path.exists(root_dir))
    wav_recording_path = os.path.join(wav_dir, base_filename.replace('.flac', '.wav'))
    subprocess.call(['sox {}  -r {} -b 16 -c 1 {}'.format(full_recording_path, str(args.sample_rate), wav_recording_path)], shell=True)
    txt_transcript_path = os.path.join(txt_dir, base_filename.replace('.flac', '.txt'))
    transcript_file = os.path.join(root_dir, ('-'.join(base_filename.split('-')[:(- 1)]) + '.trans.txt'))
    assert os.path.exists(transcript_file), 'Transcript file {} does not exist.'.format(transcript_file)
    transcriptions = open(transcript_file).read().strip().split('\n')
    transcriptions = {t.split()[0].split('-')[(- 1)]: ' '.join(t.split()[1:]) for t in transcriptions}
    with open(txt_transcript_path, 'w') as f:
        key = base_filename.replace('.flac', '').split('-')[(- 1)]
        assert (key in transcriptions), '{} is not in the transcriptions'.format(key)
        f.write(_preprocess_transcript(transcriptions[key]))
        f.flush()
def _process_file(wav_dir, txt_dir, base_filename, root_dir):
    full_recording_path = os.path.join(root_dir, base_filename)
    assert (os.path.exists(full_recording_path) and os.path.exists(root_dir))
    wav_recording_path = os.path.join(wav_dir, base_filename.replace('.flac', '.wav'))
    subprocess.call(['sox {}  -r {} -b 16 -c 1 {}'.format(full_recording_path, str(args.sample_rate), wav_recording_path)], shell=True)
    txt_transcript_path = os.path.join(txt_dir, base_filename.replace('.flac', '.txt'))
    transcript_file = os.path.join(root_dir, ('-'.join(base_filename.split('-')[:(- 1)]) + '.trans.txt'))
    assert os.path.exists(transcript_file), 'Transcript file {} does not exist.'.format(transcript_file)
    transcriptions = open(transcript_file).read().strip().split('\n')
    transcriptions = {t.split()[0].split('-')[(- 1)]: ' '.join(t.split()[1:]) for t in transcriptions}
    with open(txt_transcript_path, 'w') as f:
        key = base_filename.replace('.flac', ).split('-')[(- 1)]
        assert (key in transcriptions), '{} is not in the transcriptions'.format(key)
        f.write(_preprocess_transcript(transcriptions[key]))
        f.flush()