mirror of
https://github.com/FunAudioLLM/CosyVoice.git
synced 2026-02-05 18:09:24 +08:00
add cosyvoice code
This commit is contained in:
97
examples/libritts/cosyvoice/local/download_and_untar.sh
Executable file
97
examples/libritts/cosyvoice/local/download_and_untar.sh
Executable file
@@ -0,0 +1,97 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2014 Johns Hopkins University (author: Daniel Povey)
|
||||
# Apache 2.0
|
||||
|
||||
remove_archive=false
|
||||
|
||||
if [ "$1" == --remove-archive ]; then
|
||||
remove_archive=true
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ $# -ne 3 ]; then
|
||||
echo "Usage: $0 [--remove-archive] <data-base> <url-base> <corpus-part>"
|
||||
echo "e.g.: $0 /export/a15/vpanayotov/data www.openslr.org/resources/11 dev-clean"
|
||||
echo "With --remove-archive it will remove the archive after successfully un-tarring it."
|
||||
echo "<corpus-part> can be one of: dev-clean, test-clean, dev-other, test-other,"
|
||||
echo " train-clean-100, train-clean-360, train-other-500."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
data=$1
|
||||
url=$2
|
||||
part=$3
|
||||
|
||||
if [ ! -d "$data" ]; then
|
||||
echo "$0: no such directory $data"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
part_ok=false
|
||||
list="dev-clean test-clean dev-other test-other train-clean-100 train-clean-360 train-other-500"
|
||||
for x in $list; do
|
||||
if [ "$part" == $x ]; then part_ok=true; fi
|
||||
done
|
||||
if ! $part_ok; then
|
||||
echo "$0: expected <corpus-part> to be one of $list, but got '$part'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$url" ]; then
|
||||
echo "$0: empty URL base."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f $data/LibriSpeech/$part/.complete ]; then
|
||||
echo "$0: data part $part was already successfully extracted, nothing to do."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# sizes of the archive files in bytes. This is some older versions.
|
||||
sizes_old="371012589 347390293 379743611 361838298 6420417880 23082659865 30626749128"
|
||||
# sizes_new is the archive file sizes of the final release. Some of these sizes are of
|
||||
# things we probably won't download.
|
||||
sizes_new="337926286 314305928 695964615 297279345 87960560420 33373768 346663984 328757843 6387309499 23049477885 30593501606"
|
||||
|
||||
if [ -f $data/$part.tar.gz ]; then
|
||||
size=$(/bin/ls -l $data/$part.tar.gz | awk '{print $5}')
|
||||
size_ok=false
|
||||
for s in $sizes_old $sizes_new; do if [ $s == $size ]; then size_ok=true; fi; done
|
||||
if ! $size_ok; then
|
||||
echo "$0: removing existing file $data/$part.tar.gz because its size in bytes $size"
|
||||
echo "does not equal the size of one of the archives."
|
||||
rm $data/$part.tar.gz
|
||||
else
|
||||
echo "$data/$part.tar.gz exists and appears to be complete."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f $data/$part.tar.gz ]; then
|
||||
if ! which wget >/dev/null; then
|
||||
echo "$0: wget is not installed."
|
||||
exit 1
|
||||
fi
|
||||
full_url=$url/$part.tar.gz
|
||||
echo "$0: downloading data from $full_url. This may take some time, please be patient."
|
||||
|
||||
if ! wget -P $data --no-check-certificate $full_url; then
|
||||
echo "$0: error executing wget $full_url"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! tar -C $data -xvzf $data/$part.tar.gz; then
|
||||
echo "$0: error un-tarring archive $data/$part.tar.gz"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
touch $data/LibriSpeech/$part/.complete
|
||||
|
||||
echo "$0: Successfully downloaded and un-tarred $data/$part.tar.gz"
|
||||
|
||||
if $remove_archive; then
|
||||
echo "$0: removing $data/$part.tar.gz file since --remove-archive option was supplied."
|
||||
rm $data/$part.tar.gz
|
||||
fi
|
||||
51
examples/libritts/cosyvoice/local/prepare_data.py
Normal file
51
examples/libritts/cosyvoice/local/prepare_data.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import argparse
|
||||
import logging
|
||||
import glob
|
||||
import os
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
def main():
|
||||
wavs = list(glob.glob('{}/*/*/*wav'.format(args.src_dir)))
|
||||
|
||||
utt2wav, utt2text, utt2spk, spk2utt = {}, {}, {}, {}
|
||||
for wav in tqdm(wavs):
|
||||
txt = wav.replace('.wav', '.normalized.txt')
|
||||
if not os.path.exists(txt):
|
||||
logger.warning('{} do not exsist'.format(txt))
|
||||
continue
|
||||
with open(txt) as f:
|
||||
content = ''.join(l.replace('\n', '') for l in f.readline())
|
||||
utt = os.path.basename(wav).replace('.wav', '')
|
||||
spk = utt.split('_')[0]
|
||||
utt2wav[utt] = wav
|
||||
utt2text[utt] = content
|
||||
utt2spk[utt] = spk
|
||||
if spk not in spk2utt:
|
||||
spk2utt[spk] = []
|
||||
spk2utt[spk].append(utt)
|
||||
|
||||
with open('{}/wav.scp'.format(args.des_dir), 'w') as f:
|
||||
for k, v in utt2wav.items():
|
||||
f.write('{} {}\n'.format(k, v))
|
||||
with open('{}/text'.format(args.des_dir), 'w') as f:
|
||||
for k, v in utt2text.items():
|
||||
f.write('{} {}\n'.format(k, v))
|
||||
with open('{}/utt2spk'.format(args.des_dir), 'w') as f:
|
||||
for k, v in utt2spk.items():
|
||||
f.write('{} {}\n'.format(k, v))
|
||||
with open('{}/spk2utt'.format(args.des_dir), 'w') as f:
|
||||
for k, v in spk2utt.items():
|
||||
f.write('{} {}\n'.format(k, ' '.join(v)))
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--src_dir',
|
||||
type=str)
|
||||
parser.add_argument('--des_dir',
|
||||
type=str)
|
||||
args = parser.parse_args()
|
||||
main()
|
||||
Reference in New Issue
Block a user