From e895c5418d63a8b8f5ffa746a19282e4248a6527 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 00:20:46 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tools/tts/batch/clean_wenet_speech.py | 16 +++++++++------- tools/tts/batch/convert_to_wav.py | 27 ++++++++++++++++++++++----- tools/tts/batch/to_flac.py | 24 +++++++++++++++++++----- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/tools/tts/batch/clean_wenet_speech.py b/tools/tts/batch/clean_wenet_speech.py index 13b3ec66..3d73b429 100644 --- a/tools/tts/batch/clean_wenet_speech.py +++ b/tools/tts/batch/clean_wenet_speech.py @@ -1,20 +1,20 @@ import json -from pathlib import Path +import os import subprocess +import tempfile +import time +from pathlib import Path import librosa import soundfile as sf import torch import torchaudio from fish_audio_preprocess.utils.separate_audio import ( - separate_audio, - merge_tracks, init_model, + merge_tracks, + separate_audio, ) from tqdm import tqdm -import time -import os -import tempfile rank = int(os.environ.get("SLURM_PROCID", 0)) world_size = int(os.environ.get("SLURM_NTASKS", 1)) @@ -75,7 +75,9 @@ def main(): ) # Make it 2 channels audio = torch.cat([audio, audio], dim=0) - tracks = separate_audio(demucs, audio, shifts=1, num_workers=0, progress=False) + tracks = separate_audio( + demucs, audio, shifts=1, num_workers=0, progress=False + ) audio = merge_tracks(tracks, filter=["vocals"])[0] vocals, sr = ( torchaudio.functional.resample( diff --git a/tools/tts/batch/convert_to_wav.py b/tools/tts/batch/convert_to_wav.py index 30163929..e326b70b 100644 --- a/tools/tts/batch/convert_to_wav.py +++ b/tools/tts/batch/convert_to_wav.py @@ -1,8 +1,10 @@ -from pathlib import Path +import random import subprocess from multiprocessing import Pool, cpu_count +from pathlib import Path + from tqdm import tqdm -import random + def convert_to_wav(src_file_path): 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): try: subprocess.check_call( - ["ffmpeg", "-y", "-i", str(src_file_path), "-c:a", "pcm_s16le", "-threads", "0", "-ar", "24000", str(dst_file_path)], + [ + "ffmpeg", + "-y", + "-i", + str(src_file_path), + "-c:a", + "pcm_s16le", + "-threads", + "0", + "-ar", + "24000", + str(dst_file_path), + ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) @@ -24,6 +38,7 @@ def convert_to_wav(src_file_path): except subprocess.CalledProcessError: return False + src_dir = Path("dataset/tts/WenetSpeech/audio/") dst_dir = Path("dataset/tts/WenetSpeech/audio_wav/") @@ -35,13 +50,15 @@ def convert_to_wav(src_file_path): fail_counter = 0 with Pool(processes=cpu_count() * 2, maxtasksperchild=100) as pool: - with tqdm(pool.imap_unordered(convert_to_wav, opus_files), total=len(opus_files)) as pbar: + with tqdm( + pool.imap_unordered(convert_to_wav, opus_files), total=len(opus_files) + ) as pbar: for success in pbar: if success: success_counter += 1 else: fail_counter += 1 - + pbar.set_description(f"Success: {success_counter}, Fail: {fail_counter}") print(f"Successfully converted: {success_counter}") diff --git a/tools/tts/batch/to_flac.py b/tools/tts/batch/to_flac.py index 26efa43e..b1f4e92d 100644 --- a/tools/tts/batch/to_flac.py +++ b/tools/tts/batch/to_flac.py @@ -1,8 +1,10 @@ -from pathlib import Path +import random import subprocess from multiprocessing import Pool, cpu_count +from pathlib import Path + from tqdm import tqdm -import random + def convert_to_flac(src_file_path): dst_file_path = src_file_path.with_suffix(".flac") @@ -10,7 +12,17 @@ def convert_to_flac(src_file_path): try: subprocess.check_call( - ["ffmpeg", "-y", "-i", str(src_file_path), "-acodec", "flac", "-threads", "0", str(dst_file_path)], + [ + "ffmpeg", + "-y", + "-i", + str(src_file_path), + "-acodec", + "flac", + "-threads", + "0", + str(dst_file_path), + ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) @@ -33,13 +45,15 @@ def convert_to_flac(src_file_path): fail_counter = 0 with Pool(processes=cpu_count(), maxtasksperchild=100) as pool: - with tqdm(pool.imap_unordered(convert_to_flac, wav_files), total=len(wav_files)) as pbar: + with tqdm( + pool.imap_unordered(convert_to_flac, wav_files), total=len(wav_files) + ) as pbar: for success in pbar: if success: success_counter += 1 else: fail_counter += 1 - + pbar.set_description(f"Success: {success_counter}, Fail: {fail_counter}") print(f"Successfully converted: {success_counter}")