Spaces:
Running
Running
File size: 1,651 Bytes
a8c8d73 17263d1 a8c8d73 17263d1 ba051ef a8c8d73 17263d1 ba051ef a8c8d73 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
import librosa
import numpy as np
from pathlib import Path
from fsspec.registry import default
from scipy.io import wavfile
from tqdm import tqdm
from project_settings import project_path
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--audio_dir",
# default=(project_path / "data/yd").as_posix(),
default=r"E:\牛信文档\语音克隆\多语种语音克隆\money_char",
type=str,
)
parser.add_argument(
"--output_dir",
# default=(project_path / "data/temp_wav").as_posix(),
default=r"E:\牛信文档\语音克隆\多语种语音克隆\money_char",
type=str,
)
args = parser.parse_args()
return args
def main():
args = get_args()
audio_dir = Path(args.audio_dir)
output_dir = Path(args.output_dir)
output_dir.mkdir(parents=True, exist_ok=True)
max_wave_value = 32768.0
for filename in tqdm(audio_dir.glob("**/*.wav")):
basename = filename.stem
relative_dir = filename.parent.relative_to(audio_dir)
signal, sample_rate = librosa.load(filename, sr=8000)
# print(signal.shape)
# print(signal.dtype)
# exit(0)
signal *= max_wave_value
signal = np.array(signal, dtype=np.int16)
output_filename = output_dir / relative_dir / f"{basename}.wav"
output_filename.parent.mkdir(parents=True, exist_ok=True)
wavfile.write(
output_filename.as_posix(),
8000,
signal,
)
return
if __name__ == "__main__":
main()
|