Skip to content

Commit e895c54

Browse files
pre-commit-ci[bot]leng-yue
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 5b00752 commit e895c54

3 files changed

Lines changed: 50 additions & 17 deletions

File tree

tools/tts/batch/clean_wenet_speech.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import json
2-
from pathlib import Path
2+
import os
33
import subprocess
4+
import tempfile
5+
import time
6+
from pathlib import Path
47

58
import librosa
69
import soundfile as sf
710
import torch
811
import torchaudio
912
from fish_audio_preprocess.utils.separate_audio import (
10-
separate_audio,
11-
merge_tracks,
1213
init_model,
14+
merge_tracks,
15+
separate_audio,
1316
)
1417
from tqdm import tqdm
15-
import time
16-
import os
17-
import tempfile
1818

1919
rank = int(os.environ.get("SLURM_PROCID", 0))
2020
world_size = int(os.environ.get("SLURM_NTASKS", 1))
@@ -75,7 +75,9 @@ def main():
7575
)
7676
# Make it 2 channels
7777
audio = torch.cat([audio, audio], dim=0)
78-
tracks = separate_audio(demucs, audio, shifts=1, num_workers=0, progress=False)
78+
tracks = separate_audio(
79+
demucs, audio, shifts=1, num_workers=0, progress=False
80+
)
7981
audio = merge_tracks(tracks, filter=["vocals"])[0]
8082
vocals, sr = (
8183
torchaudio.functional.resample(

tools/tts/batch/convert_to_wav.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from pathlib import Path
1+
import random
22
import subprocess
33
from multiprocessing import Pool, cpu_count
4+
from pathlib import Path
5+
46
from tqdm import tqdm
5-
import random
7+
68

79
def convert_to_wav(src_file_path):
810
dst_file_path = dst_dir / src_file_path.relative_to(src_dir).with_suffix(".wav")
@@ -13,7 +15,19 @@ def convert_to_wav(src_file_path):
1315

1416
try:
1517
subprocess.check_call(
16-
["ffmpeg", "-y", "-i", str(src_file_path), "-c:a", "pcm_s16le", "-threads", "0", "-ar", "24000", str(dst_file_path)],
18+
[
19+
"ffmpeg",
20+
"-y",
21+
"-i",
22+
str(src_file_path),
23+
"-c:a",
24+
"pcm_s16le",
25+
"-threads",
26+
"0",
27+
"-ar",
28+
"24000",
29+
str(dst_file_path),
30+
],
1731
stdout=subprocess.DEVNULL,
1832
stderr=subprocess.DEVNULL,
1933
)
@@ -24,6 +38,7 @@ def convert_to_wav(src_file_path):
2438
except subprocess.CalledProcessError:
2539
return False
2640

41+
2742
src_dir = Path("dataset/tts/WenetSpeech/audio/")
2843
dst_dir = Path("dataset/tts/WenetSpeech/audio_wav/")
2944

@@ -35,13 +50,15 @@ def convert_to_wav(src_file_path):
3550
fail_counter = 0
3651

3752
with Pool(processes=cpu_count() * 2, maxtasksperchild=100) as pool:
38-
with tqdm(pool.imap_unordered(convert_to_wav, opus_files), total=len(opus_files)) as pbar:
53+
with tqdm(
54+
pool.imap_unordered(convert_to_wav, opus_files), total=len(opus_files)
55+
) as pbar:
3956
for success in pbar:
4057
if success:
4158
success_counter += 1
4259
else:
4360
fail_counter += 1
44-
61+
4562
pbar.set_description(f"Success: {success_counter}, Fail: {fail_counter}")
4663

4764
print(f"Successfully converted: {success_counter}")

tools/tts/batch/to_flac.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
from pathlib import Path
1+
import random
22
import subprocess
33
from multiprocessing import Pool, cpu_count
4+
from pathlib import Path
5+
46
from tqdm import tqdm
5-
import random
7+
68

79
def convert_to_flac(src_file_path):
810
dst_file_path = src_file_path.with_suffix(".flac")
911
dst_file_path.parent.mkdir(parents=True, exist_ok=True)
1012

1113
try:
1214
subprocess.check_call(
13-
["ffmpeg", "-y", "-i", str(src_file_path), "-acodec", "flac", "-threads", "0", str(dst_file_path)],
15+
[
16+
"ffmpeg",
17+
"-y",
18+
"-i",
19+
str(src_file_path),
20+
"-acodec",
21+
"flac",
22+
"-threads",
23+
"0",
24+
str(dst_file_path),
25+
],
1426
stdout=subprocess.DEVNULL,
1527
stderr=subprocess.DEVNULL,
1628
)
@@ -33,13 +45,15 @@ def convert_to_flac(src_file_path):
3345
fail_counter = 0
3446

3547
with Pool(processes=cpu_count(), maxtasksperchild=100) as pool:
36-
with tqdm(pool.imap_unordered(convert_to_flac, wav_files), total=len(wav_files)) as pbar:
48+
with tqdm(
49+
pool.imap_unordered(convert_to_flac, wav_files), total=len(wav_files)
50+
) as pbar:
3751
for success in pbar:
3852
if success:
3953
success_counter += 1
4054
else:
4155
fail_counter += 1
42-
56+
4357
pbar.set_description(f"Success: {success_counter}, Fail: {fail_counter}")
4458

4559
print(f"Successfully converted: {success_counter}")

0 commit comments

Comments
 (0)