Spaces:
Sleeping
Sleeping
primepake
commited on
Commit
·
631dfe2
1
Parent(s):
033f12a
add data preprocess
Browse files
speech/local/download_and_untar.sh
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Copyright 2014 Johns Hopkins University (author: Daniel Povey)
|
| 4 |
+
# Apache 2.0
|
| 5 |
+
|
| 6 |
+
remove_archive=false
|
| 7 |
+
|
| 8 |
+
if [ "$1" == --remove-archive ]; then
|
| 9 |
+
remove_archive=true
|
| 10 |
+
shift
|
| 11 |
+
fi
|
| 12 |
+
|
| 13 |
+
if [ $# -ne 3 ]; then
|
| 14 |
+
echo "Usage: $0 [--remove-archive] <data-base> <url-base> <corpus-part>"
|
| 15 |
+
echo "e.g.: $0 /export/a15/vpanayotov/data www.openslr.org/resources/11 dev-clean"
|
| 16 |
+
echo "With --remove-archive it will remove the archive after successfully un-tarring it."
|
| 17 |
+
echo "<corpus-part> can be one of: dev-clean, test-clean, dev-other, test-other,"
|
| 18 |
+
echo " train-clean-100, train-clean-360, train-other-500."
|
| 19 |
+
exit 1
|
| 20 |
+
fi
|
| 21 |
+
|
| 22 |
+
data=$1
|
| 23 |
+
url=$2
|
| 24 |
+
part=$3
|
| 25 |
+
|
| 26 |
+
if [ ! -d "$data" ]; then
|
| 27 |
+
echo "$0: no such directory $data"
|
| 28 |
+
exit 1
|
| 29 |
+
fi
|
| 30 |
+
|
| 31 |
+
part_ok=false
|
| 32 |
+
list="dev-clean test-clean dev-other test-other train-clean-100 train-clean-360 train-other-500"
|
| 33 |
+
for x in $list; do
|
| 34 |
+
if [ "$part" == $x ]; then part_ok=true; fi
|
| 35 |
+
done
|
| 36 |
+
if ! $part_ok; then
|
| 37 |
+
echo "$0: expected <corpus-part> to be one of $list, but got '$part'"
|
| 38 |
+
exit 1
|
| 39 |
+
fi
|
| 40 |
+
|
| 41 |
+
if [ -z "$url" ]; then
|
| 42 |
+
echo "$0: empty URL base."
|
| 43 |
+
exit 1
|
| 44 |
+
fi
|
| 45 |
+
|
| 46 |
+
if [ -f $data/LibriTTS/$part/.complete ]; then
|
| 47 |
+
echo "$0: data part $part was already successfully extracted, nothing to do."
|
| 48 |
+
exit 0
|
| 49 |
+
fi
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# sizes of the archive files in bytes. This is some older versions.
|
| 53 |
+
sizes_old="371012589 347390293 379743611 361838298 6420417880 23082659865 30626749128"
|
| 54 |
+
# sizes_new is the archive file sizes of the final release. Some of these sizes are of
|
| 55 |
+
# things we probably won't download.
|
| 56 |
+
sizes_new="337926286 314305928 695964615 297279345 87960560420 33373768 346663984 328757843 6387309499 23049477885 30593501606"
|
| 57 |
+
|
| 58 |
+
if [ -f $data/$part.tar.gz ]; then
|
| 59 |
+
size=$(/bin/ls -l $data/$part.tar.gz | awk '{print $5}')
|
| 60 |
+
size_ok=false
|
| 61 |
+
for s in $sizes_old $sizes_new; do if [ $s == $size ]; then size_ok=true; fi; done
|
| 62 |
+
if ! $size_ok; then
|
| 63 |
+
echo "$0: removing existing file $data/$part.tar.gz because its size in bytes $size"
|
| 64 |
+
echo "does not equal the size of one of the archives."
|
| 65 |
+
rm $data/$part.tar.gz
|
| 66 |
+
else
|
| 67 |
+
echo "$data/$part.tar.gz exists and appears to be complete."
|
| 68 |
+
fi
|
| 69 |
+
fi
|
| 70 |
+
|
| 71 |
+
if [ ! -f $data/$part.tar.gz ]; then
|
| 72 |
+
if ! which wget >/dev/null; then
|
| 73 |
+
echo "$0: wget is not installed."
|
| 74 |
+
exit 1
|
| 75 |
+
fi
|
| 76 |
+
full_url=$url/$part.tar.gz
|
| 77 |
+
echo "$0: downloading data from $full_url. This may take some time, please be patient."
|
| 78 |
+
|
| 79 |
+
if ! wget -P $data --no-check-certificate $full_url; then
|
| 80 |
+
echo "$0: error executing wget $full_url"
|
| 81 |
+
exit 1
|
| 82 |
+
fi
|
| 83 |
+
fi
|
| 84 |
+
|
| 85 |
+
if ! tar -C $data -xvzf $data/$part.tar.gz; then
|
| 86 |
+
echo "$0: error un-tarring archive $data/$part.tar.gz"
|
| 87 |
+
exit 1
|
| 88 |
+
fi
|
| 89 |
+
|
| 90 |
+
touch $data/LibriTTS/$part/.complete
|
| 91 |
+
|
| 92 |
+
echo "$0: Successfully downloaded and un-tarred $data/$part.tar.gz"
|
| 93 |
+
|
| 94 |
+
if $remove_archive; then
|
| 95 |
+
echo "$0: removing $data/$part.tar.gz file since --remove-archive option was supplied."
|
| 96 |
+
rm $data/$part.tar.gz
|
| 97 |
+
fi
|
speech/local/prepare_data.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import logging
|
| 3 |
+
import glob
|
| 4 |
+
import os
|
| 5 |
+
from tqdm import tqdm
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
logger = logging.getLogger()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def main():
|
| 12 |
+
wavs = list(glob.glob('{}/*/*/*wav'.format(args.src_dir)))
|
| 13 |
+
|
| 14 |
+
utt2wav, utt2text, utt2spk, spk2utt = {}, {}, {}, {}
|
| 15 |
+
for wav in tqdm(wavs):
|
| 16 |
+
txt = wav.replace('.wav', '.normalized.txt')
|
| 17 |
+
if not os.path.exists(txt):
|
| 18 |
+
logger.warning('{} do not exsist'.format(txt))
|
| 19 |
+
continue
|
| 20 |
+
with open(txt) as f:
|
| 21 |
+
content = ''.join(l.replace('\n', '') for l in f.readline())
|
| 22 |
+
utt = os.path.basename(wav).replace('.wav', '')
|
| 23 |
+
spk = utt.split('_')[0]
|
| 24 |
+
utt2wav[utt] = wav
|
| 25 |
+
utt2text[utt] = content
|
| 26 |
+
utt2spk[utt] = spk
|
| 27 |
+
if spk not in spk2utt:
|
| 28 |
+
spk2utt[spk] = []
|
| 29 |
+
spk2utt[spk].append(utt)
|
| 30 |
+
|
| 31 |
+
with open('{}/wav.scp'.format(args.des_dir), 'w') as f:
|
| 32 |
+
for k, v in utt2wav.items():
|
| 33 |
+
f.write('{} {}\n'.format(k, v))
|
| 34 |
+
with open('{}/text'.format(args.des_dir), 'w') as f:
|
| 35 |
+
for k, v in utt2text.items():
|
| 36 |
+
f.write('{} {}\n'.format(k, v))
|
| 37 |
+
with open('{}/utt2spk'.format(args.des_dir), 'w') as f:
|
| 38 |
+
for k, v in utt2spk.items():
|
| 39 |
+
f.write('{} {}\n'.format(k, v))
|
| 40 |
+
with open('{}/spk2utt'.format(args.des_dir), 'w') as f:
|
| 41 |
+
for k, v in spk2utt.items():
|
| 42 |
+
f.write('{} {}\n'.format(k, ' '.join(v)))
|
| 43 |
+
return
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
parser = argparse.ArgumentParser()
|
| 48 |
+
parser.add_argument('--src_dir',
|
| 49 |
+
type=str)
|
| 50 |
+
parser.add_argument('--des_dir',
|
| 51 |
+
type=str)
|
| 52 |
+
parser.add_argument('--ref_model',
|
| 53 |
+
type=str)
|
| 54 |
+
args = parser.parse_args()
|
| 55 |
+
main()
|