HoneyTian's picture
update
7661f93
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
ASR:
https://cloud.tencent.com/product/asr#mod2
https://huggingface.co/spaces/sanchit-gandhi/whisper-large-v2
https://huggingface.co/spaces/hf-audio/whisper-large-v3
"""
import argparse
from pathlib import Path
import numpy as np
from python_speech_features import sigproc
from scipy.io import wavfile
from tqdm import tqdm
from project_settings import project_path
area_code = 60
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--filename",
default=(project_path / "data/early_media/60/wav/voice/early_vm_8ecb7ad6-0781-405e-9ede-c4a7622d53f9.wav").as_posix(),
type=str
)
parser.add_argument(
"--templates_segmented_dir",
default=(project_path / "data/early_media/{area_code}/temp".format(area_code=area_code)).as_posix(),
type=str
)
parser.add_argument("--win_size", default=2.0, type=float)
parser.add_argument("--win_len", default=0.5, type=float)
args = parser.parse_args()
return args
def main():
args = get_args()
filename = Path(args.filename)
templates_segmented_dir = Path(args.templates_segmented_dir)
templates_segmented_dir.mkdir(parents=True, exist_ok=True)
sample_rate, signal = wavfile.read(filename)
frames = sigproc.framesig(
sig=signal,
frame_len=args.win_size * sample_rate,
frame_step=args.win_len * sample_rate,
# winfunc=np.hamming
)
for j, frame in enumerate(frames):
to_filename = templates_segmented_dir / "{}_{}.wav".format(filename.stem, j)
frame = np.array(frame, dtype=np.int16)
wavfile.write(
filename=to_filename,
rate=sample_rate,
data=frame
)
return
if __name__ == '__main__':
main()