international_voice / examples /channel_dual_to_single.py
HoneyTian's picture
update
7661f93
raw
history blame
1.25 kB
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
import os
from pathlib import Path
from scipy.io import wavfile
from tqdm import tqdm
from project_settings import project_path
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--wav_dir",
default=(project_path / "data/early_media/234/wav").as_posix(),
type=str
)
args = parser.parse_args()
return args
def main():
args = get_args()
wav_dir = Path(args.wav_dir)
for filename in tqdm(wav_dir.glob("*.wav")):
print(filename)
try:
sample_rate, signal = wavfile.read(filename)
except UnboundLocalError:
os.remove(filename)
continue
if sample_rate != 8000:
raise AssertionError
if len(signal) < 1.0 * sample_rate:
os.remove(filename.as_posix())
continue
# print(signal.shape)
if signal.ndim != 2:
continue
signal = signal[:, 0]
# print(signal.shape)
wavfile.write(filename.as_posix(), rate=8000, data=signal)
# wavfile.write("temp2.wav", rate=8000, data=signal)
# exit(0)
return
if __name__ == '__main__':
main()