Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update process.py #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions data_utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import cv2
import argparse
import numpy as np
from tqdm import tqdm


def extract_audio(path, out_path, sample_rate=16000):

Expand All @@ -24,15 +26,15 @@ def extract_images(path, mode):
raise ValueError("Using hubert,your video fps should be 25!!!")
if mode == "wenet" and fps != 20:
raise ValueError("Using wenet,your video fps should be 20!!!")

print("extracting images...")
while True:
ret, frame = cap.read()
if not ret:
break
cv2.imwrite(full_body_dir+"/"+str(counter)+'.jpg', frame)
counter += 1

def get_audio_feature(wav_path, mode):

print("extracting audio feature...")
Expand All @@ -49,7 +51,7 @@ def get_landmark(path, landmarks_dir):
from get_landmark import Landmark
landmark = Landmark()

for img_name in os.listdir(full_img_dir):
for img_name in tqdm(os.listdir(full_img_dir)):
if not img_name.endswith(".jpg"):
continue
img_path = os.path.join(full_img_dir, img_name)
Expand All @@ -64,12 +66,15 @@ def get_landmark(path, landmarks_dir):
f.write("\n")

if __name__ == "__main__":

parser = argparse.ArgumentParser()
parser.add_argument('path', type=str, help="path to video file")
parser.add_argument('--asr', type=str, default='hubert', help="wenet or hubert")
parser.add_argument('--device_id', type=int, default=0, help="gpu id")
opt = parser.parse_args()
asr_mode = opt.asr

print('Using gpu id: {}'.format(opt.device_id))
os.environ['CUDA_VISIBLE_DEVICES'] = str(opt.device_id)

base_dir = os.path.dirname(opt.path)
wav_path = os.path.join(base_dir, 'aud.wav')
Expand All @@ -81,5 +86,3 @@ def get_landmark(path, landmarks_dir):
extract_images(opt.path, asr_mode)
get_landmark(opt.path, landmarks_dir)
get_audio_feature(wav_path, asr_mode)