Skip to content

Commit

Permalink
support for official audio loader
Browse files Browse the repository at this point in the history
  • Loading branch information
hay86 committed Jul 30, 2024
1 parent 1323282 commit 333f6e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
21 changes: 16 additions & 5 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import yaml
import torch
import random
import torchaudio
import folder_paths
import numpy as np
from PIL import Image
Expand Down Expand Up @@ -93,7 +94,7 @@ def INPUT_TYPES(s):
files.append(f)
return {"required": {
"source_image": ("IMAGE", ),
"driving_audio": (sorted(files), ),
"driving_audio": ("AUDIO", ),
"pose_weight" :("FLOAT",{"default": 1.0}),
"face_weight":("FLOAT",{"default": 1.0}),
"lip_weight":("FLOAT",{"default": 1.0}),
Expand Down Expand Up @@ -147,10 +148,20 @@ def inference(self, source_image, driving_audio, pose_weight, face_weight, lip_w
print(f'saved src image to {src_img_path}')
break

# get src audio
src_audio_path = os.path.join(folder_paths.get_input_directory(), driving_audio)
if not os.path.exists(src_audio_path):
src_audio_path = driving_audio # absolute path
# # get src audio
# src_audio_path = os.path.join(folder_paths.get_input_directory(), driving_audio)
# if not os.path.exists(src_audio_path):
# src_audio_path = driving_audio # absolute path

# save audio to path
waveform = driving_audio["waveform"]
sample_rate = driving_audio["sample_rate"]

if waveform.dim() == 3:
waveform = waveform.squeeze(0)

src_audio_path = os.path.join(output_dir, f"hallo_{output_name}_src_audio.wav")
torchaudio.save(src_audio_path, waveform, sample_rate)

env = ':'.join([os.environ.get('PYTHONPATH', ''), cur_dir])
cmd = f"""PYTHONPATH={env} python {infer_py} --config "{tmp_yaml_path}" --source_image "{src_img_path}" --driving_audio "{src_audio_path}" --output {output_video_path} --pose_weight {pose_weight} --face_weight {face_weight} --lip_weight {lip_weight} --face_expand_ratio {face_expand_ratio}"""
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ pre-commit
accelerate
xformers
torch
torchaudio
numpy
opencv-python

0 comments on commit 333f6e7

Please sign in to comment.