Upload 4 files
Browse files
processors/modules/lip_syncer/choices.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Sequence, get_args
|
| 2 |
+
|
| 3 |
+
from facefusion.common_helper import create_float_range
|
| 4 |
+
from facefusion.processors.modules.lip_syncer.types import LipSyncerModel
|
| 5 |
+
|
| 6 |
+
lip_syncer_models : List[LipSyncerModel] = list(get_args(LipSyncerModel))
|
| 7 |
+
|
| 8 |
+
lip_syncer_weight_range : Sequence[float] = create_float_range(0.0, 1.0, 0.05)
|
processors/modules/lip_syncer/core.py
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from argparse import ArgumentParser
|
| 2 |
+
from functools import lru_cache
|
| 3 |
+
from types import ModuleType
|
| 4 |
+
from typing import List
|
| 5 |
+
|
| 6 |
+
import cv2
|
| 7 |
+
import numpy
|
| 8 |
+
|
| 9 |
+
import facefusion.jobs.job_manager
|
| 10 |
+
import facefusion.jobs.job_store
|
| 11 |
+
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, state_manager, translator, video_manager, voice_extractor
|
| 12 |
+
from facefusion.audio import read_static_voice
|
| 13 |
+
from facefusion.common_helper import create_float_metavar, get_middle
|
| 14 |
+
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
| 15 |
+
from facefusion.face_creator import scale_face
|
| 16 |
+
from facefusion.face_helper import create_bounding_box, paste_back, warp_face_by_bounding_box, warp_face_by_face_landmark_5
|
| 17 |
+
from facefusion.face_masker import create_area_mask, create_box_mask, create_occlusion_mask
|
| 18 |
+
from facefusion.face_selector import select_faces
|
| 19 |
+
from facefusion.filesystem import has_audio, resolve_relative_path
|
| 20 |
+
from facefusion.processors.modules.lip_syncer import choices as lip_syncer_choices
|
| 21 |
+
from facefusion.processors.modules.lip_syncer.types import LipSyncerInputs, LipSyncerWeight
|
| 22 |
+
from facefusion.processors.types import ProcessorOutputs
|
| 23 |
+
from facefusion.program_helper import find_argument_group
|
| 24 |
+
from facefusion.thread_helper import conditional_thread_semaphore
|
| 25 |
+
from facefusion.types import ApplyStateItem, Args, AudioFrame, DownloadScope, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, VisionFrame
|
| 26 |
+
from facefusion.vision import read_static_image, read_static_video_frame
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@lru_cache()
|
| 30 |
+
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
| 31 |
+
return\
|
| 32 |
+
{
|
| 33 |
+
'edtalk_256':
|
| 34 |
+
{
|
| 35 |
+
'__metadata__':
|
| 36 |
+
{
|
| 37 |
+
'vendor': 'tanshuai0219',
|
| 38 |
+
'license': 'Apache-2.0',
|
| 39 |
+
'year': 2024
|
| 40 |
+
},
|
| 41 |
+
'hashes':
|
| 42 |
+
{
|
| 43 |
+
'lip_syncer':
|
| 44 |
+
{
|
| 45 |
+
'url': resolve_download_url('models-3.3.0', 'edtalk_256.hash'),
|
| 46 |
+
'path': resolve_relative_path('../.assets/models/edtalk_256.hash')
|
| 47 |
+
}
|
| 48 |
+
},
|
| 49 |
+
'sources':
|
| 50 |
+
{
|
| 51 |
+
'lip_syncer':
|
| 52 |
+
{
|
| 53 |
+
'url': resolve_download_url('models-3.3.0', 'edtalk_256.onnx'),
|
| 54 |
+
'path': resolve_relative_path('../.assets/models/edtalk_256.onnx')
|
| 55 |
+
}
|
| 56 |
+
},
|
| 57 |
+
'type': 'edtalk',
|
| 58 |
+
'size': (256, 256)
|
| 59 |
+
},
|
| 60 |
+
'wav2lip_96':
|
| 61 |
+
{
|
| 62 |
+
'__metadata__':
|
| 63 |
+
{
|
| 64 |
+
'vendor': 'Rudrabha',
|
| 65 |
+
'license': 'Non-Commercial',
|
| 66 |
+
'year': 2020
|
| 67 |
+
},
|
| 68 |
+
'hashes':
|
| 69 |
+
{
|
| 70 |
+
'lip_syncer':
|
| 71 |
+
{
|
| 72 |
+
'url': resolve_download_url('models-3.0.0', 'wav2lip_96.hash'),
|
| 73 |
+
'path': resolve_relative_path('../.assets/models/wav2lip_96.hash')
|
| 74 |
+
}
|
| 75 |
+
},
|
| 76 |
+
'sources':
|
| 77 |
+
{
|
| 78 |
+
'lip_syncer':
|
| 79 |
+
{
|
| 80 |
+
'url': resolve_download_url('models-3.0.0', 'wav2lip_96.onnx'),
|
| 81 |
+
'path': resolve_relative_path('../.assets/models/wav2lip_96.onnx')
|
| 82 |
+
}
|
| 83 |
+
},
|
| 84 |
+
'type': 'wav2lip',
|
| 85 |
+
'size': (96, 96)
|
| 86 |
+
},
|
| 87 |
+
'wav2lip_gan_96':
|
| 88 |
+
{
|
| 89 |
+
'__metadata__':
|
| 90 |
+
{
|
| 91 |
+
'vendor': 'Rudrabha',
|
| 92 |
+
'license': 'Non-Commercial',
|
| 93 |
+
'year': 2020
|
| 94 |
+
},
|
| 95 |
+
'hashes':
|
| 96 |
+
{
|
| 97 |
+
'lip_syncer':
|
| 98 |
+
{
|
| 99 |
+
'url': resolve_download_url('models-3.0.0', 'wav2lip_gan_96.hash'),
|
| 100 |
+
'path': resolve_relative_path('../.assets/models/wav2lip_gan_96.hash')
|
| 101 |
+
}
|
| 102 |
+
},
|
| 103 |
+
'sources':
|
| 104 |
+
{
|
| 105 |
+
'lip_syncer':
|
| 106 |
+
{
|
| 107 |
+
'url': resolve_download_url('models-3.0.0', 'wav2lip_gan_96.onnx'),
|
| 108 |
+
'path': resolve_relative_path('../.assets/models/wav2lip_gan_96.onnx')
|
| 109 |
+
}
|
| 110 |
+
},
|
| 111 |
+
'type': 'wav2lip',
|
| 112 |
+
'size': (96, 96)
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def get_inference_pool() -> InferencePool:
|
| 118 |
+
model_names = [ state_manager.get_item('lip_syncer_model') ]
|
| 119 |
+
model_source_set = get_model_options().get('sources')
|
| 120 |
+
|
| 121 |
+
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def clear_inference_pool() -> None:
|
| 125 |
+
model_names = [ state_manager.get_item('lip_syncer_model') ]
|
| 126 |
+
inference_manager.clear_inference_pool(__name__, model_names)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def get_model_options() -> ModelOptions:
|
| 130 |
+
model_name = state_manager.get_item('lip_syncer_model')
|
| 131 |
+
return create_static_model_set('full').get(model_name)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def register_args(program : ArgumentParser) -> None:
|
| 135 |
+
group_processors = find_argument_group(program, 'processors')
|
| 136 |
+
if group_processors:
|
| 137 |
+
group_processors.add_argument('--lip-syncer-model', help = translator.get('help.model', __package__), default = config.get_str_value('processors', 'lip_syncer_model', 'wav2lip_gan_96'), choices = lip_syncer_choices.lip_syncer_models)
|
| 138 |
+
group_processors.add_argument('--lip-syncer-weight', help = translator.get('help.weight', __package__), type = float, default = config.get_float_value('processors', 'lip_syncer_weight', '0.5'), choices = lip_syncer_choices.lip_syncer_weight_range, metavar = create_float_metavar(lip_syncer_choices.lip_syncer_weight_range))
|
| 139 |
+
facefusion.jobs.job_store.register_step_keys([ 'lip_syncer_model', 'lip_syncer_weight' ])
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
| 143 |
+
apply_state_item('lip_syncer_model', args.get('lip_syncer_model'))
|
| 144 |
+
apply_state_item('lip_syncer_weight', args.get('lip_syncer_weight'))
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def get_common_modules() -> List[ModuleType]:
|
| 148 |
+
return [ content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, voice_extractor ]
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def pre_check() -> bool:
|
| 152 |
+
model_hash_set = get_model_options().get('hashes')
|
| 153 |
+
model_source_set = get_model_options().get('sources')
|
| 154 |
+
|
| 155 |
+
for common_module in get_common_modules():
|
| 156 |
+
if not common_module.pre_check():
|
| 157 |
+
return False
|
| 158 |
+
|
| 159 |
+
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def pre_process(mode : ProcessMode) -> bool:
|
| 163 |
+
if not has_audio(state_manager.get_item('source_paths')):
|
| 164 |
+
logger.error(translator.get('choose_audio_source') + translator.get('exclamation_mark'), __name__)
|
| 165 |
+
return False
|
| 166 |
+
return True
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def post_process() -> None:
|
| 170 |
+
read_static_image.cache_clear()
|
| 171 |
+
read_static_video_frame.cache_clear()
|
| 172 |
+
read_static_voice.cache_clear()
|
| 173 |
+
video_manager.clear_video_pool()
|
| 174 |
+
|
| 175 |
+
if state_manager.get_item('video_memory_strategy') in [ 'strict', 'moderate' ]:
|
| 176 |
+
clear_inference_pool()
|
| 177 |
+
|
| 178 |
+
if state_manager.get_item('video_memory_strategy') == 'strict':
|
| 179 |
+
for common_module in get_common_modules():
|
| 180 |
+
common_module.clear_inference_pool()
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def sync_lip(target_face : Face, source_voice_frame : AudioFrame, temp_vision_frame : VisionFrame) -> VisionFrame:
|
| 184 |
+
model_type = get_model_options().get('type')
|
| 185 |
+
model_size = get_model_options().get('size')
|
| 186 |
+
source_voice_frame = prepare_audio_frame(source_voice_frame)
|
| 187 |
+
crop_vision_frame, affine_matrix = warp_face_by_face_landmark_5(temp_vision_frame, target_face.landmark_set.get('5/68'), 'ffhq_512', (512, 512))
|
| 188 |
+
crop_masks = []
|
| 189 |
+
|
| 190 |
+
if 'occlusion' in state_manager.get_item('face_mask_types'):
|
| 191 |
+
occlusion_mask = create_occlusion_mask(crop_vision_frame)
|
| 192 |
+
crop_masks.append(occlusion_mask)
|
| 193 |
+
|
| 194 |
+
if model_type == 'edtalk':
|
| 195 |
+
lip_syncer_weight = numpy.array([ state_manager.get_item('lip_syncer_weight') ]).astype(numpy.float32)
|
| 196 |
+
box_mask = create_box_mask(crop_vision_frame, state_manager.get_item('face_mask_blur'), state_manager.get_item('face_mask_padding'))
|
| 197 |
+
crop_masks.append(box_mask)
|
| 198 |
+
crop_vision_frame = prepare_crop_frame(crop_vision_frame)
|
| 199 |
+
crop_vision_frame = forward_edtalk(source_voice_frame, crop_vision_frame, lip_syncer_weight)
|
| 200 |
+
crop_vision_frame = normalize_crop_frame(crop_vision_frame)
|
| 201 |
+
|
| 202 |
+
if model_type == 'wav2lip':
|
| 203 |
+
face_landmark_68 = cv2.transform(target_face.landmark_set.get('68').reshape(1, -1, 2), affine_matrix).reshape(-1, 2)
|
| 204 |
+
area_mask = create_area_mask(crop_vision_frame, face_landmark_68, [ 'lower-face' ])
|
| 205 |
+
crop_masks.append(area_mask)
|
| 206 |
+
bounding_box = create_bounding_box(face_landmark_68)
|
| 207 |
+
area_vision_frame, area_matrix = warp_face_by_bounding_box(crop_vision_frame, bounding_box, model_size)
|
| 208 |
+
area_vision_frame = prepare_crop_frame(area_vision_frame)
|
| 209 |
+
area_vision_frame = forward_wav2lip(source_voice_frame, area_vision_frame)
|
| 210 |
+
area_vision_frame = normalize_crop_frame(area_vision_frame)
|
| 211 |
+
crop_vision_frame = cv2.warpAffine(area_vision_frame, cv2.invertAffineTransform(area_matrix), (512, 512), borderMode = cv2.BORDER_REPLICATE)
|
| 212 |
+
|
| 213 |
+
crop_mask = numpy.minimum.reduce(crop_masks)
|
| 214 |
+
paste_vision_frame = paste_back(temp_vision_frame, crop_vision_frame, crop_mask, affine_matrix)
|
| 215 |
+
return paste_vision_frame
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
def forward_edtalk(temp_audio_frame : AudioFrame, crop_vision_frame : VisionFrame, lip_syncer_weight : LipSyncerWeight) -> VisionFrame:
|
| 219 |
+
lip_syncer = get_inference_pool().get('lip_syncer')
|
| 220 |
+
|
| 221 |
+
with conditional_thread_semaphore():
|
| 222 |
+
crop_vision_frame = lip_syncer.run(None,
|
| 223 |
+
{
|
| 224 |
+
'source': temp_audio_frame,
|
| 225 |
+
'target': crop_vision_frame,
|
| 226 |
+
'weight': lip_syncer_weight
|
| 227 |
+
})[0]
|
| 228 |
+
|
| 229 |
+
return crop_vision_frame
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def forward_wav2lip(temp_audio_frame : AudioFrame, area_vision_frame : VisionFrame) -> VisionFrame:
|
| 233 |
+
lip_syncer = get_inference_pool().get('lip_syncer')
|
| 234 |
+
|
| 235 |
+
with conditional_thread_semaphore():
|
| 236 |
+
area_vision_frame = lip_syncer.run(None,
|
| 237 |
+
{
|
| 238 |
+
'source': temp_audio_frame,
|
| 239 |
+
'target': area_vision_frame
|
| 240 |
+
})[0]
|
| 241 |
+
|
| 242 |
+
return area_vision_frame
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def prepare_audio_frame(temp_audio_frame : AudioFrame) -> AudioFrame:
|
| 246 |
+
model_type = get_model_options().get('type')
|
| 247 |
+
temp_audio_frame = numpy.maximum(numpy.exp(-5 * numpy.log(10)), temp_audio_frame)
|
| 248 |
+
temp_audio_frame = numpy.log10(temp_audio_frame) * 1.6 + 3.2
|
| 249 |
+
temp_audio_frame = temp_audio_frame.clip(-4, 4).astype(numpy.float32)
|
| 250 |
+
|
| 251 |
+
if model_type == 'wav2lip':
|
| 252 |
+
temp_audio_frame = temp_audio_frame * state_manager.get_item('lip_syncer_weight') * 2.0
|
| 253 |
+
|
| 254 |
+
temp_audio_frame = numpy.expand_dims(temp_audio_frame, axis = (0, 1))
|
| 255 |
+
return temp_audio_frame
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def prepare_crop_frame(crop_vision_frame : VisionFrame) -> VisionFrame:
|
| 259 |
+
model_type = get_model_options().get('type')
|
| 260 |
+
model_size = get_model_options().get('size')
|
| 261 |
+
|
| 262 |
+
if model_type == 'edtalk':
|
| 263 |
+
crop_vision_frame = cv2.resize(crop_vision_frame, model_size, interpolation = cv2.INTER_AREA)
|
| 264 |
+
crop_vision_frame = crop_vision_frame[:, :, ::-1] / 255.0
|
| 265 |
+
crop_vision_frame = numpy.expand_dims(crop_vision_frame.transpose(2, 0, 1), axis = 0).astype(numpy.float32)
|
| 266 |
+
|
| 267 |
+
if model_type == 'wav2lip':
|
| 268 |
+
crop_vision_frame = numpy.expand_dims(crop_vision_frame, axis = 0)
|
| 269 |
+
prepare_vision_frame = crop_vision_frame.copy()
|
| 270 |
+
prepare_vision_frame[:, model_size[0] // 2:] = 0
|
| 271 |
+
crop_vision_frame = numpy.concatenate((prepare_vision_frame, crop_vision_frame), axis = 3)
|
| 272 |
+
crop_vision_frame = crop_vision_frame.transpose(0, 3, 1, 2).astype(numpy.float32) / 255.0
|
| 273 |
+
|
| 274 |
+
return crop_vision_frame
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def normalize_crop_frame(crop_vision_frame : VisionFrame) -> VisionFrame:
|
| 278 |
+
model_type = get_model_options().get('type')
|
| 279 |
+
crop_vision_frame = crop_vision_frame[0].transpose(1, 2, 0)
|
| 280 |
+
crop_vision_frame = crop_vision_frame.clip(0, 1) * 255
|
| 281 |
+
crop_vision_frame = crop_vision_frame.astype(numpy.uint8)
|
| 282 |
+
|
| 283 |
+
if model_type == 'edtalk':
|
| 284 |
+
crop_vision_frame = crop_vision_frame[:, :, ::-1]
|
| 285 |
+
crop_vision_frame = cv2.resize(crop_vision_frame, (512, 512), interpolation = cv2.INTER_CUBIC)
|
| 286 |
+
|
| 287 |
+
return crop_vision_frame
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
def process_frame(inputs : LipSyncerInputs) -> ProcessorOutputs:
|
| 291 |
+
reference_vision_frame = inputs.get('reference_vision_frame')
|
| 292 |
+
source_vision_frames = inputs.get('source_vision_frames')
|
| 293 |
+
source_voice_frame = inputs.get('source_voice_frame')
|
| 294 |
+
target_vision_frames = inputs.get('target_vision_frames')
|
| 295 |
+
temp_vision_frame = inputs.get('temp_vision_frame')
|
| 296 |
+
temp_vision_mask = inputs.get('temp_vision_mask')
|
| 297 |
+
|
| 298 |
+
target_vision_frame = get_middle(target_vision_frames)
|
| 299 |
+
target_faces = select_faces(reference_vision_frame, source_vision_frames, target_vision_frames)
|
| 300 |
+
|
| 301 |
+
if target_faces:
|
| 302 |
+
for target_face in target_faces:
|
| 303 |
+
target_face = scale_face(target_face, target_vision_frame, temp_vision_frame)
|
| 304 |
+
temp_vision_frame = sync_lip(target_face, source_voice_frame, temp_vision_frame)
|
| 305 |
+
|
| 306 |
+
return temp_vision_frame, temp_vision_mask
|
processors/modules/lip_syncer/locales.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from facefusion.types import Locales
|
| 2 |
+
|
| 3 |
+
LOCALES : Locales =\
|
| 4 |
+
{
|
| 5 |
+
'en':
|
| 6 |
+
{
|
| 7 |
+
'help':
|
| 8 |
+
{
|
| 9 |
+
'model': 'choose the model responsible for syncing the lips',
|
| 10 |
+
'weight': 'specify the degree of weight applied to the lips'
|
| 11 |
+
},
|
| 12 |
+
'uis':
|
| 13 |
+
{
|
| 14 |
+
'model_dropdown': 'LIP SYNCER MODEL',
|
| 15 |
+
'weight_slider': 'LIP SYNCER WEIGHT'
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
}
|
processors/modules/lip_syncer/types.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, List, Literal, TypeAlias, TypedDict
|
| 2 |
+
|
| 3 |
+
from numpy.typing import NDArray
|
| 4 |
+
|
| 5 |
+
from facefusion.types import AudioFrame, Mask, VisionFrame
|
| 6 |
+
|
| 7 |
+
LipSyncerInputs = TypedDict('LipSyncerInputs',
|
| 8 |
+
{
|
| 9 |
+
'reference_vision_frame' : VisionFrame,
|
| 10 |
+
'source_vision_frames' : List[VisionFrame],
|
| 11 |
+
'source_voice_frame' : AudioFrame,
|
| 12 |
+
'target_vision_frames' : List[VisionFrame],
|
| 13 |
+
'temp_vision_frame' : VisionFrame,
|
| 14 |
+
'temp_vision_mask' : Mask
|
| 15 |
+
})
|
| 16 |
+
|
| 17 |
+
LipSyncerModel = Literal['edtalk_256', 'wav2lip_96', 'wav2lip_gan_96']
|
| 18 |
+
|
| 19 |
+
LipSyncerWeight : TypeAlias = NDArray[Any]
|