Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and leng-yue committed Oct 11, 2023
1 parent 5b00752 commit e895c54
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
16 changes: 9 additions & 7 deletions tools/tts/batch/clean_wenet_speech.py
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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(
Expand Down
27 changes: 22 additions & 5 deletions tools/tts/batch/convert_to_wav.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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,
)
Expand All @@ -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/")

Expand All @@ -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}")
Expand Down
24 changes: 19 additions & 5 deletions tools/tts/batch/to_flac.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
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")
dst_file_path.parent.mkdir(parents=True, exist_ok=True)

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,
)
Expand All @@ -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}")
Expand Down

0 comments on commit e895c54

Please sign in to comment.