2025-07-01

This commit is contained in:
2026-03-17 14:30:01 -06:00
parent f9a22056dd
commit 62b5978595
4579 changed files with 1257472 additions and 0 deletions
@@ -0,0 +1,652 @@
from typing import Iterator, Literal, cast
import bpy
from .LIPSYNC2D_ShapeKeysAnimator import LIPSYNC2D_ShapeKeysAnimator
from ..phoneme_to_viseme import (
get_viseme_priority,
viseme_items_mpeg4_v2,
UNSKIPPABLE_VISEMES,
)
from ..Timeline.LIPSYNC2D_TimeConversion import LIPSYNC2D_TimeConversion
from ..constants import ACTION_SUFFIX_NAME, SLOT_POSE_ASSETS_NAME
from ..Timeline.LIPSYNC2D_Timeline import LIPSYNC2D_Timeline
from ..types import (
VisemeActionAnimationData,
VisemeData,
WordTiming,
)
from ...Preferences.LIPSYNC2D_AP_Preferences import LIPSYNC2D_AP_Preferences
from ...lipsync_types import (
BpyAction,
BpyActionChannelbag,
BpyActionKeyframeStrip,
BpyActionSlot,
BpyContext,
BpyObject,
BpyPropertyGroup,
)
class LIPSYNC2D_PoseAssetsAnimator:
"""
A class designed to manage lip-sync animation using pose assets in Blender.
This class provides methods for manipulating bone pose animations, including clearing
existing keyframes, setting up new animations, modifying interpolation types, and inserting
keyframes for viseme data using pose library assets.
:ivar _slot: Internal storage representing a reference to an action slot used in
the animation chain for lip-syncing (assigned during setup phase).
:type _slot: BpyActionSlot
"""
def __init__(self) -> None:
self._slot: BpyActionSlot | None = None
self.pose_assets_actions: dict[str, bpy.types.Action]
self.silence_frame_threshold: float = -1
self.in_between_frame_threshold: float = -1
self.previous_start: int = -1
self.previous_viseme: str | None = None
self.inserted_keyframes: int = 0
self.word_end_frame = -1
self.word_start_frame = -1
self.delay_until_next_word = -1
self.is_last_word = False
self.is_first_word = False
self.time_conversion = None
self.close_motion_duration = -1
self.channelbag: BpyActionChannelbag
self.armature: BpyObject | None = None
def get_armature_action(self, obj: BpyObject):
"""
Retrieves the action associated with the armature of the given object, if available.
This function checks if the provided object has an armature with animation data.
If the armature is present and has associated animation data with an assigned action,
the function returns the action. If any of these conditions fail, the function returns None.
:param obj: The armature object to retrieve the action from.
:type obj: BpyObject
:return: The action associated with the armature's animation data if available, otherwise None.
:rtype: BpyAction or None
"""
if not isinstance(obj.data, bpy.types.Armature):
return None
if (
self.armature
and self.armature.animation_data
and self.armature.animation_data.action
):
return self.armature.animation_data.action
return None
def clear_previous_keyframes(self, obj: BpyObject):
"""
Clears all previous keyframes from the armature action's channelbag for
the provided object, ensuring the removal of existing animation
data within the specified context.
:param obj: The Blender armature object from which previous keyframes are to be
cleared. Must have an armature data type.
:type obj: BpyObject
:return: This function does not return any value. If the provided object
does not meet the required conditions (e.g., not an armature or has no
trackable action), the function terminates without modification.
:rtype: None
"""
if not isinstance(obj.data, bpy.types.Armature):
return
if (action := self.get_armature_action(obj)) is None:
return
strip = cast(BpyActionKeyframeStrip, action.layers[0].strips[0])
channelbag = strip.channelbag(self._slot, ensure=True)
for fcurve in channelbag.fcurves:
fcurve.keyframe_points.clear()
def insert_keyframes(
self,
obj: BpyObject,
props: BpyPropertyGroup,
visemes_data: VisemeData,
word_timing: WordTiming,
delay_until_next_word: int,
is_last_word: bool,
word_index: int,
):
"""
Insert viseme animations based on given viseme data, word timing, and properties. This function ensures
that the pose assets for lip-sync animations are manipulated and keyframed correctly for smooth transitions
between viseme states using bone poses. It also optionally adds a silence (SIL) pose asset at the end of a word
depending on specific conditions.
:param word_index: Word index
:param obj: The Blender armature object to insert visemes into.
:param props: Properties related to lipsync and pose asset data.
:param visemes_data: Data about visemes, including their order and division details.
:param word_timing: Timing information for the word's animation frames.
:param delay_until_next_word: A delay value used to determine if silence should be inserted between words.
:param is_last_word: Indicates whether the current word is the last word in the sequence.
:return: None
"""
# Initialize word properties
self.word_end_frame = word_timing["word_frame_end"]
self.word_start_frame = word_timing["word_frame_start"]
self.delay_until_next_word = max(0, delay_until_next_word)
self.is_last_word = is_last_word
self.is_first_word = word_index == 0
# Insert silences before or after word when needed
self.insert_silences(visemes_data, word_index)
# Iterate through visemes and insert keyframes on time
for action_anim_data in self._insert_on_visemes(
obj, props, visemes_data, word_timing
):
if (action := action_anim_data["action"]) is None:
continue
self.insert_keyframe_points(action, action_anim_data["frame"])
def insert_keyframe_points(
self,
pose_action: BpyAction,
frame: int,
interpolation: Literal["LINEAR"] = "LINEAR",
):
"""
Inserts keyframe points from a pose asset action into the target armature action.
This method copies bone transform values from the pose asset's F-curves and inserts
them as keyframes at the specified frame in the target armature's action.
:param pose_action: The pose asset action containing the bone poses to copy.
:type pose_action: BpyAction
:param frame: The frame number where keyframes should be inserted.
:type frame: int
:param interpolation: The interpolation type for the keyframes.
:type interpolation: Literal["LINEAR"]
"""
for fcurve in self.channelbag.fcurves:
pose_asset_fcurve = pose_action.fcurves.find(
fcurve.data_path, index=fcurve.array_index
)
if pose_asset_fcurve is None:
continue
# Since Action is from a Pose Asset, we can safely assume that first keyframe point holds the Pose
fcurve_value = pose_asset_fcurve.keyframe_points[0].co.y
kframe = fcurve.keyframe_points.insert(
frame,
value=fcurve_value,
)
kframe.interpolation = interpolation
self.inserted_keyframes += 1
def insert_silences(self, visemes_data: VisemeData, word_index: int):
"""
Inserts silence pose assets at appropriate timing intervals.
This method adds silence poses (typically mouth closed positions) before the first word,
after the last word, and between words when there's sufficient delay.
:param visemes_data: Data about visemes, including their timing information.
:type visemes_data: VisemeData
:param word_index: The index of the current word being processed.
:type word_index: int
"""
add_sil_at_word_end = (
self.delay_until_next_word > self.silence_frame_threshold
) or self.is_last_word
action: BpyAction | None = getattr(self.props, f"lip_sync_2d_viseme_pose_sil")
if action is None:
return
if add_sil_at_word_end:
# Last viseme is inserted a bit before end of word. This ensures that silence uses correct timing
corrected_word_end_frame = (
LIPSYNC2D_ShapeKeysAnimator.get_corrected_end_frame(
self.word_start_frame, visemes_data
)
)
frame = corrected_word_end_frame + max(
1,
min(
self.delay_until_next_word - self.in_between_frame_threshold,
self.close_motion_duration,
),
)
if not self.is_last_word:
# Add silence after current word, with some delay to allow a smooth motion
# If close_motion_duration is too high, fallback to next word time-postion minus defined threshold
frame = corrected_word_end_frame + max(
1,
min(
self.delay_until_next_word - self.in_between_frame_threshold,
self.close_motion_duration,
),
)
self.insert_keyframe_points(action, int(frame))
frame = (
corrected_word_end_frame
+ self.delay_until_next_word
- max(1, self.in_between_frame_threshold)
)
self.insert_keyframe_points(action, int(frame))
else:
frame = corrected_word_end_frame + self.close_motion_duration
self.insert_keyframe_points(action, int(frame))
if self.is_first_word:
frame = max(
LIPSYNC2D_Timeline.get_frame_start(),
self.word_start_frame - max(1, self.close_motion_duration / 2),
)
self.insert_keyframe_points(action, int(frame))
def _insert_on_visemes(
self,
obj: BpyObject,
props: BpyPropertyGroup,
visemes_data: VisemeData,
word_timing: WordTiming,
) -> Iterator[VisemeActionAnimationData]:
"""
Generate viseme animation data for inserting pose asset keyframes based on viseme timing.
This function processes viseme data and yields animation information for each viseme,
ensuring that pose assets for lip-sync animations are applied correctly for smooth transitions
between bone pose states. It also handles timing and redundancy checks.
:param obj: The Blender armature object to insert visemes into.
:type obj: BpyObject
:param props: Properties related to lipsync and pose asset data.
:type props: BpyPropertyGroup
:param visemes_data: Data about visemes, including their order and division details.
:type visemes_data: VisemeData
:param word_timing: Timing information for the word's animation frames.
:type word_timing: WordTiming
:yield: Animation data for each viseme including frame, action, and metadata.
:rtype: Iterator[VisemeActionAnimationData]
"""
if not isinstance(obj.data, bpy.types.Armature):
yield {
"frame": -1,
"viseme": "",
"action": None,
"action_name": "",
"viseme_index": -1,
}
visemes = enumerate(visemes_data["visemes"])
for viseme_index, v in visemes:
self.is_last_viseme = (viseme_index + 1) == visemes_data["visemes_len"]
viseme_frame_start = word_timing["word_frame_start"] + round(
viseme_index * visemes_data["visemes_parts"]
)
if v not in self.pose_assets_actions:
continue
if self.should_skip_keyframe(props, v, viseme_frame_start):
continue
action_name: str = getattr(props, f"lip_sync_2d_viseme_pose_{v}")
action = self.pose_assets_actions[v]
yield {
"frame": viseme_frame_start,
"viseme": v,
"action": action,
"viseme_index": viseme_index,
"action_name": action_name,
}
self.previous_start = viseme_frame_start
self.previous_viseme = v
def should_skip_keyframe(self, props, v, viseme_frame_start):
# Skip if there's a priority conflict
if self.should_skip_due_to_priority_conflict(v, viseme_frame_start):
return True
# Skip if redundant with previous viseme
if self.is_redundant(props, v):
return True
# Handle timing conflicts
if self.is_prev_kframe_too_close(viseme_frame_start):
return self._should_skip_due_to_timing(props, v)
return False
def _should_skip_due_to_timing(self, props, v: str) -> bool:
"""Handle timing conflicts based on force_lips_contact setting"""
force_lips_contact = props.lip_sync_2d_prioritize_accuracy
is_unskippable = v.lower() in UNSKIPPABLE_VISEMES
if force_lips_contact:
# With force enabled: only skip skippable visemes
return not is_unskippable
else:
# Without force: skip all visemes that are too close
return True
def should_skip_due_to_priority_conflict(
self, current_viseme: str, frame: int
) -> bool:
"""Skip current viseme if previous viseme at same frame has higher priority."""
if not self.has_already_a_kframe(frame) or not self.previous_viseme:
return False
prev_priority = get_viseme_priority(self.previous_viseme)
current_priority = get_viseme_priority(current_viseme)
# Skip if current has lower priority (higher number)
return current_priority > prev_priority
def has_already_a_kframe(self, viseme_frame_start):
"""Check if a keyframe already exists at the specified frame."""
return viseme_frame_start == self.previous_start
def is_prev_kframe_too_close(self, viseme_frame_start):
"""Check if the previous keyframe is too close to the current frame."""
return self.previous_start >= 0 and (
viseme_frame_start - self.previous_start <= self.in_between_frame_threshold
)
def is_redundant(self, props: BpyPropertyGroup, v: str):
"""Check if the current viseme pose asset is the same as the previous one."""
if self.previous_viseme is None or self.previous_viseme == "sil":
return False
previous_viseme_prop_name = getattr(
props, f"lip_sync_2d_viseme_pose_{self.previous_viseme}"
)
viseme_prop_name = getattr(props, f"lip_sync_2d_viseme_pose_{v}")
return previous_viseme_prop_name == viseme_prop_name
def set_interpolation(self, obj: BpyObject):
"""Set interpolation type for pose asset keyframes (placeholder method)."""
pass
def setup(self, obj: BpyObject):
"""
Sets up the animation action and its components for the provided Blender armature object
if it meets the necessary conditions. Verifies the object's data type and animation
data, ensures that a specific action exists for lip-syncing with pose assets, and assigns
it to the armature's animation data.
:param obj: The Blender armature object for which the lip-sync animation is being set up.
Must have a data type of Armature and support animation data.
:type obj: BpyObject
:return: None if the object does not meet the specified conditions for setup.
:rtype: None
"""
self.setup_properties(obj)
self.setup_animation_properties(obj)
def setup_properties(self, obj: BpyObject):
"""
Initialize timing and threshold properties for pose asset animation.
This method sets up frame thresholds, timing conversions, and other properties
needed for smooth pose asset transitions during lip-sync animation.
:param obj: The Blender armature object being configured.
:type obj: BpyObject
"""
props = obj.lipsync2d_props # type: ignore
if bpy.context.scene is not None:
self.time_conversion = LIPSYNC2D_TimeConversion(bpy.context.scene.render)
self.close_motion_duration = self.time_conversion.time_to_frame(
props.lip_sync_2d_close_motion_duration
)
if self.time_conversion is None:
return
self.silence_frame_threshold = self.time_conversion.time_to_frame(
props.lip_sync_2d_sil_threshold
)
self.in_between_frame_threshold = self.time_conversion.time_to_frame(
props.lip_sync_2d_in_between_threshold
)
self.previous_start = -1
self.previous_viseme = None
self.inserted_keyframes = 0
self.props = props
self.armature = obj
def setup_animation_properties(self, obj: BpyObject):
"""
Set up animation-specific properties including actions and F-curves for pose assets.
:param obj: The Blender armature object to configure.
:type obj: BpyObject
"""
_, strip = self.set_up_action(obj)
if strip is None:
return
self.setup_fcurves(obj, strip)
def get_available_actions(self) -> dict[str, BpyAction]:
"""
Retrieve all available pose asset actions mapped to their corresponding visemes.
This method scans through all viseme properties and returns a dictionary mapping
viseme IDs to their associated pose asset actions.
:return: Dictionary mapping viseme IDs to pose asset actions.
:rtype: dict[str, BpyAction]
"""
visemes = viseme_items_mpeg4_v2(None, None)
available_actions: dict[str, BpyAction] = {
enum_id: key
for (enum_id, _, _) in visemes
if (key := getattr(self.props, f"lip_sync_2d_viseme_pose_{enum_id}"))
is not None
}
return available_actions
def setup_fcurves(self, obj: BpyObject, strip: BpyActionKeyframeStrip):
"""
Set up F-curves in the target armature action based on pose asset F-curves.
This method copies F-curve structure from pose assets to the target armature action,
creating the necessary bone channels and groups for animation. It supports both
basic and advanced rig types with appropriate filtering.
:param obj: The Blender armature object to set up F-curves for.
:type obj: BpyObject
:param strip: The action keyframe strip to work with.
:type strip: BpyActionKeyframeStrip
"""
if not isinstance(obj.data, bpy.types.Armature):
return
props = obj.lipsync2d_props # type: ignore
is_basic_rig = props.lip_sync_2d_rig_type_basic
self.pose_assets_actions = self.get_available_actions()
self.channelbag = strip.channelbag(self._slot, ensure=True)
fcurves = self.channelbag.fcurves
if props.lip_sync_2d_use_clear_keyframes:
fcurves.clear()
seen_actions = set()
bone_groups_cache = {}
for action in self.pose_assets_actions.values():
action_id = id(action)
if action_id in seen_actions:
continue
seen_actions.add(action_id)
if (
len(action.layers) == 0
or len(action.layers[0].strips) == 0
or not isinstance(
pose_strip := action.layers[0].strips[0],
bpy.types.ActionKeyframeStrip,
)
or len(action.slots) == 0
):
continue # Skip malformed pose asset actions
pose_channelbag = pose_strip.channelbag(action.slots[0])
for fcurve in pose_channelbag.fcurves:
if fcurves.find(fcurve.data_path, index=fcurve.array_index):
continue
property_name = fcurve.data_path.split(".")[-1]
if is_basic_rig and (
"bbone" in fcurve.data_path
or property_name
not in {
"location",
"rotation_euler",
"rotation_quaternion",
"scale",
}
):
continue
new_fcurve = fcurves.new(fcurve.data_path, index=fcurve.array_index)
if "pose.bones[" in fcurve.data_path:
bone_name = fcurve.data_path.split('"')[1]
if bone_name not in bone_groups_cache:
bone_groups_cache[bone_name] = self.channelbag.groups.get(
bone_name
) or self.channelbag.groups.new(bone_name)
new_fcurve.group = bone_groups_cache[bone_name]
def set_up_action(
self, obj: BpyObject
) -> tuple[BpyAction, BpyActionKeyframeStrip] | tuple[None, None]:
"""
Create or retrieve the main armature action for lip-sync animation.
This method ensures that the armature has proper animation data and creates
a dedicated action for lip-sync pose asset animation with the necessary
layers, strips, and slots.
:param obj: The Blender armature object to set up the action for.
:type obj: BpyObject
:return: Tuple containing the action and keyframe strip, or (None, None) if setup fails.
:rtype: tuple[BpyAction, BpyActionKeyframeStrip] | tuple[None, None]
"""
if not isinstance(obj.data, bpy.types.Armature):
return (None, None)
# Safety check but should never occur because of Operator's poll method
if self.armature is None:
return (None, None)
if self.armature.animation_data is None:
self.armature.animation_data_create()
if not isinstance(self.armature.animation_data, bpy.types.AnimData):
return (None, None)
obj_name = obj.name
action = bpy.data.actions.get(f"{obj_name}-{ACTION_SUFFIX_NAME}")
if action is None:
action = bpy.data.actions.new(f"{obj_name}-{ACTION_SUFFIX_NAME}")
layer = action.layers.new("Layer")
strip = cast(
bpy.types.ActionKeyframeStrip, layer.strips.new(type="KEYFRAME")
)
self.armature.animation_data.action = action
else:
self.armature.animation_data.action = action
layer = action.layers[0]
strip = cast(bpy.types.ActionKeyframeStrip, layer.strips[0])
self._slot = action.slots.get(f"OB{SLOT_POSE_ASSETS_NAME}") or action.slots.new(
id_type="OBJECT", name=f"{SLOT_POSE_ASSETS_NAME}"
)
self.armature.animation_data.action = action
self.armature.animation_data.action_slot = self._slot
return action, strip
def cleanup(self, obj: BpyObject):
"""Clean up resources after pose asset animation is complete."""
pass
def poll(self, cls, context: BpyContext):
"""
Check if pose asset lip-sync animation can be performed in the current context.
This method verifies that an armature is selected, has the necessary properties,
and that the system is ready for pose asset animation.
:param cls: The class calling this poll method.
:param context: The current Blender context.
:type context: BpyContext
:return: True if pose asset animation can be performed, False otherwise.
:rtype: bool
"""
obj = context.active_object
if obj is None or obj.type != "ARMATURE":
return False
props = getattr(obj, "lipsync2d_props")
if props is None:
return False
model_state = LIPSYNC2D_AP_Preferences.get_model_state()
return (context.scene is not None) and model_state != "DOWNLOADING"
@staticmethod
def get_corrected_end_frame(word_start_frame, visemes_data: VisemeData) -> int:
"""
Calculate the corrected end frame for a word based on viseme timing.
This method computes the actual end frame of the last viseme in a word,
which may differ from the word's theoretical end frame.
:param word_start_frame: The starting frame of the word.
:type word_start_frame: int
:param visemes_data: Data about visemes including timing information.
:type visemes_data: VisemeData
:return: The corrected end frame for the word.
:rtype: int
"""
return word_start_frame + round(
visemes_data["visemes_parts"] * (visemes_data["visemes_len"] - 1)
)
@@ -0,0 +1,502 @@
from typing import Any, Iterator, cast
import bpy
from ..phoneme_to_viseme import viseme_items_mpeg4_v2
from ..Timeline.LIPSYNC2D_TimeConversion import LIPSYNC2D_TimeConversion
from ...Core.constants import ACTION_SUFFIX_NAME, SLOT_SHAPE_KEY_NAME
from ...Core.Timeline.LIPSYNC2D_Timeline import LIPSYNC2D_Timeline
from ...Core.types import VisemeData, VisemeSKeyAnimationData, WordTiming
from ...Preferences.LIPSYNC2D_AP_Preferences import LIPSYNC2D_AP_Preferences
from ...lipsync_types import (
BpyAction,
BpyActionChannelbag,
BpyActionKeyframeStrip,
BpyActionSlot,
BpyContext,
BpyObject,
BpyPropertyGroup,
BpyShapeKey,
)
class LIPSYNC2D_ShapeKeysAnimator:
"""
A class designed to manage lip-sync animation using shape keys in Blender.
This class provides methods for manipulating shape key animations, including clearing
existing keyframes, setting up new animations, modifying interpolation types, and inserting
keyframes for viseme data.
:ivar _slot: Internal storage representing a reference to an action slot used in
the animation chain for lip-syncing (assigned during setup phase).
:type _slot: BpyActionSlot
"""
def __init__(self) -> None:
self._slot: BpyActionSlot | None = None
self._key_blocks: Any
self.silence_frame_threshold: float = -1
self.in_between_frame_threshold: float = -1
self.silence_shape_key_name: str | None = None
self.previous_start: int = -1
self.previous_viseme: str | None = None
self.inserted_keyframes: int = 0
self.word_end_frame = -1
self.word_start_frame = -1
self.delay_until_next_word = -1
self.is_last_word = False
self.is_first_word = False
self.time_conversion = None
self.close_motion_duration = -1
self.channelbag: BpyActionChannelbag
@staticmethod
def get_shape_key_action(obj: BpyObject):
"""
Retrieves the action associated with the shape keys of the given object, if available.
This function checks if the provided object has shape keys defined. If shape keys
are present and they have associated animation data and an assigned action, the
function returns the action. If any of these conditions fail, the function returns None.
:param obj: The object to retrieve the shape key action from.
:type obj: Any
:return: The action associated with the object's shape keys if available, otherwise None.
:rtype: Any or None
"""
if not isinstance(obj.data, bpy.types.Mesh):
return None
if (
obj.data.shape_keys
and obj.data.shape_keys.animation_data
and obj.data.shape_keys.animation_data.action
):
return obj.data.shape_keys.animation_data.action
return None
def clear_previous_keyframes(self, obj: BpyObject):
"""
Clears all previous keyframes from the shape key action's channelbag for
the provided object, ensuring the removal of existing animation
data within the specified context.
:param obj: The Blender object from which previous keyframes are to be
cleared. Must have a mesh data type.
:type obj: BpyObject
:return: This function does not return any value. If the provided object
does not meet the required conditions (e.g., not a mesh or has no
trackable action), the function terminates without modification.
:rtype: None
"""
if not isinstance(obj.data, bpy.types.Mesh):
return
if (action := self.get_shape_key_action(obj)) is None:
return
strip = cast(BpyActionKeyframeStrip, action.layers[0].strips[0])
channelbag = strip.channelbag(self._slot, ensure=True)
for fcurve in channelbag.fcurves:
fcurve.keyframe_points.clear()
def insert_keyframes(
self,
obj: BpyObject,
props: BpyPropertyGroup,
visemes_data: VisemeData,
word_timing: WordTiming,
delay_until_next_word: int,
is_last_word: bool,
word_index: int,
):
"""
Insert viseme animations based on given viseme data, word timing, and properties. This function ensures
that the shape keys for lip-sync animations are manipulated and keyframed correctly for smooth transitions
between viseme states. It also optionally adds a silence (SIL) shape key at the end of a word depending
on specific conditions.
:param word_index: Word index
:param obj: The Blender object to insert visemes into.
:param props: Properties related to lipsync and shape key data.
:param visemes_data: Data about visemes, including their order and division details.
:param word_timing: Timing information for the word's animation frames.
:param delay_until_next_word: A delay value used to determine if silence should be inserted between words.
:param is_last_word: Indicates whether the current word is the last word in the sequence.
:return: None
"""
# Initialize word properties
self.word_end_frame = word_timing["word_frame_end"]
self.word_start_frame = word_timing["word_frame_start"]
self.delay_until_next_word = max(0, delay_until_next_word)
self.is_last_word = is_last_word
self.is_first_word = word_index == 0
# Insert silences before or after word when needed
self.insert_silences(visemes_data, word_index)
# Iterate through visemes and insert keyframes on time
for shape_key_anim_data in self._insert_on_visemes(
obj, props, visemes_data, word_timing
):
for fcurve in self.channelbag.fcurves:
fcurve: bpy.types.FCurve
shape_key_name = shape_key_anim_data["shape_key"]
shape_key_data_path = f'key_blocks["{shape_key_name}"].value'
value = (
shape_key_anim_data["value"]
if shape_key_data_path == fcurve.data_path
else 0
)
fcurve.keyframe_points.insert(
shape_key_anim_data["frame"], value=value, options={"FAST"}
)
self.inserted_keyframes += 1
def insert_silences(self, visemes_data: VisemeData, word_index: int):
add_sil_at_word_end = (
self.delay_until_next_word > self.silence_frame_threshold
) or self.is_last_word
silence_data_path = f'key_blocks["{self.silence_shape_key_name}"].value'
if add_sil_at_word_end:
for fcurve in self.channelbag.fcurves:
fcurve: bpy.types.FCurve
# Define data-path and value
value = 1 if silence_data_path == fcurve.data_path else 0
# Last viseme is inserted a bit before end of word. This ensures that silence uses correct timing
corrected_word_end_frame = (
LIPSYNC2D_ShapeKeysAnimator.get_corrected_end_frame(
self.word_start_frame, visemes_data
)
)
if not self.is_last_word:
# Add silence after current word, with some delay to allow a smooth motion
# If close_motion_duration is too high, fallback to next word time-postion minus defined threshold
frame = corrected_word_end_frame + max(
1,
min(
self.delay_until_next_word
- self.in_between_frame_threshold,
self.close_motion_duration,
),
)
fcurve.keyframe_points.insert(frame, value=value, options={"FAST"})
self.inserted_keyframes += 1
# Add silence just before the next word.
# This prevents the lips from sliding unnaturally.
# TODO previous_start is not updated although new keyframe is inserted. see how to update it
frame = (
corrected_word_end_frame
+ self.delay_until_next_word
- max(1, self.in_between_frame_threshold)
)
fcurve.keyframe_points.insert(frame, value=value, options={"FAST"})
self.inserted_keyframes += 1
elif self.is_last_word:
frame = corrected_word_end_frame + self.close_motion_duration
fcurve.keyframe_points.insert(frame, value=value, options={"FAST"})
self.inserted_keyframes += 1
if self.is_first_word:
for fcurve in self.channelbag.fcurves:
fcurve: bpy.types.FCurve
value = 1 if silence_data_path == fcurve.data_path else 0
frame = max(
LIPSYNC2D_Timeline.get_frame_start(),
self.word_start_frame - max(1, self.close_motion_duration),
)
fcurve.keyframe_points.insert(frame, value=value, options={"FAST"})
def _insert_on_visemes(
self,
obj: BpyObject,
props: BpyPropertyGroup,
visemes_data: VisemeData,
word_timing: WordTiming,
) -> Iterator[VisemeSKeyAnimationData]:
"""
Insert viseme animations based on given viseme data, word timing, and properties. This function ensures
that the shape keys for lip-sync animations are manipulated and keyframed correctly for smooth transitions
between viseme states. It also optionally adds a silence (SIL) shape key at the end of a word depending
on specific conditions.
:param word_index: Word index
:param obj: The Blender object to insert visemes into.
:param props: Properties related to lipsync and shape key data.
:param visemes_data: Data about visemes, including their order and division details.
:param word_timing: Timing information for the word's animation frames.
:param delay_until_next_word: A delay value used to determine if silence should be inserted between words.
:param is_last_word: Indicates whether the current word is the last word in the sequence.
:return: None
"""
if not isinstance(obj.data, bpy.types.Mesh) or obj.data.shape_keys is None:
yield {
"frame": -1,
"viseme": "",
"value": -1,
"shape_key": "",
"viseme_index": -1,
}
visemes = enumerate(visemes_data["visemes"])
for viseme_index, v in visemes:
self.is_last_viseme = (viseme_index + 1) == visemes_data["visemes_len"]
viseme_frame_start = word_timing["word_frame_start"] + round(
viseme_index * visemes_data["visemes_parts"]
)
if (
# Do not insert a keyframe on a frame that already contains a keyframed shapekey
self.has_already_a_kframe(viseme_frame_start)
# Do not insert a keyframe if previous keyframe is too close
or self.is_prev_kframe_too_close(viseme_frame_start)
# Do not insert a keyframe if previous keyframed shapekey was for the same viseme
or self.is_redundant(props, v)
):
continue
yield {
"frame": viseme_frame_start,
"viseme": v,
"viseme_index": viseme_index,
"value": 1,
"shape_key": getattr(props, f"lip_sync_2d_viseme_shape_keys_{v}"),
}
self.previous_start = viseme_frame_start
self.previous_viseme = v
def has_already_a_kframe(self, viseme_frame_start):
return viseme_frame_start == self.previous_start
def is_prev_kframe_too_close(self, viseme_frame_start):
return self.previous_start >= 0 and (
viseme_frame_start - self.previous_start <= self.in_between_frame_threshold
)
def is_redundant(self, props: BpyPropertyGroup, v: str):
if self.previous_viseme is None or self.previous_viseme == "sil":
return False
previous_viseme_prop_name = getattr(
props, f"lip_sync_2d_viseme_shape_keys_{self.previous_viseme}"
)
viseme_prop_name = getattr(props, f"lip_sync_2d_viseme_shape_keys_{v}")
return previous_viseme_prop_name == viseme_prop_name
def set_interpolation(self, obj: BpyObject):
"""
Sets the interpolation type for all keyframes of the given object's animation
data to 'LINEAR'. This ensures that the transition between keyframes is linear
and removes any other interpolation effects.
:param obj: The Blender object whose animation keyframe interpolation will be
modified.
:type obj: BpyObject
:return: None
"""
if (action := self.get_shape_key_action(obj)) is None:
return
strip = cast(BpyActionKeyframeStrip, action.layers[0].strips[0])
channelbag = strip.channelbag(self._slot, ensure=True)
for fcurve in channelbag.fcurves:
for fcurve in (
cast(BpyActionKeyframeStrip, action.layers[0].strips[0])
.channelbag(action.slots.get(f"KE{SLOT_SHAPE_KEY_NAME}"))
.fcurves
):
for keyframe in fcurve.keyframe_points:
keyframe.interpolation = "LINEAR"
@staticmethod
def reset_shape_keys(key_blocks: Any, viseme_frame_start: float | None = None):
"""
Resets the values of all shape keys in the provided key blocks to 0 and inserts
keyframes for those values at the specified frame.
:param key_blocks: The collection of shape key blocks to reset. Typically
consists of shape keys associated with an object.
:type key_blocks: Any
:param viseme_frame_start: The starting frame at which the keyframe for the
shape key values will be inserted.
:type viseme_frame_start: float
:return: None
"""
for s in key_blocks:
s: BpyShapeKey
if s.name == "Basis":
continue
s.value = 0
if viseme_frame_start is not None:
s.keyframe_insert("value", frame=viseme_frame_start)
def setup(self, obj: BpyObject):
"""
Sets up the animation action and its components for the provided Blender object
if it meets the necessary conditions. Verifies the object's data type and animation
data, ensures that a specific action exists for lip-syncing, and assigns it to the
shape key animation data.
:param obj: The Blender object for which the lip-sync animation is being set up.
Must have a data type of Mesh and support animation data.
:type obj: BpyObject
:return: None if the object does not meet the specified conditions for setup.
:rtype: None
"""
self.setup_properties(obj)
self.setup_animation_properties(obj)
def setup_properties(self, obj: BpyObject):
props = obj.lipsync2d_props # type: ignore
if bpy.context.scene is not None:
self.time_conversion = LIPSYNC2D_TimeConversion(bpy.context.scene.render)
self.close_motion_duration = self.time_conversion.time_to_frame(
props.lip_sync_2d_close_motion_duration
)
if self.time_conversion is None:
return
self.silence_frame_threshold = self.time_conversion.time_to_frame(
props.lip_sync_2d_sil_threshold
)
self.in_between_frame_threshold = self.time_conversion.time_to_frame(
props.lip_sync_2d_in_between_threshold
)
self.silence_shape_key_name = getattr(
props, "lip_sync_2d_viseme_shape_keys_sil"
)
self.previous_start = -1
self.previous_viseme = None
self.inserted_keyframes = 0
self.props = props
def setup_animation_properties(self, obj: BpyObject):
_, strip = self.set_up_action(obj)
if strip is None:
return
self.setup_fcurves(obj, strip)
def get_available_shape_key_names(self):
visemes = viseme_items_mpeg4_v2(None, None)
available_shape_keys = [
key
for (enum_id, _, _) in visemes
if (key := getattr(self.props, f"lip_sync_2d_viseme_shape_keys_{enum_id}"))
!= "NONE"
]
return available_shape_keys
def setup_fcurves(self, obj: BpyObject, strip: BpyActionKeyframeStrip):
if not isinstance(obj.data, bpy.types.Mesh) or obj.data.shape_keys is None:
return
props = obj.lipsync2d_props # type: ignore
available_shape_keys = self.get_available_shape_key_names()
self._key_blocks = [
shape_key
for shape_key in obj.data.shape_keys.key_blocks
if shape_key.name in available_shape_keys
]
self.channelbag = strip.channelbag(self._slot, ensure=True)
fcurves = self.channelbag.fcurves
fcurves: bpy.types.ActionChannelbagFCurves
if props.lip_sync_2d_use_clear_keyframes:
fcurves.clear()
for shape_key in self._key_blocks:
shape_key_data_path = f'key_blocks["{shape_key.name}"].value'
if fcurves.find(shape_key_data_path) is None:
fcurves.new(shape_key_data_path)
def set_up_action(
self, obj: BpyObject
) -> tuple[BpyAction, BpyActionKeyframeStrip] | tuple[None, None]:
if not isinstance(obj.data, bpy.types.Mesh):
return (None, None)
# Safety check but should never occur because of Operator's poll method
if obj.data.shape_keys is None:
return (None, None)
if obj.data.shape_keys.animation_data is None:
obj.data.shape_keys.animation_data_create()
if not isinstance(obj.data.shape_keys.animation_data, bpy.types.AnimData):
return (None, None)
obj_name = obj.name
action = bpy.data.actions.get(f"{obj_name}-{ACTION_SUFFIX_NAME}")
if action is None:
action = bpy.data.actions.new(f"{obj_name}-{ACTION_SUFFIX_NAME}")
layer = action.layers.new("Layer")
strip = cast(
bpy.types.ActionKeyframeStrip, layer.strips.new(type="KEYFRAME")
)
obj.data.shape_keys.animation_data.action = action
else:
obj.data.shape_keys.animation_data.action = action
layer = action.layers[0]
strip = cast(bpy.types.ActionKeyframeStrip, layer.strips[0])
self._slot = action.slots.get(f"KE{SLOT_SHAPE_KEY_NAME}") or action.slots.new(
id_type="KEY", name=f"{SLOT_SHAPE_KEY_NAME}"
)
obj.data.shape_keys.animation_data.action = action
obj.data.shape_keys.animation_data.action_slot = self._slot
return action, strip
def cleanup(self, obj: BpyObject):
pass
def poll(self, cls, context: BpyContext):
obj = context.active_object
if obj is None or not isinstance(obj.data, bpy.types.Mesh):
return False
if obj.data.shape_keys is None:
return False
model_state = LIPSYNC2D_AP_Preferences.get_model_state()
return (
context.scene is not None or context.active_object is not None
) and model_state != "DOWNLOADING"
@staticmethod
def get_corrected_end_frame(word_start_frame, visemes_data: VisemeData) -> int:
return word_start_frame + round(
visemes_data["visemes_parts"] * (visemes_data["visemes_len"] - 1)
)
@@ -0,0 +1,293 @@
import bpy
from typing import cast
from ...Preferences.LIPSYNC2D_AP_Preferences import LIPSYNC2D_AP_Preferences
from ...Core.constants import ACTION_SUFFIX_NAME, SLOT_SPRITE_SHEET_NAME
from ...Core.Timeline.LIPSYNC2D_Timeline import LIPSYNC2D_Timeline
from ...Core.types import VisemeData, WordTiming
from ...lipsync_types import BpyAction, BpyActionChannelbag, BpyActionSlot, BpyActionKeyframeStrip, BpyContext, BpyObject, BpyPropertyGroup
from .LIPSYNC2D_ShapeKeysAnimator import LIPSYNC2D_ShapeKeysAnimator
from ..Timeline.LIPSYNC2D_TimeConversion import LIPSYNC2D_TimeConversion
class LIPSYNC_SpriteSheetAnimator:
"""
Class responsible for handling sprite sheet animation specifically for lipsync. It provides functionalities
to manage keyframes, interpolate lipsync viseme animations, and perform animation configurations.
This class is focused on managing the animation data for 2D lipsync sprite sheets by clearing keyframes,
inserting viseme keyframes, setting interpolation methods, and providing setup and cleanup methods.
:ivar lipsync2d_props: Holds properties relevant for 2D lipsync, such as the sprite sheet index and viseme
mappings.
:type lipsync2d_props: BpyPropertyGroup
:ivar lip_sync_2d_sprite_sheet_index: Index of the current viseme in the sprite sheet.
:type lip_sync_2d_sprite_sheet_index: int
:ivar lip_sync_2d_viseme_sil: Viseme index representing silence or no sound.
:type lip_sync_2d_viseme_sil: int
:ivar lip_sync_2d_viseme_{v}: Dynamically managed viseme index mapping for different mouth shapes.
:type lip_sync_2d_viseme_{v}: int
"""
def __init__(self) -> None:
self.inserted_keyframes: int = 0
self._slot: BpyActionSlot | None = None
self.silence_frame_threshold: float = -1
self.in_between_frame_threshold: float = -1
self.previous_start: int = -1
self.previous_viseme: str | None = None
self.word_end_frame = -1
self.word_start_frame = -1
self.delay_until_next_word = -1
self.is_last_word = False
self.is_first_word = False
self.time_conversion: LIPSYNC2D_TimeConversion | None = None
self.channelbag: BpyActionChannelbag
def clear_previous_keyframes(self, obj: BpyObject):
"""
Clears all previous keyframes associated with the property
'lipsync2d_props.lip_sync_2d_sprite_sheet_index' for the given object's
animation data.
This function iterates over the f-curves in the object's animation action,
if any, and removes all keyframe points for the specified data path.
:param obj: The object whose keyframes associated with the specified property
should be cleared.
:type obj: BpyObject
:return: None
"""
action = obj.animation_data.action if obj.animation_data else None
if action:
for fcurve in action.fcurves:
if fcurve.data_path == "lipsync2d_props.lip_sync_2d_sprite_sheet_index":
fcurve.keyframe_points.clear()
def insert_keyframes(self, obj: BpyObject, props: BpyPropertyGroup, visemes_data: VisemeData,
word_timing: WordTiming,
delay_until_next_word: int, is_last_word: bool, word_index: int):
"""
Insert viseme animations based on given viseme data, word timing, and properties. This function ensures
that the shape keys for lip-sync animations are manipulated and keyframed correctly for smooth transitions
between viseme states. It also optionally adds a silence (SIL) shape key at the end of a word depending
on specific conditions.
:param word_index: Word index
:param obj: The Blender object to insert visemes into.
:param props: Properties related to lipsync and shape key data.
:param visemes_data: Data about visemes, including their order and division details.
:param word_timing: Timing information for the word's animation frames.
:param delay_until_next_word: A delay value used to determine if silence should be inserted between words.
:param is_last_word: Indicates whether the current word is the last word in the sequence.
:return: None
"""
# Initialize word properties
self.word_end_frame = word_timing["word_frame_end"]
self.word_start_frame = word_timing["word_frame_start"]
self.delay_until_next_word = max(0, delay_until_next_word)
self.is_last_word = is_last_word
self.is_first_word = word_index == 0
# Insert silences before or after word when needed
self.insert_silences(props, visemes_data)
# Iterate through visemes and insert keyframes on time
for shape_key_anim_data in self._insert_on_visemes(obj, props, visemes_data, word_timing):
for fcurve in self.channelbag.fcurves:
fcurve: bpy.types.FCurve
value = shape_key_anim_data["value"]
fcurve.keyframe_points.insert(shape_key_anim_data["frame"], value=value, options={"FAST"})
self.inserted_keyframes += 1
def insert_silences(self, props, visemes_data):
add_sil_at_word_end = (self.delay_until_next_word > self.silence_frame_threshold) or self.is_last_word
if add_sil_at_word_end:
for fcurve in self.channelbag.fcurves:
fcurve: bpy.types.FCurve
# Define data-path and value
value = props[f"lip_sync_2d_viseme_sil"]
# Last viseme is inserted a bit before end of word. This ensures that silence uses correct timing
corrected_word_end_frame = LIPSYNC2D_ShapeKeysAnimator.get_corrected_end_frame(self.word_start_frame,
visemes_data)
# Add silence after current word
#TODO previous_start is not updated although new keyframe is inserted. see how to update it
frame = corrected_word_end_frame + self.in_between_frame_threshold
fcurve.keyframe_points.insert(frame, value=value, options={"FAST"})
self.inserted_keyframes += 1
if self.is_last_word:
frame = corrected_word_end_frame + self.in_between_frame_threshold
fcurve.keyframe_points.insert(frame, value=value, options={"FAST"})
self.inserted_keyframes += 1
if self.is_first_word:
for fcurve in self.channelbag.fcurves:
fcurve: bpy.types.FCurve
value = props["lip_sync_2d_viseme_sil"]
frame = max(LIPSYNC2D_Timeline.get_frame_start(),
self.word_start_frame - max(1, self.in_between_frame_threshold))
fcurve.keyframe_points.insert(frame, value=value, options={"FAST"})
def _insert_on_visemes(self, obj: BpyObject, props: BpyPropertyGroup, visemes_data: VisemeData,
word_timing: WordTiming):
"""
Inserts keyframes for viseme animations based on viseme data and timing information for lip-syncing.
This function computes the required frame indices for animating visemes in a sprite sheet and handles
the insertion of "silent" visemes during pauses or at the end of a word. It takes into account the
timing of each viseme and applies it to an object's animation data.
:param obj: The Blender object (BpyObject) to which keyframes will be added.
:param props: A Blender property group (BpyPropertyGroup) containing viseme animation settings,
including indices for each viseme.
:param visemes_data: A dictionary containing viseme-related data such as "visemes" and
"visemes_len".
:param word_timing: A dictionary containing word timing information, including "word_frame_start"
and "word_frame_end".
:param delay_until_next_word: A float value representing the delay until the next word in seconds.
:param is_last_word: A boolean indicating whether the current word is the last word in the sequence.
:return: None
"""
visemes = enumerate(visemes_data["visemes"])
for viseme_index, v in visemes:
self.is_last_viseme = (viseme_index + 1) == visemes_data["visemes_len"]
viseme_frame_start = word_timing["word_frame_start"] + round(viseme_index * visemes_data["visemes_parts"])
sprite_index = props[f"lip_sync_2d_viseme_{v}"]
if (
# Do not insert a keyframe on a frame that already contains a keyframed shapekey
self.has_already_a_kframe(viseme_frame_start)
# Do not insert a keyframe if previous keyframe is too close
or self.is_prev_kframe_too_close(viseme_frame_start)
# Do not insert a keyframe if previous keyframed shapekey was for the same viseme
or self.is_redundant(props, v)
):
continue
yield {
"frame": viseme_frame_start,
"viseme": v,
"viseme_index": viseme_index,
"value": sprite_index,
"shape_key": getattr(props, "lip_sync_2d_sprite_sheet_index")
}
self.previous_start = viseme_frame_start
self.previous_viseme = v
def has_already_a_kframe(self, viseme_frame_start):
return viseme_frame_start == self.previous_start
def is_prev_kframe_too_close(self, viseme_frame_start):
return self.previous_start >= 0 and (
(viseme_frame_start - self.previous_start) <= self.in_between_frame_threshold)
def is_redundant(self, props: BpyPropertyGroup, v: str):
if self.previous_viseme is None or self.previous_viseme == "sil":
return False
def set_interpolation(self, obj: BpyObject):
"""
Sets the interpolation mode of keyframes in the animation action of a given object
to 'CONSTANT'. This operation affects all keyframe points of all f-curves within the
action, modifying their interpolation behavior.
:param obj: The object whose animation action keyframe interpolation will be
modified. It must have animation data with an action to apply changes.
:type obj: BpyObject
:return: None
"""
action = obj.animation_data.action if obj.animation_data else None
if action:
for fcurve in action.fcurves:
for keyframe in fcurve.keyframe_points:
keyframe.interpolation = 'CONSTANT'
def setup(self, obj: BpyObject):
self.setup_animation_properties(obj)
self.setup_properties(obj)
def setup_properties(self, obj: BpyObject):
props = obj.lipsync2d_props # type: ignore
if bpy.context.scene is not None:
self.time_conversion = LIPSYNC2D_TimeConversion(bpy.context.scene.render)
if self.time_conversion is None:
return
self.silence_frame_threshold = self.time_conversion.time_to_frame(props.lip_sync_2d_sps_sil_threshold)
self.in_between_frame_threshold = max(1,self.time_conversion.time_to_frame(props.lip_sync_2d_sps_in_between_threshold))
self.previous_start = -1
self.previous_viseme = None
self.inserted_keyframes = 0
def setup_animation_properties(self, obj: BpyObject):
_, strip = self.set_up_action(obj)
if strip is None:
return
self.setup_fcurves(obj, strip)
def setup_fcurves(self, obj: BpyObject, strip: BpyActionKeyframeStrip):
if not isinstance(obj.data, bpy.types.Mesh):
return
props = obj.lipsync2d_props # type: ignore
self.channelbag = strip.channelbag(self._slot, ensure=True)
data_path = 'lipsync2d_props.lip_sync_2d_sprite_sheet_index'
fcurves = self.channelbag.fcurves
if props.lip_sync_2d_use_clear_keyframes:
fcurves.clear()
if fcurves.find(data_path) is None:
fcurves.new(data_path)
def set_up_action(self, obj: BpyObject) -> tuple[BpyAction, BpyActionKeyframeStrip] | tuple[None, None]:
if not isinstance(obj.data, bpy.types.Mesh):
return (None, None)
if obj.animation_data is None:
obj.animation_data_create()
if not isinstance(obj.animation_data, bpy.types.AnimData):
return (None, None)
obj_name = obj.name
action = bpy.data.actions.get(f"{obj_name}-{ACTION_SUFFIX_NAME}")
if action is None:
action = bpy.data.actions.new(f"{obj_name}-{ACTION_SUFFIX_NAME}")
layer = action.layers.new("Layer")
strip = cast(bpy.types.ActionKeyframeStrip, layer.strips.new(type='KEYFRAME'))
obj.animation_data.action = action
else:
layer = action.layers[0]
strip = cast(bpy.types.ActionKeyframeStrip, layer.strips[0])
self._slot = action.slots.get(f"OB{SLOT_SPRITE_SHEET_NAME}") or action.slots.new(id_type='OBJECT', name=SLOT_SPRITE_SHEET_NAME)
obj.animation_data.action = action
obj.animation_data.action_slot = self._slot
return action, strip
def cleanup(self, obj: BpyObject):
pass
def poll(self, cls, context: BpyContext):
model_state = LIPSYNC2D_AP_Preferences.get_model_state()
return (context.scene is not None or context.active_object is not None) and model_state != "DOWNLOADING"
@@ -0,0 +1,57 @@
from typing import Any, Iterator, Protocol
from ...Core.types import VisemeData, VisemeSKeyAnimationData, WordTiming
from ...lipsync_types import BpyContext, BpyObject, BpyPropertyGroup
class LIPSYNC2D_LipSyncAnimator(Protocol):
"""
Interface for handling lip-sync animation.
This protocol defines methods for animating lip-sync via viseme-based
keyframe generation, interpolation setup, and cleanup. Classes
implementing this protocol are expected to provide mechanisms for setting
up animation objects, managing keyframes, and generating smooth
transitions between visemes.
:ivar setup: Initializes and configures the given animation object for lip-sync.
:type setup: Callable[[BpyObject], None]
:ivar clear_previous_keyframes: Clears all keyframes previously set on the animation object.
:type clear_previous_keyframes: Callable[[BpyObject], None]
:ivar insert_on_visemes: Inserts keyframes on the animation object based on the provided
viseme data, word timings, and additional properties.
:type insert_on_visemes: Callable[[BpyObject, BpyPropertyGroup, VisemeData, WordTiming, int, bool], None]
:ivar set_interpolation: Adjusts keyframe interpolation for smoother lip-sync animation.
:type set_interpolation: Callable[[BpyObject], None]
:ivar cleanup: Finalizes animation and removes temporary data from the object.
:type cleanup: Callable[[BpyObject], None]
"""
inserted_keyframes: int
def setup(self, obj: BpyObject):
pass
def clear_previous_keyframes(self, obj: BpyObject):
pass
def insert_keyframes(
self,
obj: BpyObject,
props: BpyPropertyGroup,
visemes_data: VisemeData,
word_timing: WordTiming,
delay_until_next_word: int,
is_last_word: bool,
word_index: int,
):
pass
def set_interpolation(self, obj: BpyObject):
pass
def cleanup(self, obj: BpyObject):
pass
def poll(self, cls, context: BpyContext) -> bool:
return False
@@ -0,0 +1,7 @@
from typing import TypedDict
class VoskRecognitionWord(TypedDict):
conf: float
end: float
start: float
word: str
@@ -0,0 +1,68 @@
from typing import cast
from phonemizer import phonemize
from .Timeline.LIPSYNC2D_TimeConversion import LIPSYNC2D_TimeConversion
from .Animator.LIPSYNC2D_ShapeKeysAnimator import LIPSYNC2D_ShapeKeysAnimator
from .types import VisemeData, WordTiming
from ..Core.LIPSYNC2D_ISOLangConverter import LIPSYNC2D_ISOLangConverter
from ..Core.phoneme_to_viseme import phoneme_to_viseme_arkit_v2 as phoneme_to_viseme
from ..Core.Timeline.LIPSYNC2D_Timeline import LIPSYNC2D_Timeline
from ..Preferences.LIPSYNC2D_AP_Preferences import LIPSYNC2D_AP_Preferences
from ..lipsync_types import BpyContext, BpyRenderSettings
class LIPSYNC2D_DialogInspector:
time_conversion: LIPSYNC2D_TimeConversion
def __init__(self, render_settings: BpyRenderSettings):
self.time_conversion = LIPSYNC2D_TimeConversion(render_settings)
@staticmethod
def extract_phonemes(words: list[str], context: BpyContext) -> list[str]:
lang_code = LIPSYNC2D_AP_Preferences.get_current_lang_code()
iso_639_3 = LIPSYNC2D_ISOLangConverter.convert_iso6391_to_iso6393(lang_code)
phonemes = cast(list[str], phonemize(words, language=iso_639_3, backend='espeak'))
return phonemes
@staticmethod
def ipaphoneme_to_viseme(ipa_phoneme: str):
clean = ipa_phoneme.strip("ː̥̬̃012") # remove length, nasal, stress etc
return phoneme_to_viseme.get(clean, "UNK")
def get_word_timing(self, recognized_word) -> WordTiming:
word_frame_start = self.time_conversion.time_to_frame(recognized_word['start']) + max(0,LIPSYNC2D_Timeline.get_frame_start() - 1)
word_frame_end = self.time_conversion.time_to_frame(recognized_word['end']) + max(0, LIPSYNC2D_Timeline.get_frame_start() - 1)
duration = word_frame_end - word_frame_start
return {
"word_frame_start": word_frame_start,
"word_frame_end": word_frame_end,
"duration": duration,
}
@staticmethod
def get_visemes(phoneme, duration: float) -> VisemeData:
phoneme = phoneme.strip()
visemes = [LIPSYNC2D_DialogInspector.ipaphoneme_to_viseme(p) for p in phoneme]
visemes_no_sil = [v for v in visemes if v != "sil"]
visemes_len = len(visemes_no_sil)
visemes_parts = duration / len(visemes_no_sil)
return {
"visemes": visemes_no_sil,
"visemes_len": visemes_len,
"visemes_parts": visemes_parts,
}
def get_next_word_timing(self, recognized_words, index: int) -> WordTiming:
result: WordTiming = {
"word_frame_start": -1,
"word_frame_end": -1,
"duration": -1,
}
if index + 1 >= len(recognized_words):
return result
return self.get_word_timing(recognized_words[index + 1])
@@ -0,0 +1,99 @@
import os
import pathlib
import platform
import zipfile
from typing import cast
import bpy
from phonemizer.backend import EspeakBackend
from ..LIPSYNC2D_Utils import get_package_name
class LIPSYNC2D_EspeakInspector():
@staticmethod
def unzip_binaries() -> None:
espeak_archive_path = LIPSYNC2D_EspeakInspector.get_espeak_archive_path()
espeak_data_archive_path = LIPSYNC2D_EspeakInspector.get_espeak_data_archive_path()
espeak_extraction_path = LIPSYNC2D_EspeakInspector.get_espeak_extraction_path()
try:
with zipfile.ZipFile(espeak_archive_path, 'r') as zip_ref:
zip_ref.extractall(espeak_extraction_path)
with zipfile.ZipFile(espeak_data_archive_path, 'r') as zip_ref:
zip_ref.extractall(espeak_extraction_path)
except FileNotFoundError:
raise FileNotFoundError(f"Input archive '{espeak_archive_path}' not found")
except zipfile.BadZipFile:
raise Exception(f"The file '{espeak_archive_path}' is not a valid zip archive")
except Exception as e:
raise Exception(f"Error during archive extraction: {e}")
@staticmethod
def set_espeak_backend():
plat = str.lower(platform.system())
espeak_extraction_path = LIPSYNC2D_EspeakInspector.get_espeak_extraction_path()
output_path = pathlib.Path(espeak_extraction_path)
if plat == "windows":
EspeakBackend.set_library(output_path / "libespeak-ng.dll")
elif plat == "linux":
EspeakBackend.set_library(output_path / "libespeak-ng.so")
elif plat == "darwin":
EspeakBackend.set_library(output_path / "libespeak-ng.dylib")
else:
raise Exception(f"Unsupported platform: {plat}")
os.environ["ESPEAK_DATA_PATH"] = str(output_path / "espeak-ng-data")
@staticmethod
def get_espeak_archive_path() -> pathlib.Path:
plat = str.lower(platform.system())
script_dir = pathlib.Path(__file__).parent # Get the directory where the script is located
archive_path = script_dir / ".." / "Assets" / "Archives" / plat / f"espeak-ng-{plat}.zip"
return archive_path
@staticmethod
def get_espeak_data_archive_path() -> pathlib.Path:
script_dir = pathlib.Path(__file__).parent # Get the directory where the script is located
archive_path = script_dir / ".." / "Assets" / "Archives" / "common" / "espeak-ng-data.zip"
return archive_path
@staticmethod
def get_espeak_extraction_path() -> pathlib.Path:
package_name = cast(str, get_package_name())
plat = str.lower(platform.system())
try:
user_extension_bin_dir = bpy.utils.extension_path_user(package_name, path=f"bin/{plat}", create=True)
user_extension_bin_path = pathlib.Path(user_extension_bin_dir)
except Exception as e:
raise Exception("Error while trying to get User Extension Path", e)
return user_extension_bin_path
@staticmethod
def get_espeak_filepath() -> pathlib.Path:
plat = str.lower(platform.system())
espeak_path = LIPSYNC2D_EspeakInspector.get_espeak_extraction_path()
if plat == "windows":
return espeak_path / "libespeak-ng.dll"
elif plat == "linux":
return espeak_path / "libespeak-ng.so"
elif plat == "darwin":
return espeak_path / "libespeak-ng.dylib"
# Fallback to linux lib
return espeak_path / "libespeak-ng.so"
@staticmethod
def is_espeak_already_extracted() -> bool:
espeak_filepath = LIPSYNC2D_EspeakInspector.get_espeak_filepath()
return espeak_filepath.is_file()
@@ -0,0 +1,53 @@
class LIPSYNC2D_ISOLangConverter():
# Default fallback ISO 639-3 language code
DEFAULT_ISO6393_CODE = "en-us"
# Mapping from Vosk (ISO 639-1) to eSpeak language codes (ISO 639-3 + custom codes)
vosk_to_espeak_map = {
"ar": "ar", # Arabic
"ar-tn": "ar", # Arabic (Tunisian) maps to generic Arabic
"ca": "ca", # Catalan
"cn": "cmn", # Chinese maps to Mandarin (cmn)
"cs": "cs", # Czech
"de": "de", # German
"en": "en-gb", # English maps to US English
"en-gb": "en-gb", # UK English
"en-in": "en-us", # Indian English maps to US English
"en-us": "en-us", # US English
"eo": "eo", # Esperanto
"es": "es", # Spanish
"fa": "fa", # Farsi / Persian
"fr": "fr-fr", # French. In espeak it's identify with fr-fr
"gu": "gu", # Gujarati
"hi": "hi", # Hindi
"it": "it", # Italian
"ja": "ja", # Japanese
"ko": "ko", # Korean
"kz": "kk", # Kazakh (ISO 639-3: kk)
"nl": "nl", # Dutch
"pl": "pl", # Polish
"pt": "pt", # Portuguese
"ru": "ru", # Russian
"sv": "sv", # Swedish
"te": "te", # Telugu
"tg": "fa", # Tajik maps to Farsi / Persian
"tr": "tr", # Turkish
"ua": "uk", # Ukrainian (maps from ua to ISO code uk)
"uz": "uz", # Uzbek
"vn": "vi", # Vietnamese (maps to ISO 639-3: vi)
}
@staticmethod
def convert_iso6391_to_iso6393(iso6391_code: str) -> str:
"""
Converts an ISO 639-1 language code to its corresponding ISO 639-3
code using a predefined mapping. If the provided code is not found,
returns the default fallback code ("en").
:param iso6391_code: The ISO 639-1 language code to convert.
:return: The mapped ISO 639-3 code or the default fallback code.
"""
return LIPSYNC2D_ISOLangConverter.vosk_to_espeak_map.get(
iso6391_code, LIPSYNC2D_ISOLangConverter.DEFAULT_ISO6393_CODE
)
@@ -0,0 +1,8 @@
class SingletonMeta(type):
"""A metaclass for creating singleton classes."""
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super().__call__(*args, **kwargs)
return cls._instances[cls]
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,319 @@
import json
import os
import pathlib
import subprocess
import sys
from typing import Callable, Literal, cast
import bpy
import requests
from vosk import MODEL_DIRS, MODEL_LIST_URL
from ..LIPSYNC2D_Utils import get_package_name
class LIPSYNC2D_VoskHelper():
"""
Helper functions and utilities for lip-syncing using Vosk language models.
This class offers tools for managing language models for lip-syncing in
Blender. It includes methods for listing available languages, installing
language models, managing cache, and more. The class primarily works with
online and offline Vosk language models and facilitates usage within the
Blender environment.
:ivar worker_proc: Manages the subprocess handling asynchronous language model installation.
:type worker_proc: subprocess.Popen | None
:ivar excluded_lang: A list of language codes to exclude from model selection,
such as unstable languages or ones causing caching issues.
:type excluded_lang: list[str]
"""
worker_proc: subprocess.Popen | None = None
# Langs in this list won't show up in Language Model selection
excluded_lang = [
"kz", # Unstable, throw ASSERTION_FAILED error
"ua"
# Vosk uses ua to identify Ukrainian but store a model named **-uk-**.zip preventing efficient caching and force model to be downloaded each time
]
@staticmethod
def setextensionpath(func):
"""
A static method decorator that sets a predefined path for vosk Cache and ensures the directory exists.
It wraps the given function, updating the vosk project-specific `MODEL_DIRS` mapping with the dynamically
determined path for the extension cache directory. If the directory does not already exist, it will
be created before the wrapped function executes.
:param func: The function to be wrapped.
:type func: Callable
:return: Wrapped function that ensures the extension cache path is set and exists.
:rtype: Callable
"""
def wrapper(*args, **kwargs):
MODEL_DIRS[3] = LIPSYNC2D_VoskHelper.get_extension_path("cache")
model_path = pathlib.Path(MODEL_DIRS[3])
if not model_path.exists():
model_path.mkdir(parents=True, exist_ok=True)
result = func(*args, **kwargs)
return result
return wrapper
@staticmethod
def get_extension_path(subfolder: Literal['cache', 'tmp', 'bin', ''] = "") -> pathlib.Path:
"""
Gets the user-defined extension path for a specific subfolder associated with the package.
This method retrieves the path where addon can store various elements. The subfolder
argument allows specifying a specific subdirectory within the extension path to retrieve.
If no subfolder is provided, the base extension path is returned. The path will automatically
be created if it does not already exist. The result is returned as a `pathlib.Path` object.
:param subfolder: One of the specified subfolder names ('cache', 'tmp', 'bin', or '')
indicating the subdirectory within the extension path to retrieve.
:return: A `pathlib.Path` object pointing to the requested extension path.
:rtype: pathlib.Path
"""
package_name = cast(str, get_package_name())
return pathlib.Path(bpy.utils.extension_path_user(package_name, path=subfolder, create=True))
@staticmethod
def get_available_langs_online() -> list[tuple[str, str, str]]:
"""
This method retrieves a language list from a cached file, filters it based on predefined
criteria, and returns it in a formatted tuple containing unique identifiers, language
names, and additional data. Sorting is applied for better readability of the language options.
:param cached_langs_list_file: The path to the cached languages list file, fetched from the class helper.
:raises Exception: Raised when there is an error loading the cached file.
:rtype: List[tuple[str, str, str]]
:return: A list of tuples where each tuple contains three strings:
- Language identifier
- Display text for the language
- Key representing the language
"""
langs_list = []
all_langs = []
cached_langs_list_file = LIPSYNC2D_VoskHelper.get_language_list_file()
if os.path.isfile(cached_langs_list_file):
try:
with open(cached_langs_list_file, "r", encoding="utf-8") as f:
langs_list = json.load(f)
except Exception as e:
raise Exception(f"Error while loading cached files index.{e}")
if langs_list:
# List should already be filtered. This is done as a safety measure.
all_langs = [(l["lang"], l["lang_text"]) for l in langs_list if
l["lang"] != "all" and l["obsolete"] == "false" and l['type'] == 'small' and l[
"lang"] not in LIPSYNC2D_VoskHelper.excluded_lang]
all_langs.sort(key=lambda x: x[1])
all_langs = [('none', "-- None --", "No selection"), ] + all_langs
enum_items = [(list(l)[0], list(l)[1], list(l)[0]) for l in all_langs]
return enum_items
@staticmethod
def get_available_langs_offline() -> list[tuple[str, str, str]]:
"""
Returns a list of all available offline language models from the local cache directory
along with their metadata. It checks the local extension path for cached language
model directories and a JSON file containing language metadata. If a corresponding
language model exists in both the cache and the metadata file, it is included in the
list. A default 'none' option is always included at the beginning of the list.
This method is useful for retrieving the available offline language models to
be used in the application.
:param ext_path: The path to the cache directory where language models are stored,
as obtained by the `get_extension_path` method.
:type ext_path: pathlib.Path
:return: A list of tuples, where each tuple contains the following elements:
- The code of the language model.
- The display text for the language model.
- A detailed label for the language model.
:rtype: list[tuple[str, str, str]]
:raises Exception: If the `languages_list.json` file is present but cannot be parsed
as valid JSON, or an unexpected error occurs during the file reading or
processing.
"""
ext_path = LIPSYNC2D_VoskHelper.get_extension_path("cache")
all_offline_langs = []
if not ext_path.is_dir():
return all_offline_langs
cached_langs_list_file = ext_path / "languages_list.json"
if cached_langs_list_file.is_file():
try:
with open(cached_langs_list_file, "r", encoding="utf-8") as f:
langs_list = json.load(f)
except Exception as e:
raise Exception(f"Error while loading cached files index. {e}")
all_dir_names = {
lang["name"]: (lang["lang"], lang["lang_text"], lang["lang"])
for lang in langs_list
if lang["type"] == "small" and lang["obsolete"] == "false"
}
all_offline_langs = [all_dir_names[pathlib.Path(model_dir).name] for model_dir in ext_path.iterdir() if
model_dir.is_dir() and pathlib.Path(model_dir).name in all_dir_names]
all_offline_langs = [('none', "-- None --", "No selection")] + all_offline_langs
return all_offline_langs
@staticmethod
def cache_online_langs_list() -> None:
"""
Caches the list of online language models by fetching them from the specified URL and
filtering the data. The filtered list is then stored in a local file for later use.
This method retrieves the language model list via an HTTP GET request, processes it
to filter models based on specified criteria, and writes the filtered list to a local
file in JSON format. If any error occurs during the process, it raises an exception.
:raises Exception: If there is an error while writing the filtered data to the file or
during processing.
:return: This method does not return any value.
"""
list_request = requests.get(MODEL_LIST_URL)
if list_request:
try:
with open(LIPSYNC2D_VoskHelper.get_language_list_file(), "w", encoding="utf-8") as f:
full_list = list_request.json()
filter_list = [item for item in full_list if
item["type"] == "small" and item["obsolete"] == "false"]
json.dump(filter_list, f, ensure_ascii=False)
except Exception as e:
raise Exception(f"Error while creating cached file index: {e}")
@staticmethod
def get_language_list_file() -> pathlib.Path:
"""
Gets the path to the languages list file.
This method retrieves the path to the JSON file that contains the list of
languages for the application. The file is stored under a 'cache' directory
within the extension path.
:return: The pathlib.Path object representing the location of the languages
list JSON file.
:rtype: pathlib.Path
"""
return LIPSYNC2D_VoskHelper.get_extension_path("cache") / "languages_list.json"
@staticmethod
def get_available_languages(_, context) -> list[tuple[str, str, str]]:
"""
Retrieve the list of available languages either online or offline.
This method determines available languages based on the applications online
connectivity. When online access is available, it returns the list of languages
available online; otherwise, it retrieves the list of cached languages. Each language entry
is represented by a tuple containing three string elements.
:param _: Placeholder argument, not used in the method.
:param context: Blender context providing information such as the current area,
screen, scene, etc.
:return: A list of tuples representing the available languages. Each tuple consists
of three strings: the language code, a human-readable language name, and
additional language metadata.
:rtype: list[tuple[str, str, str]]
"""
available_langs = LIPSYNC2D_VoskHelper.get_available_langs_online() if bpy.app.online_access else LIPSYNC2D_VoskHelper.get_available_langs_offline()
return available_langs
@staticmethod
def install_model(addon_prefs, context) -> None:
"""
Install a language model for use with the application. This method initializes the
environment, sets up the necessary paths, and spawns a separate process to download
language models asynchronously. It ensures that resources are correctly managed
during the process.
:param addon_prefs: An instance of the addon preferences containing the configuration
settings. Includes current language and status of the download process.
:type addon_prefs: AddonPreferences
:param context: The Blender context in which this method is invoked. Provides access
to the current state of Blender.
:type context: bpy.types.Context
:return: None. The method performs operations asynchronously and handles the
results through callbacks.
:rtype: NoneType
"""
if addon_prefs.current_lang == "none":
return
addon_prefs.is_downloading = True
# Prepare env to ensure process can access to all modules
env = os.environ.copy()
env["PYTHONPATH"] = os.pathsep.join(sys.path)
# Get custom cache path to change vosk default one
vosk_cache_path = LIPSYNC2D_VoskHelper.get_extension_path("cache")
args = [addon_prefs.current_lang, vosk_cache_path]
current_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.dirname(current_dir)
worker_path = os.path.join(project_root, "Workers", "wrk_download_models.py")
LIPSYNC2D_VoskHelper.worker_proc = subprocess.Popen(
[sys.executable, worker_path, *args],
env=env,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
text=True)
bpy.app.timers.register(LIPSYNC2D_VoskHelper.check_worker_finished)
return
@staticmethod
def check_worker_finished() -> float | None:
"""
Checks the state of the worker process for LIPSYNC2D_VoskHelper and updates
related addon preferences if necessary.
This method inspects the current state of the `worker_proc` attribute
belonging to `LIPSYNC2D_VoskHelper`. If the process is still active,
it returns 1. If the process has completed execution, the method performs
additional cleanup tasks, such as resetting the `worker_proc` to None,
retrieving the associated addon preferences from Blender's context,
and updating the `is_downloading` preference flag for the identified addon
(if applicable).
:returns: 1 if the worker process is still active; None otherwise.
:rtype: int or None
"""
if LIPSYNC2D_VoskHelper.worker_proc is None:
return None
if LIPSYNC2D_VoskHelper.worker_proc.poll() is None:
return 1
else:
LIPSYNC2D_VoskHelper.worker_proc = None
all_preferences = bpy.context.preferences
package_name = get_package_name()
if package_name is None or all_preferences is None or all_preferences.addons is None:
return None
addon = all_preferences.addons.get(package_name)
if addon is None or addon.preferences is None:
return
addon.preferences["is_downloading"] = False
return None
@@ -0,0 +1,12 @@
from ...lipsync_types import BpyRenderSettings
class LIPSYNC2D_TimeConversion:
def __init__(self, render_settings: BpyRenderSettings):
self.based_fps = render_settings.fps / render_settings.fps_base
def time_to_frame(self, time: float) -> int:
return round(time * self.based_fps)
def frame_to_time(self, frame: int) -> int:
return round(frame / self.based_fps)
@@ -0,0 +1,23 @@
import bpy
class LIPSYNC2D_Timeline:
@staticmethod
def get_fps_range() -> int:
if bpy.context.scene is None:
return -1
return bpy.context.scene.frame_end - bpy.context.scene.frame_start
@staticmethod
def get_frame_start():
if bpy.context.scene is None:
return -1
return bpy.context.scene.frame_start
@staticmethod
def get_frame_end():
if bpy.context.scene is None:
return -1
return bpy.context.scene.frame_end
@@ -0,0 +1,4 @@
SLOT_POSE_ASSETS_NAME = "LipSync-PoseAssets"
SLOT_SHAPE_KEY_NAME = "LipSync-ShapeKeys"
SLOT_SPRITE_SHEET_NAME = "LipSync-SpriteSheet"
ACTION_SUFFIX_NAME = "LipSyncAction"
@@ -0,0 +1,153 @@
phoneme_to_viseme_arkit_v2 = {
# Silence
"": "sil",
"ʔ": "sil",
"UNK": "sil",
# PP closed lips
"m": "PP",
"b": "PP",
"p": "PP",
# FF upper teeth and lower lip
"f": "FF",
"v": "FF",
# TH tongue between teeth
"θ": "TH",
"ð": "TH",
# CH affricates
"": "CH",
"": "CH",
# SS narrow gap fricatives
"s": "SS",
"z": "SS",
# SH → grouped visually into SS
"ʃ": "SS",
"ʒ": "SS",
"ɕ": "SS",
"ʑ": "SS",
# RR r-like sounds
"r": "RR",
"ɾ": "RR",
"ʁ": "RR",
"ʀ": "RR",
"ɹ": "RR",
"ɻ": "RR",
# DD default consonants
"t": "DD",
"d": "DD",
"ʈ": "DD",
"ɖ": "DD",
"c": "DD",
"ɟ": "DD",
"x": "DD",
"ɣ": "DD",
"h": "DD",
"ɦ": "DD",
"j": "DD",
"ç": "DD",
"ʝ": "DD",
# kk velar stops
"k": "kk",
"g": "kk",
# nn nasal group + "L"
"n": "nn",
"ŋ": "nn",
"ɲ": "nn",
"ɳ": "nn",
"l": "nn",
"ɫ": "nn",
# aa open and low/mid front vowels
"a": "aa",
"aː": "aa",
"ä": "aa",
"æ": "aa",
"ɐ": "aa",
"ɑ": "aa",
"ɑ̃": "aa",
"aɪ": "aa",
"ɛ": "aa",
"ɛː": "aa",
# E mid/closed front vowels
"e": "E",
"eː": "E",
"œ": "E",
"ø": "E",
"ə": "E",
# ih high front
"i": "ih",
"ɪ": "ih",
"y": "ih",
"iː": "ih",
"ʏ": "ih",
# oh mid back / open-mid
"o": "oh",
"ɔ": "oh",
"ɔ̃": "oh",
"ɒ": "oh",
"oː": "oh",
"ʌ": "oh",
# ou high back rounded
"u": "ou",
"uː": "ou",
"ɯ": "ou",
"ɰ": "ou",
"ʊ": "ou",
"w": "ou",
}
visemes_priority = {"sil": 0, "pp": 1, "th": 2}
UNSKIPPABLE_VISEMES = ["sil", "pp", "th", "ff"]
def get_viseme_priority(viseme: str) -> int:
"""Get viseme priority. Lower number = higher priority."""
if not viseme:
return 999 # Lowest priority for invalid visemes
try:
return getattr(visemes_priority, viseme.lower(), 999)
except (AttributeError, TypeError):
return 999 # Default to lowest priority on any error
def viseme_items_mpeg4_v2(self, context):
return [
("sil", "sil", "Silence / Rest"),
("PP", "PP", "P, B, M (closed lips)"),
("FF", "FF", "F, V (teeth on lip)"),
("TH", "TH", "TH, DH (tongue between teeth)"),
("DD", "DD", "T, D, etc. (tongue behind teeth)"),
("kk", "kk", "K, G (velar stops)"),
("CH", "CH", "CH, J (affricates)"),
("SS", "SS", "S, Z, SH, ZH (narrow fricatives)"),
("nn", "nn", "N, NG, L (nasals and laterals)"),
("RR", "RR", "R (r-like sounds)"),
("aa", "aa", "A, Æ (open/low vowels)"),
("E", "E", "E, Ø, Ə (mid front vowels)"),
("ih", "ih", "I, Y (high front vowels)"),
("oh", "oh", "O, ɔ, ʌ (mid back vowels)"),
("ou", "ou", "U, W (high back vowels)"),
("UNK", "unk", "Unknown phoneme"),
]
def phonemes_to_default_sprite_index():
phoneme_map = {
"sil": 0,
"PP": 4,
"FF": 7,
"TH": 1,
"DD": 9,
"kk": 9,
"CH": 10,
"SS": 2,
"nn": 10,
"RR": 3,
"aa": 11,
"E": 8,
"ih": 6,
"oh": 5,
"ou": 5,
"UNK": 0,
}
return phoneme_map
@@ -0,0 +1,32 @@
from __future__ import annotations
from typing import TypedDict
from ..lipsync_types import BpyAction
class WordTiming(TypedDict):
word_frame_start: int
word_frame_end: int
duration: int
class VisemeData(TypedDict):
visemes: list[str]
visemes_len: int
visemes_parts: float
class VisemeSKeyAnimationData(TypedDict):
frame: int
viseme: str
viseme_index: int
value: float
shape_key: str
class VisemeActionAnimationData(TypedDict):
frame: int
viseme: str
action: BpyAction | None
viseme_index: int
action_name: str
@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
@@ -0,0 +1,2 @@
def get_package_name():
return __package__
@@ -0,0 +1,243 @@
import json
import os
import wave
from typing import Literal, cast
import bpy
from vosk import KaldiRecognizer, Model
from ..Core.Animator.LIPSYNC2D_PoseAssetsAnimator import LIPSYNC2D_PoseAssetsAnimator
from ..Core.Animator.LIPSYNC2D_ShapeKeysAnimator import LIPSYNC2D_ShapeKeysAnimator
from ..Core.Animator.LIPSYNC_SpriteSheetAnimator import LIPSYNC_SpriteSheetAnimator
from ..Core.Animator.protocols import LIPSYNC2D_LipSyncAnimator
from ..Core.LIPSYNC2D_DialogInspector import LIPSYNC2D_DialogInspector
from ..Core.LIPSYNC2D_VoskHelper import LIPSYNC2D_VoskHelper
from ..Core.Timeline.LIPSYNC2D_Timeline import LIPSYNC2D_Timeline
from ..LIPSYNC2D_Utils import get_package_name
from ..lipsync_types import BpyObject
class LIPSYNC2D_OT_AnalyzeAudio(bpy.types.Operator):
bl_idname = "sound.cgp_analyze_audio"
bl_label = "Bake audio"
bl_description = "Analyze audio and insert Keyframes on detected phonemes"
bl_options = {"REGISTER", "UNDO"}
animator: LIPSYNC2D_LipSyncAnimator
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.animator: LIPSYNC2D_LipSyncAnimator
@classmethod
def poll(cls, context):
if context.active_object is None:
return False
animator = LIPSYNC2D_OT_AnalyzeAudio.get_animator(context.active_object)
return animator.poll(cls, context)
def execute(
self, context: bpy.types.Context
) -> set[
Literal["RUNNING_MODAL", "CANCELLED", "FINISHED", "PASS_THROUGH", "INTERFACE"]
]:
prefs = context.preferences.addons[get_package_name()].preferences # type: ignore
obj = context.active_object
if (
context.scene is None
or obj is None
or context.scene.sequence_editor is None
):
self.report(type={"ERROR"}, message="No Sequence Editor found")
return {"CANCELLED"}
all_strips = context.scene.sequence_editor.strips_all
has_sound = any(strip.type == "SOUND" for strip in all_strips)
if not has_sound:
self.report(type={"ERROR"}, message="No sound detected in Sequence Editor")
return {"CANCELLED"}
self.set_bake_range()
file_path = extract_audio()
if not os.path.isfile(f"{file_path}"):
self.report(
type={"ERROR"},
message="Error while importing extracted audio WAV file from /tmp",
)
self.reset_bake_range()
return {"CANCELLED"}
model = self.get_model(prefs)
result = self.vosk_recognize_voice(file_path, model)
if "result" not in result:
self.reset_bake_range()
os.remove(file_path) # Need to be removed AFTER vosk_recognize_voice
return {"FINISHED"}
recognized_words = result["result"]
os.remove(file_path) # Need to be removed AFTER vosk_recognize_voice
dialog_inspector = LIPSYNC2D_DialogInspector(context.scene.render)
words = [word["word"] for word in recognized_words]
total_words = len(words)
phonemes = LIPSYNC2D_DialogInspector.extract_phonemes(words, context)
auto_obj = self.get_animator(obj)
auto_obj.setup(obj)
self.auto_insert_keyframes(
auto_obj, obj, recognized_words, dialog_inspector, total_words, phonemes
)
auto_obj.set_interpolation(obj)
auto_obj.cleanup(obj)
self.reset_bake_range()
if bpy.context.view_layer:
bpy.context.view_layer.update()
self.report(
{"INFO"}, message=f"{auto_obj.inserted_keyframes} keyframes inserted"
)
return {"FINISHED"}
def auto_insert_keyframes(
self,
auto_obj: LIPSYNC2D_LipSyncAnimator,
obj: BpyObject,
recognized_words,
dialog_inspector: LIPSYNC2D_DialogInspector,
total_words,
phonemes,
):
props = obj.lipsync2d_props # type: ignore
words = enumerate(recognized_words)
for index, recognized_word in words:
is_last_word = index == total_words - 1
word_timing = dialog_inspector.get_word_timing(recognized_word)
visemes_data = dialog_inspector.get_visemes(
phonemes[index], word_timing["duration"]
)
next_word_timing = dialog_inspector.get_next_word_timing(
recognized_words, index
)
# Last viseme is inserted a bit before end of word.
# This ensures that delay_until_next_word uses correct timing
corrected_word_end_frame = (
LIPSYNC2D_ShapeKeysAnimator.get_corrected_end_frame(
word_timing["word_frame_start"], visemes_data
)
)
delay_until_next_word = (
next_word_timing["word_frame_start"] - corrected_word_end_frame
)
auto_obj.insert_keyframes(
obj,
props,
visemes_data,
word_timing,
delay_until_next_word,
is_last_word,
index,
)
@staticmethod
def get_animator(obj: BpyObject) -> LIPSYNC2D_LipSyncAnimator:
props = obj.lipsync2d_props # type: ignore
type = props.lip_sync_2d_lips_type
automations = {
"SPRITESHEET": LIPSYNC_SpriteSheetAnimator,
"SHAPEKEYS": LIPSYNC2D_ShapeKeysAnimator,
"POSEASSETS": LIPSYNC2D_PoseAssetsAnimator,
}
return automations[type]()
@LIPSYNC2D_VoskHelper.setextensionpath
def get_model(self, prefs):
model = Model(lang=prefs.current_lang)
return model
def vosk_recognize_voice(self, file_path: str, model: Model):
with wave.open(file_path, "rb") as wf:
# Check audio format
if (
wf.getnchannels() != 1
or wf.getsampwidth() != 2
or wf.getcomptype() != "NONE"
):
raise ValueError("Audio file must be WAV format mono PCM.")
# Setup recognizer
rec = KaldiRecognizer(model, wf.getframerate())
rec.SetWords(True)
# Read and process audio
while True:
data = wf.readframes(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
pass
result = json.loads(rec.FinalResult())
return result
def set_bake_range(self) -> None:
if bpy.context.scene is None:
return
props = bpy.context.active_object.lipsync2d_props # type: ignore
bake_start = props.lip_sync_2d_bake_start
bake_end = props.lip_sync_2d_bake_end
use_bake_range = props.lip_sync_2d_use_bake_range
if not use_bake_range:
return
self.frame_start = LIPSYNC2D_Timeline.get_frame_start()
self.frame_end = LIPSYNC2D_Timeline.get_frame_end()
bpy.context.scene.frame_start = max(0, bake_start)
# Bake end should never be lower than bake start
bpy.context.scene.frame_end = max(bake_start, bake_end)
def reset_bake_range(self) -> None:
if bpy.context.scene is None:
return
props = bpy.context.active_object.lipsync2d_props # type: ignore
use_bake_range = props.lip_sync_2d_use_bake_range
if not use_bake_range:
return
bpy.context.scene.frame_start = self.frame_start
bpy.context.scene.frame_end = self.frame_end
def extract_audio():
package_name = cast(str, get_package_name())
output_path = bpy.utils.extension_path_user(package_name, path="tmp", create=True)
filepath = os.path.join(output_path, "cgp_lipsync_extracted_audio.wav")
bpy.ops.sound.mixdown(
filepath=filepath,
check_existing=False,
container="WAV",
codec="PCM",
format="S16",
mixrate=16000, # Sample rate for Vosk
channels="MONO", # Vosk prefers mono
)
return filepath
@@ -0,0 +1,19 @@
from typing import Literal
import bpy
from bpy.types import Context
from ..Preferences.LIPSYNC2D_AP_Preferences import LIPSYNC2D_VoskHelper
class LIPSYNC2D_OT_DownloadModelsList(bpy.types.Operator):
bl_idname = "wm.lipsync_download_list"
bl_label="Refresh Models List"
bl_description="Reuires Online Access. Fetch a new models list. Use this if models list is empty / incomplete."
def execute(self, context: Context) -> set[Literal['RUNNING_MODAL', 'CANCELLED', 'FINISHED', 'PASS_THROUGH', 'INTERFACE']]:
try:
LIPSYNC2D_VoskHelper.cache_online_langs_list()
except:
self.report({'ERROR'}, "Unable to fetch a new models list")
self.report({'INFO'}, "New list has been downloaded!")
return {'FINISHED'}
@@ -0,0 +1,72 @@
from typing import Literal
import bpy
from ..Core.constants import (
ACTION_SUFFIX_NAME,
SLOT_POSE_ASSETS_NAME,
SLOT_SHAPE_KEY_NAME,
SLOT_SPRITE_SHEET_NAME,
)
from ..lipsync_types import BpyContext
class LIPSYNC2D_OT_RemoveAnimations(bpy.types.Operator):
bl_idname = "object.remove_lip_sync_animations"
bl_label = "Remove Animations"
bl_description = (
"Remove Lip Sync Animation Data from your Object. "
"\n"
"\nSK: ShapeKeys Animation Data."
"\nSPT: Sprite Sheet Animation Data."
"\nall: Remove the entire Action"
)
bl_options = {"UNDO"}
animation_type: bpy.props.StringProperty(name="animation_type") # type: ignore
@classmethod
def poll(cls, context: BpyContext) -> bool:
return context.active_object is not None
def execute(
self, context: BpyContext
) -> set[
Literal["RUNNING_MODAL", "CANCELLED", "FINISHED", "PASS_THROUGH", "INTERFACE"]
]:
obj = context.active_object
if obj is None:
return {"FINISHED"}
action = bpy.data.actions.get(f"{obj.name}-{ACTION_SUFFIX_NAME}")
if action is not None:
if self.animation_type == "ALL":
bpy.data.actions.remove(action)
self.report({"INFO"}, message="Animation successfully removed!")
return {"FINISHED"}
slots = []
if self.animation_type == "SHAPEKEYS":
slots = [action.slots.get(f"KE{SLOT_SHAPE_KEY_NAME}")]
elif self.animation_type == "SPRITESHEET":
slots = [action.slots.get(f"OB{SLOT_SPRITE_SHEET_NAME}")]
elif self.animation_type == "POSEASSETS":
slots = [action.slots.get(f"OB{SLOT_POSE_ASSETS_NAME}")]
for slot in slots:
if slot is not None:
action.slots.remove(slot)
if all(slot is not None for slot in slots):
self.report({"INFO"}, message="Animation successfully removed!")
else:
self.report({"WARNING"}, message="Slot not found.")
else:
self.report(
{"WARNING"}, message="Action not found. Cannot remove Animation."
)
return {"FINISHED"}
@@ -0,0 +1,50 @@
from typing import Literal
import bpy
from bpy.types import Context
from ..Core.constants import ACTION_SUFFIX_NAME
from .LIPSYNC2D_OT_RemoveNodeGroups import LIPSYNC2D_OT_RemoveNodeGroups
class LIPSYNC2D_OT_RemoveLipSync(bpy.types.Operator):
bl_idname = "object.remove_lip_sync_from_selection"
bl_label = "Remove Lip Sync"
bl_description = "Remove all Lip Sync properties from the selection. All custom settings will be forever lost"
bl_options = {"REGISTER", "UNDO"}
def execute(
self, context: Context
) -> set[
Literal["RUNNING_MODAL", "CANCELLED", "FINISHED", "PASS_THROUGH", "INTERFACE"]
]:
obj = context.active_object
if obj is None:
self.report(
{"ERROR"},
message="Lip Sync cannot be removed! Please, select an Active Object",
)
return {"FINISHED"}
elif "lipsync2d_props" in obj:
second_message = ""
if obj.lipsync2d_props.lip_sync_2d_remove_animation_data: # type: ignore
action = bpy.data.actions.get(f"{obj.name}-{ACTION_SUFFIX_NAME}")
if action is not None:
bpy.data.actions.remove(action)
else:
second_message = f"Could not remove the Action. Try do it manually."
if obj.lipsync2d_props.lip_sync_2d_remove_cgp_node_group: # type: ignore
LIPSYNC2D_OT_RemoveNodeGroups.remove_nodes_from_materials(obj)
del obj["lipsync2d_props"]
self.report(
{"INFO"}, message=f"Lip Sync successfully removed! {second_message}"
)
return {"FINISHED"}
@@ -0,0 +1,64 @@
from typing import Literal
import bpy
from .LIPSYNC2D_OT_SetCustomProperties import link_nodes
from ..lipsync_types import BpyContext, BpyObject
class LIPSYNC2D_OT_RemoveNodeGroups(bpy.types.Operator):
bl_idname = "object.remove_lip_sync_node_groups"
bl_label = "Remove Node Groups"
bl_description = "Remove Lip Sync's node groups from Object's Materials"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: BpyContext) -> bool:
return context.active_object is not None
def execute(self, context: BpyContext) -> set[
Literal['RUNNING_MODAL', 'CANCELLED', 'FINISHED', 'PASS_THROUGH', 'INTERFACE']]:
obj = context.active_object
if obj is None:
self.report({'ERROR'}, message="Please, select an active object")
return {'FINISHED'}
message = LIPSYNC2D_OT_RemoveNodeGroups.remove_nodes_from_materials(obj)
self.report({'INFO'}, message=message)
return {'FINISHED'}
@staticmethod
def remove_nodes_from_materials(obj: BpyObject):
materials = [m.material for m in obj.material_slots]
prev_node = None
next_node = None
for m in materials:
if m is None or m.node_tree is None:
continue
main_group = m.node_tree.nodes.get("cgp_main_group")
if main_group:
for input in main_group.inputs:
if input.name == "Shader":
links = input.links
if links and len(links) > 0:
prev_node = links[0].from_node
for output in main_group.outputs:
if output.name == "Output":
links = output.links
if links and len(links) > 0:
next_node = links[0].to_node
m.node_tree.nodes.remove(main_group)
if prev_node and next_node and m.node_tree:
link_nodes(m.node_tree, prev_node, next_node, 0, 0)
message = "Nodes successfully removed!" if prev_node and next_node else "Nodes were not found"
return message
@@ -0,0 +1,346 @@
import os
from typing import Literal, cast
import bpy
from ..Core.phoneme_to_viseme import (
phonemes_to_default_sprite_index,
viseme_items_mpeg4_v2 as viseme_items,
)
from ..Core.LIPSYNC2D_SpritesheetNode import (
cgp_spriteratio_node_group,
cgp_spritesheet_reader_node_group,
)
class LIPSYNC2D_OT_SetCustomProperties(bpy.types.Operator):
bl_idname = "object.set_lipsync_custom_properties"
bl_label = "Set Lips Material"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context: bpy.types.Context) -> bool:
obj = context.active_object
return (
obj is not None
and (obj.type == "MESH" or obj.type == "ARMATURE")
and (
not hasattr(obj, "lipsync2d_props")
or context.active_object.lipsync2d_props.lip_sync_2d_initialized # type: ignore
== False
)
) # type: ignore
def execute(
self, context: bpy.types.Context
) -> set[
Literal["RUNNING_MODAL", "CANCELLED", "FINISHED", "PASS_THROUGH", "INTERFACE"]
]:
if context.active_object is None:
return {"CANCELLED"}
create_custom_prop(context.active_object)
if context.active_object.type == "MESH":
context.active_object.lipsync2d_props.lip_sync_2d_sprite_sheet = add_default_image_spritesheet() # type: ignore
return {"FINISHED"}
def add_default_image_spritesheet():
image = bpy.data.images.get("CGP_default_spritesheet_visemes")
if image is None:
spritesheet_path = os.path.join(
os.path.dirname(__file__),
"..",
"Assets",
"Images",
"spritesheet_visemes.png",
)
image = bpy.data.images.new(
"CGP_default_spritesheet_visemes", width=512, height=6144
)
image.source = "FILE"
image.filepath = spritesheet_path
return image
def create_custom_prop(obj: bpy.types.Object):
obj.lipsync2d_props.lip_sync_2d_initialized = True # type: ignore
obj.lipsync2d_props.lip_sync_2d_sprite_sheet = None # type: ignore
obj.lipsync2d_props.lip_sync_2d_main_material = None # type: ignore
obj.lipsync2d_props.lip_sync_2d_sprite_sheet_columns = 1 # type: ignore
obj.lipsync2d_props.lip_sync_2d_sprite_sheet_rows = 12 # type: ignore
obj.lipsync2d_props.lip_sync_2d_sprite_sheet_sprite_scale = 1 # type: ignore
obj.lipsync2d_props.lip_sync_2d_sprite_sheet_main_scale = 1 # type: ignore
obj.lipsync2d_props.lip_sync_2d_sprite_sheet_index = 0 # type: ignore
obj.lipsync2d_props.lip_sync_2d_sprite_sheet_format = "VLINE" # type: ignore
obj.lipsync2d_props.lip_sync_2d_lips_type = "SPRITESHEET" if obj.type == "MESH" else "POSEASSETS" # type: ignore
obj.lipsync2d_props["lip_sync_2d_viseme_shape_keys"] = 0 # type: ignore
obj.lipsync2d_props.lip_sync_2d_in_between_threshold = 0.0417 # type: ignore
obj.lipsync2d_props["lip_sync_2d_bake_start"] = 0 # type: ignore
obj.lipsync2d_props["lip_sync_2d_bake_end"] = 0 # type: ignore
visemes = viseme_items(None, None)
mapping = phonemes_to_default_sprite_index()
for v in visemes:
enum_id, _, _ = v
prop_name = f"lip_sync_2d_viseme_{enum_id}"
actual_value = getattr(obj.lipsync2d_props, prop_name) # type: ignore
value = actual_value if actual_value != -1 else mapping[enum_id]
setattr(obj.lipsync2d_props, prop_name, value) # type: ignore
def add_spritesheet_node_to_mat(
active_obj,
material: bpy.types.Material,
spritesheet_reader: bpy.types.ShaderNodeTree,
):
if material.node_tree is None:
return
main_group = cast(
bpy.types.ShaderNodeGroup, material.node_tree.nodes.new("ShaderNodeGroup")
)
main_group.name = "cgp_main_group"
main_group.node_tree = cast(
bpy.types.ShaderNodeTree,
bpy.data.node_groups.new("cgp_main_group", type="ShaderNodeTree"),
)
if main_group.node_tree.interface is None:
return
main_group.node_tree.interface.new_socket(
"Shader", in_out="INPUT", socket_type="NodeSocketShader"
)
main_group.node_tree.interface.new_socket(
"Output", in_out="OUTPUT", socket_type="NodeSocketShader"
)
group_input = cast(
bpy.types.ShaderNodeGroup, main_group.node_tree.nodes.new("NodeGroupInput")
)
group_output = cast(
bpy.types.ShaderNodeGroup, main_group.node_tree.nodes.new("NodeGroupOutput")
)
group = cast(
bpy.types.ShaderNodeGroup, main_group.node_tree.nodes.new("ShaderNodeGroup")
)
group.name = "cgp_spritesheet_reader"
principled = cast(
bpy.types.ShaderNodeGroup,
main_group.node_tree.nodes.new("ShaderNodeBsdfPrincipled"),
)
mix_shader = main_group.node_tree.nodes.new("ShaderNodeMixShader")
# group1.node_tree.nodes.new(mix_shader.bl_idname)
for node in material.node_tree.nodes:
if node.bl_idname == "ShaderNodeOutputMaterial":
x_offset = 800
next_node = node
# Quick & Dirty way to reposition nodes to prevent node stacking
initial_output_node_loc = next_node.location.copy()
main_group.location.x += principled.width + x_offset / 4
main_group.location.y = next_node.location.y
next_node.location.x = main_group.location.x + x_offset / 2
mix_shader.location = initial_output_node_loc
mix_shader.location.x += x_offset / 1.3 + x_offset / 4
principled.location = initial_output_node_loc
principled.location.x += x_offset / 4 + x_offset / 4
principled.location.y -= principled.height
group.location = initial_output_node_loc
group.location.y -= group.height
group.location.x += x_offset / 4
group_output.location.x = group_output.width + mix_shader.location.x + 100
group_output.location.y = mix_shader.location.y
group_input.location.x = group.location.x
group_input.location.y = mix_shader.location.y
inputs_name = node.inputs.keys()
for input_name in inputs_name:
if input_name == "Surface":
node_links = node.inputs[input_name].links
if node_links is None:
continue
for link in node_links:
prev_node = link.from_node
if prev_node is None:
return
group.node_tree = spritesheet_reader
material.node_tree.links.remove(link)
# Connect Input group to Mix Node
link_nodes(main_group.node_tree, group_input, mix_shader, 0, 1)
# Connect spritesheet Node to new Principled Node
link_nodes(main_group.node_tree, group, principled, 0, 0)
# Connect spritesheet Node Specular to new Principled Node
link_nodes(main_group.node_tree, group, principled, 2, 13)
# Connect spritesheet Node Roughness to new Principled Node
link_nodes(main_group.node_tree, group, principled, 3, 2)
# Connect spritesheet Node to Mix Node
link_nodes(main_group.node_tree, group, mix_shader, 1, 0)
# Connect previous node to Mix Node
link_nodes(material.node_tree, prev_node, main_group, 0, 0)
# Connect new Principled BSDF to Mix Node
link_nodes(main_group.node_tree, principled, mix_shader, 0, 2)
# Connect Mix Shader to output
link_nodes(material.node_tree, main_group, next_node, 0, 0)
# Connect Mix Node to Output group
link_nodes(main_group.node_tree, mix_shader, group_output, 0, 0)
column_field = (
'nodes["cgp_spritesheet_reader"].inputs[1].default_value'
)
rows_field = (
'nodes["cgp_spritesheet_reader"].inputs[2].default_value'
)
index_field = (
'nodes["cgp_spritesheet_reader"].inputs[0].default_value'
)
sprite_scale_field = (
'nodes["cgp_spritesheet_reader"].inputs[3].default_value'
)
main_scale_field = (
'nodes["cgp_spritesheet_reader"].inputs[4].default_value'
)
add_object_driver(
main_group.node_tree,
column_field,
active_obj,
"lipsync2d_props.lip_sync_2d_sprite_sheet_columns",
)
add_object_driver(
main_group.node_tree,
rows_field,
active_obj,
"lipsync2d_props.lip_sync_2d_sprite_sheet_rows",
)
add_object_driver(
main_group.node_tree,
index_field,
active_obj,
"lipsync2d_props.lip_sync_2d_sprite_sheet_index",
)
add_object_driver(
main_group.node_tree,
sprite_scale_field,
active_obj,
"lipsync2d_props.lip_sync_2d_sprite_sheet_sprite_scale",
)
add_object_driver(
main_group.node_tree,
main_scale_field,
active_obj,
"lipsync2d_props.lip_sync_2d_sprite_sheet_main_scale",
)
def link_nodes(
node_tree: bpy.types.NodeTree,
output_node: bpy.types.Node,
input_node: bpy.types.Node,
output_socket: int,
input_socket: int,
):
output = output_node.outputs[output_socket]
input = input_node.inputs[input_socket]
node_tree.links.new(input, output)
def create_spritesheet_nodes(
context: bpy.types.Context, material: bpy.types.Material
) -> bpy.types.ShaderNodeTree:
node_sprite_ratio = bpy.data.node_groups.get("CGP_SpriteRatio")
nodes_spritesheet_reader = cast(
bpy.types.ShaderNodeTree, bpy.data.node_groups.get("cgp_spritesheet_reader")
)
if isinstance(nodes_spritesheet_reader, bpy.types.ShaderNodeTree):
return nodes_spritesheet_reader.copy()
# TODO: Here we could have an issue if node is found but is not a shadernodetree. See if we should delete it or not
# TODO: context.active_object should always be valid, but maybe object should be passed as argument
if node_sprite_ratio is None:
node_sprite_ratio = cgp_spriteratio_node_group()
if nodes_spritesheet_reader is None:
nodes_spritesheet_reader = cast(
bpy.types.ShaderNodeTree,
cgp_spritesheet_reader_node_group(
node_sprite_ratio,
context.active_object.lipsync2d_props.lip_sync_2d_sprite_sheet, # type: ignore
),
) # type: ignore
return nodes_spritesheet_reader
def get_or_create_material(
obj: bpy.types.Object, material_index: int
) -> bpy.types.Material:
if not obj or obj.type != "MESH" or not isinstance(obj.data, bpy.types.Mesh):
raise TypeError("Object must be a mesh")
# If there's already a material in the first slot
if (
obj.material_slots
and material_index >= 0
and material_index < len(obj.material_slots)
):
mat = obj.material_slots[material_index].material
if mat:
return mat
# No material? Create one
new_mat = bpy.data.materials.new(name="CGP_LipsAutoMaterial")
new_mat.use_nodes = True
# Make sure there's at least one slot
if not obj.material_slots:
obj.data.materials.append(new_mat)
else:
obj.material_slots[0].material = new_mat
return new_mat
def add_object_driver(
target: bpy.types.ID,
target_property: str,
ref_obj: bpy.types.ID,
data_path: str,
expression: str = "var",
):
"""Add a driver to a node socket (input) inside a material."""
fcurve = cast(bpy.types.FCurve, target.driver_add(target_property))
driver = fcurve.driver
if driver is None:
return
driver.type = "SCRIPTED"
var = driver.variables.new()
var.name = "var"
var.targets[0].data_path = data_path
var.targets[0].id = ref_obj
var.type = "SINGLE_PROP"
driver.expression = expression
@@ -0,0 +1,218 @@
import functools
from typing import Literal, TypedDict, cast
import bmesh
import bpy
import mathutils
from .LIPSYNC2D_OT_SetCustomProperties import add_default_image_spritesheet, add_spritesheet_node_to_mat, \
create_spritesheet_nodes, get_or_create_material
class ViewState(TypedDict):
location: mathutils.Vector
rotation: mathutils.Quaternion
distance: float
perspective: Literal['PERSP', 'ORTHO', 'CAMERA']
class LIPSYNC2D_OT_SetMouthArea(bpy.types.Operator):
bl_idname = "mesh.set_lips_area"
bl_label = "Set Lips Area"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
obj = context.active_object
return obj is not None and obj.mode == 'EDIT' and obj.type == 'MESH'
def execute(self, context: bpy.types.Context) -> set[
Literal['RUNNING_MODAL', 'CANCELLED', 'FINISHED', 'PASS_THROUGH', 'INTERFACE']]:
obj = context.active_object
if obj is None:
return {'CANCELLED'}
if obj and obj.mode == 'EDIT' and isinstance(obj.data, bpy.types.Mesh):
mesh = obj.data
bm = bmesh.from_edit_mesh(mesh)
LIPSYNC2D_OT_SetMouthArea.edit_face_material(context, obj, bm)
view_state = LIPSYNC2D_OT_SetMouthArea.change_view(bm)
LIPSYNC2D_OT_SetMouthArea.set_shading(context)
if view_state is not None and context.area is not None:
activate_area_info = get_area_identifier(context.area)
bpy.app.timers.register(functools.partial(uv_unwrap_selection, activate_area_info, view_state),
first_interval=.01)
return {'FINISHED'}
@staticmethod
def set_shading(context):
if context.screen is not None and context.area is not None:
for area in context.screen.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
space_view3d = cast(bpy.types.SpaceView3D, space)
space_view3d.shading.type = "MATERIAL"
@staticmethod
def change_view(bm):
selected_faces_normals = sum([f.normal for f in bm.faces if f.select], mathutils.Vector())
average_normal = selected_faces_normals.normalized()
quat = average_normal.to_track_quat('Z', 'Y')
view_state = align_view_to_selection(quat)
return view_state
@staticmethod
def edit_face_material(context: bpy.types.Context, obj: bpy.types.Object, bm: bmesh.types.BMesh):
face_material_indices = [f.material_index for f in bm.faces if f.select]
material_index = face_material_indices[0] if len(face_material_indices) > 0 else -1
main_material = get_or_create_material(obj, material_index)
obj.lipsync2d_props.lip_sync_2d_main_material = main_material # type: ignore
nodes_spritesheet_reader = get_spritesheet_reader_from_mat(main_material)
if nodes_spritesheet_reader is None:
nodes_spritesheet_reader = create_spritesheet_nodes(context, main_material)
if nodes_spritesheet_reader is None:
return {'CANCELLED'}
add_spritesheet_node_to_mat(context.active_object, main_material, nodes_spritesheet_reader)
context.active_object.lipsync2d_props.lip_sync_2d_sprite_sheet = add_default_image_spritesheet() # type: ignore
def get_spritesheet_reader_from_mat(main_material: bpy.types.Material):
material_node_tree = main_material.node_tree
nodes_spritesheet_reader = None
if material_node_tree is not None:
nodes_spritesheet_reader = material_node_tree.nodes.get("cgp_main_group")
return nodes_spritesheet_reader
def uv_unwrap_selection(activate_area_info: tuple[float, float, float, float, str], view_state: ViewState) -> None:
obj = bpy.context.active_object
if obj is None or not isinstance(obj.data, bpy.types.Mesh):
return
if bpy.context.window is None:
return
mesh = obj.data
bm = bmesh.from_edit_mesh(mesh)
selected_faces = [f for f in bm.faces if f.select]
uv_layer = None
uv_layer_name = 'Mouth'
previous_active_uv = mesh.uv_layers.active_index
if not uv_layer_name:
return
uv_layer = bm.loops.layers.uv.get(uv_layer_name)
if uv_layer is None:
uv_layer = bm.loops.layers.uv.new(uv_layer_name)
if not uv_layer:
raise Exception("No UV map found.")
mesh = obj.data
uv_index = mesh.uv_layers.find(uv_layer_name)
if uv_index != -1:
mesh.uv_layers.active_index = uv_index
for area in bpy.context.window.screen.areas:
if get_area_identifier(area) == activate_area_info:
for region in area.regions:
if region.type == 'WINDOW':
override = bpy.context.copy()
override["area"] = area
override["region"] = region
if area.spaces.active is None:
break
space = cast(bpy.types.SpaceView3D, area.spaces.active)
override["space_data"] = space
override["region_data"] = space.region_3d
with bpy.context.temp_override(**override):
bpy.ops.uv.project_from_view(orthographic=True, scale_to_bounds=True)
# TODO: Unwrap unselected faces and move them out
unselected = [f for f in bm.faces if not f.select]
for e in bm.edges:
e.select_set(False)
for f in bm.faces:
f.select_set(False)
for v in bm.verts:
v.select_set(False)
for f in unselected:
f.select_set(True)
bpy.ops.uv.unwrap()
for face in unselected:
for loop in face.loops:
loop[uv_layer].uv = mathutils.Vector([-.1, 0])
# TODO: Rotate uv island to cancel view rotation
for f in unselected:
f.select_set(False)
for f in selected_faces:
f.select_set(True)
break
mesh.uv_layers.active_index = previous_active_uv
return None
def get_area_identifier(area: bpy.types.Area):
return (area.x, area.y, area.width, area.height, area.type)
def save_view_state(region_3d: bpy.types.RegionView3D) -> ViewState:
return {
"location": region_3d.view_location.copy(),
"rotation": region_3d.view_rotation.copy(),
"distance": region_3d.view_distance,
"perspective": region_3d.view_perspective,
}
def restore_view_state(region_3d: bpy.types.RegionView3D, view_state: ViewState, only_perspective: bool = True):
if only_perspective is False:
region_3d.view_location = view_state["location"]
region_3d.view_rotation = view_state["rotation"]
region_3d.view_distance = view_state["distance"]
region_3d.view_perspective = view_state["perspective"]
def align_view_to_selection(quat: mathutils.Quaternion) -> ViewState | None:
if bpy.context.window is None:
return None
for area in bpy.context.window.screen.areas:
if area.type == 'VIEW_3D':
for region in area.regions:
if region.type == 'WINDOW':
space = cast(bpy.types.SpaceView3D, area.spaces.active)
region_3d = space.region_3d
if region_3d is None: break
view_state = save_view_state(region_3d)
region_3d.view_rotation = quat
return view_state
return None
@@ -0,0 +1,55 @@
from pathlib import Path
from typing import Literal
import bpy
class LIPSYNC2D_OT_refresh_pose_assets(bpy.types.Operator):
bl_idname = "lipsync2d.refresh_pose_assets"
bl_label = "Refresh Pose Assets"
bl_description = "Only use this if your Asset Poses are not shown.\nIt will load all Pose Assets from your assets libraries into your current .blend."
def execute(
self, context
) -> set[
Literal["RUNNING_MODAL", "CANCELLED", "FINISHED", "PASS_THROUGH", "INTERFACE"]
]:
self.load_pose_assets_from_libraries()
# Count loaded pose assets
pose_asset_count = sum(1 for action in bpy.data.actions if action.asset_data)
self.report({"INFO"}, f"Loaded {pose_asset_count} pose assets")
return {"FINISHED"}
def load_pose_assets_from_libraries(self):
"""Load pose assets from all configured asset libraries using bpy.data.libraries.load"""
# Get asset library preferences
prefs = bpy.context.preferences
if prefs is None:
return
filepaths = prefs.filepaths
asset_libraries = filepaths.asset_libraries
for asset_library in asset_libraries:
library_path = Path(asset_library.path)
if not library_path.exists():
continue
# Find all .blend files in the library
blend_files = [fp for fp in library_path.rglob("*.blend") if fp.is_file()]
for blend_file in blend_files:
try:
# Load only assets from the file
with bpy.data.libraries.load(str(blend_file), assets_only=True) as (
data_from,
data_to,
):
# Load all actions that are assets (pose assets)
data_to.actions = data_from.actions
except Exception as e:
continue
@@ -0,0 +1,104 @@
from typing import cast
import bpy
from ..LIPSYNC2D_Utils import get_package_name
from ..lipsync_types import BpyContext, BpyObject, BpyPropertyGroup, BpyUILayout
class AnimatorPanelMixin:
def __init__(self, obj: BpyObject):
self.package_name = get_package_name()
self.prefs: bpy.types.AddonPreferences | None = None
self.obj: BpyObject = obj
lipsync_props = self.obj.lipsync2d_props # type: ignore
self.props: bpy.types.PropertyGroup = cast(BpyPropertyGroup, lipsync_props)
if (
self.package_name
and bpy.context.preferences is not None
and self.package_name in bpy.context.preferences.addons
):
self.prefs = bpy.context.preferences.addons[self.package_name].preferences
self.current_lang = self.prefs.current_lang if self.prefs is not None else None # type: ignore
self.is_model_installed = (
True if self.current_lang not in ["", "none"] else False
)
def draw_animation_section(self, context: BpyContext, layout: BpyUILayout):
raise NotImplementedError()
def draw_visemes_section(self, context: BpyContext, layout: BpyUILayout):
raise NotImplementedError()
def draw_animator_section(self, context: BpyContext, layout: BpyUILayout):
raise NotImplementedError()
def draw_edit_section(self, context: BpyContext, layout: BpyUILayout):
row = layout.row()
row.label(text="Clean Up:")
box = layout.box()
row = box.row()
row.label(text="Shader Editor:")
row = box.row()
row.operator("object.remove_lip_sync_node_groups")
box = layout.box()
row = box.row()
row.label(text="Animation:")
row = box.row()
operator = row.operator("object.remove_lip_sync_animations", text="Remove SK")
operator.animation_type = "SHAPEKEYS" # type: ignore
operator = row.operator("object.remove_lip_sync_animations", text="Remove SPT")
operator.animation_type = "SPRITESHEET" # type: ignore
row = box.row()
operator = row.operator(
"object.remove_lip_sync_animations", text="Remove all Animations"
)
operator.animation_type = "ALL" # type: ignore
box = layout.box()
row = box.row()
row.prop(self.props, "lip_sync_2d_remove_animation_data")
row.prop(self.props, "lip_sync_2d_remove_cgp_node_group")
row = box.row()
row.alert = True
row.operator("object.remove_lip_sync_from_selection")
def draw_baking_section(self, context: BpyContext, layout: BpyUILayout):
if not self.is_model_installed:
new_row = layout.row()
new_row.label(
text="Select a Language Model before Analyzing audio",
icon="WARNING_LARGE",
)
new_row = layout.row()
new_row.operator(
"sound.cgp_analyze_audio", text="Bake audio", icon="SCRIPTPLUGINS"
)
new_row.enabled = self.is_model_installed
def draw_bake_section(self, context: BpyContext, layout: BpyUILayout):
panel_head, panel_body = layout.panel(
"cgp_lipsync_bake_settings_dropdown", default_closed=True
)
panel_head.label(text="Bake Settings")
if panel_body is not None:
row = panel_body.row()
row.label(text="Misc:")
row = panel_body.row()
row.prop(self.props, "lip_sync_2d_use_clear_keyframes")
row = panel_body.row()
row.label(text="Range:")
row = panel_body.row()
row.prop(self.props, "lip_sync_2d_use_bake_range")
row = panel_body.row(align=True)
row.prop(self.props, "lip_sync_2d_bake_start", text="Start")
row.prop(self.props, "lip_sync_2d_bake_end", text="End")
row.enabled = self.props.lip_sync_2d_use_bake_range # type: ignore
@@ -0,0 +1,117 @@
import bpy
from ..lipsync_types import BpyObject
from .AnimatorPanelMixin import AnimatorPanelMixin
from ..Core.phoneme_to_viseme import viseme_items_mpeg4_v2 as viseme_items
from ..lipsync_types import BpyContext, BpyUILayout
class AnimatorPanelPoseAssetsStrategy(AnimatorPanelMixin):
def __init__(self, obj: BpyObject):
super().__init__(obj)
if not isinstance(obj.data, bpy.types.Mesh):
return
def draw_animator_section(self, context: BpyContext, layout: BpyUILayout):
panel_header, panel_body = layout.panel(
"vpg_lipsync_animator_dropdown", default_closed=True
)
panel_header.label(text="Rig Settings")
if panel_body is not None:
row = panel_body.row()
row.label(text="Rig Type")
row = panel_body.row(align=True)
row.prop(self.props, "lip_sync_2d_rig_type_basic", toggle=True)
row.prop(self.props, "lip_sync_2d_rig_type_advanced", toggle=True)
panel_body.separator(factor=1)
def draw_animation_section(self, context: BpyContext, layout: BpyUILayout):
panel_header, panel_body = layout.panel(
"cgp_lipsync_animation_dropdown", default_closed=False
)
panel_header.label(text="Animation Settings")
if panel_body is not None:
row = panel_body.row()
row.label(text="Motion:")
row = panel_body.row()
row.prop(self.props, "lip_sync_2d_close_motion_duration")
self.draw_thresholds(self.props, panel_body)
row = panel_body.row()
row.prop(self.props, "lip_sync_2d_prioritize_accuracy", toggle=True)
def draw_visemes_section(self, context: BpyContext, layout: BpyUILayout):
panel_head, panel_body = layout.panel(
"cgp_lipsync_viseme_dropdown", default_closed=False
)
panel_head.label(text="Viseme Settings")
if panel_body is not None:
row = panel_body.row(align=True)
row.label(text="Viseme")
row.label(text="Pose")
visemes = viseme_items(None, None)
for i, viseme in enumerate(visemes):
lang_code = list(viseme)[0]
row = panel_body.row(align=True)
row.label(text=f"{lang_code}")
row.prop(self.props, f"lip_sync_2d_viseme_pose_{lang_code}", text="")
def draw_thresholds(self, props, layout):
row = layout.row()
row.label(text="Thresholds:")
data_list = ["lip_sync_2d_in_between_threshold", "lip_sync_2d_sil_threshold"]
row = layout.row()
for data in data_list:
row.prop(props, data)
def draw_baking_section(self, context: BpyContext, layout: BpyUILayout):
if not self.is_model_installed:
new_row = layout.row()
new_row.label(
text="Select a Language Model before Analyzing audio",
icon="WARNING_LARGE",
)
new_row = layout.row()
new_row.operator(
"sound.cgp_analyze_audio", text="Bake audio", icon="SCRIPTPLUGINS"
)
new_row.enabled = self.is_model_installed
def draw_edit_section(self, context: BpyContext, layout: BpyUILayout):
row = layout.row()
row.label(text="Pose Assets:")
box = layout.box()
row = box.row(align=True)
row.operator("lipsync2d.refresh_pose_assets")
row = layout.row()
row.label(text="Clean Up:")
box = layout.box()
row = box.row()
row.label(text="Animation:")
row = box.row()
operator = row.operator(
"object.remove_lip_sync_animations", text="Remove Pose Animation"
)
operator.animation_type = "POSEASSETS" # type: ignore
row = box.row()
operator = row.operator(
"object.remove_lip_sync_animations", text="Remove all Animations"
)
operator.animation_type = "ALL" # type: ignore
box = layout.box()
row = box.row()
row.prop(self.props, "lip_sync_2d_remove_animation_data")
row = box.row()
row.alert = True
row.operator("object.remove_lip_sync_from_selection")
@@ -0,0 +1,100 @@
import bpy
from ..lipsync_types import BpyObject
from .AnimatorPanelMixin import AnimatorPanelMixin
from ..Core.phoneme_to_viseme import viseme_items_mpeg4_v2 as viseme_items
from ..lipsync_types import BpyContext, BpyUILayout
class AnimatorPanelShapeKeysStrategy(AnimatorPanelMixin):
def __init__(self, obj: BpyObject):
super().__init__(obj)
if not isinstance(obj.data, bpy.types.Mesh):
return
self.at_least_two_shape_keys = bool(
(
obj.data
and obj.data.shape_keys
and obj.data.shape_keys.key_blocks.__len__() > 1
)
)
self.is_relative = bool(
(obj.data and obj.data.shape_keys and obj.data.shape_keys.use_relative)
)
def draw_animator_section(self, context: BpyContext, layout: BpyUILayout):
pass
def draw_animation_section(self, context: BpyContext, layout: BpyUILayout):
panel_header, panel_body = layout.panel(
"cgp_lipsync_animation_dropdown", default_closed=False
)
panel_header.label(text="Animation Settings")
if panel_body is not None:
row = panel_body.row()
row.label(text="Motion:")
row = panel_body.row()
row.prop(self.props, "lip_sync_2d_close_motion_duration")
self.draw_thresholds(self.props, panel_body)
def draw_visemes_section(self, context: BpyContext, layout: BpyUILayout):
panel_head, panel_body = layout.panel(
"cgp_lipsync_viseme_dropdown", default_closed=True
)
panel_head.label(text="Viseme Settings")
if panel_body is not None:
row = panel_body.row(align=True)
row.label(text="Viseme")
row.label(text="Shape Key")
visemes = viseme_items(None, None)
for i, viseme in enumerate(visemes):
lang_code = list(viseme)[0]
row = panel_body.row(align=True)
row.label(text=f"{lang_code}")
row.prop(
self.props, f"lip_sync_2d_viseme_shape_keys_{lang_code}", text=""
)
def draw_thresholds(self, props, layout):
row = layout.row()
row.label(text="Thresholds:")
data_list = ["lip_sync_2d_in_between_threshold", "lip_sync_2d_sil_threshold"]
row = layout.row()
for data in data_list:
row.prop(props, data)
def draw_baking_section(self, context: BpyContext, layout: BpyUILayout):
if not self.is_model_installed:
new_row = layout.row()
new_row.label(
text="Select a Language Model before Analyzing audio",
icon="WARNING_LARGE",
)
if not self.at_least_two_shape_keys:
new_row = layout.row()
new_row.label(
text="Missing Shape Keys",
icon="WARNING_LARGE",
)
if not self.is_relative:
new_row = layout.row()
new_row.label(
text="Shape Keys have to be set to 'Relative'",
icon="WARNING_LARGE",
)
new_row = layout.row()
new_row.operator(
"sound.cgp_analyze_audio", text="Bake audio", icon="SCRIPTPLUGINS"
)
new_row.enabled = (
self.is_model_installed
and self.at_least_two_shape_keys
and self.is_relative
)
@@ -0,0 +1,101 @@
from .AnimatorPanelMixin import AnimatorPanelMixin
from ..Core.phoneme_to_viseme import viseme_items_mpeg4_v2 as viseme_items
from ..lipsync_types import BpyContext, BpyUILayout
class AnimatorPanelSpriteSheetStrategy(AnimatorPanelMixin):
def draw_animator_section(self, context: BpyContext, layout: BpyUILayout):
panel_header, panel_body = layout.panel(
"cgp_lipsync_animator_dropdown", default_closed=False
)
panel_header.label(text="Sprite Sheet Settings")
if panel_body is not None:
row = panel_body.row()
row.label(text="Area")
row = panel_body.row()
row.label(
text="Go in Edit Mode to define Mouth Area",
icon="INFO_LARGE",
)
row = panel_body.row()
row.operator("mesh.set_lips_area", text="Set Mouth Area")
panel_body.separator(factor=1)
row = panel_body.row()
row.label(text="Select your Sprite sheet")
panel_body.template_ID_preview(
self.props,
"lip_sync_2d_sprite_sheet",
rows=2,
cols=6,
open="image.open",
)
panel_body.separator(factor=1)
row = panel_body.row(align=True)
row.label(text="Spritesheet Format")
row.prop(self.props, "lip_sync_2d_sprite_sheet_format", text="")
panel_body.separator(factor=1)
row = panel_body.row(align=True)
if self.props["lip_sync_2d_sprite_sheet_format"] == 3:
row.prop(self.props, "lip_sync_2d_sprite_sheet_rows")
elif self.props["lip_sync_2d_sprite_sheet_format"] == 2:
row.prop(self.props, "lip_sync_2d_sprite_sheet_columns")
elif self.props["lip_sync_2d_sprite_sheet_format"] == 0:
row.prop(self.props, "lip_sync_2d_sprite_sheet_rows")
elif self.props["lip_sync_2d_sprite_sheet_format"] == 1:
row.prop(self.props, "lip_sync_2d_sprite_sheet_columns")
row.prop(self.props, "lip_sync_2d_sprite_sheet_rows")
row = panel_body.row()
row.prop(self.props, "lip_sync_2d_sprite_sheet_index")
panel_body.separator(factor=1)
row = panel_body.row()
row.label(text="Scale")
row = panel_body.row(align=True)
row.prop(self.props, "lip_sync_2d_sprite_sheet_sprite_scale")
row.prop(self.props, "lip_sync_2d_sprite_sheet_main_scale", text="Main")
def draw_animation_section(self, context: BpyContext, layout: BpyUILayout):
panel_header, panel_body = layout.panel(
"cgp_lipsync_animation_dropdown", default_closed=True
)
panel_header.label(text="Animation Settings")
if panel_body is not None:
self.draw_thresholds(self.props, panel_body)
def draw_visemes_section(self, context: BpyContext, layout: BpyUILayout):
panel_head, panel_body = layout.panel(
"cgp_lipsync_viseme_dropdown", default_closed=True
)
panel_head.label(text="Viseme Settings")
if panel_body is not None:
row = panel_body.row(align=True)
row.label(text="Viseme")
row.label(text="Image index")
visemes = viseme_items(None, None)
for i, viseme in enumerate(visemes):
lang_code = list(viseme)[0]
row = panel_body.row(align=True)
row.label(text=f"{lang_code}")
row.prop(self.props, f"lip_sync_2d_viseme_{lang_code}", text="")
def draw_thresholds(self, props, layout):
row = layout.row()
row.label(text="Thresholds:")
data_list = [
"lip_sync_2d_sps_in_between_threshold",
"lip_sync_2d_sps_sil_threshold",
]
row = layout.row()
for data in data_list:
row.prop(props, data)
@@ -0,0 +1,68 @@
import bpy
from .AnimatorPanelPoseAssetsStrategy import AnimatorPanelPoseAssetsStrategy
from .protocols import LIPSYNC2D_AnimatorPanel
from ..Panels.AnimatorPanelShapeKeysStrategy import AnimatorPanelShapeKeysStrategy
from ..Panels.AnimatorPanelSpriteSheetStrategy import AnimatorPanelSpriteSheetStrategy
class LIPSYNC2D_PT_Edit(bpy.types.Panel):
bl_idname = "LIPSYNC2D_PT_Edit"
bl_label = "Quick Edit"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Lip Sync"
bl_options = {"DEFAULT_CLOSED"}
def __init__(self, *args, **kargs):
super().__init__(*args, **kargs)
self.animator_panel: LIPSYNC2D_AnimatorPanel | None = None
def draw(self, context: bpy.types.Context):
if self.layout is None:
return
if context.scene is None:
return
if context.preferences is None:
return
active_obj = context.active_object
if active_obj is None or (
active_obj.type != "MESH" and active_obj.type != "ARMATURE"
):
self.layout.label(
text="Please, select an Object with Mesh Data or an Armature",
icon="INFO_LARGE",
)
return
if not hasattr(active_obj, "lipsync2d_props"):
self.layout.label(
text="Something wrong happened. Try uninstall / reinstall Lip Sync Addon",
icon="WARNING_LARGE",
)
return
if "lip_sync_2d_initialized" not in context.active_object.lipsync2d_props: # type: ignore
self.layout.label(text="Press on Add Lip Sync to start", icon="INFO_LARGE")
return
props = active_obj.lipsync2d_props # type: ignore
if props is None:
return
if props.lip_sync_2d_lips_type == "SHAPEKEYS":
self.animator_panel = AnimatorPanelShapeKeysStrategy(active_obj)
elif props.lip_sync_2d_lips_type == "SPRITESHEET":
self.animator_panel = AnimatorPanelSpriteSheetStrategy(active_obj)
elif props.lip_sync_2d_lips_type == "POSEASSETS":
self.animator_panel = AnimatorPanelPoseAssetsStrategy(active_obj)
if self.animator_panel is None:
return
self.animator_panel.draw_edit_section(context, self.layout)
@@ -0,0 +1,90 @@
import bpy
from .AnimatorPanelPoseAssetsStrategy import AnimatorPanelPoseAssetsStrategy
from .protocols import LIPSYNC2D_AnimatorPanel
from .AnimatorPanelSpriteSheetStrategy import AnimatorPanelSpriteSheetStrategy
from .AnimatorPanelShapeKeysStrategy import AnimatorPanelShapeKeysStrategy
class LIPSYNC2D_PT_Panel(bpy.types.Panel):
"""Creates a Panel in the scene context of the property editor"""
bl_label = "Lip Sync"
bl_idname = "LIPSYNC2D_PT_Panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Lip Sync"
def __init__(self, *args, **kargs) -> None:
super().__init__(*args, **kargs)
self.animator_panel: LIPSYNC2D_AnimatorPanel | None = None
def draw(self, context: bpy.types.Context):
if self.layout is None:
return
if context.scene is None:
return
if context.preferences is None:
return
active_obj = context.active_object
if active_obj is None or (
active_obj.type != "MESH" and active_obj.type != "ARMATURE"
):
self.layout.label(
text="Please, select an Object with Mesh Data or an Armature",
icon="INFO_LARGE",
)
return
if not hasattr(active_obj, "lipsync2d_props"):
self.layout.label(
text="Something wrong happened. Try uninstall / reinstall Lip Sync Addon",
icon="WARNING_LARGE",
)
return
props = active_obj.lipsync2d_props # type: ignore
if props is None:
return
if props.lip_sync_2d_lips_type == "SHAPEKEYS":
self.animator_panel = AnimatorPanelShapeKeysStrategy(active_obj)
elif props.lip_sync_2d_lips_type == "SPRITESHEET":
self.animator_panel = AnimatorPanelSpriteSheetStrategy(active_obj)
elif props.lip_sync_2d_lips_type == "POSEASSETS":
self.animator_panel = AnimatorPanelPoseAssetsStrategy(active_obj)
layout = self.layout
if (
context.active_object is None
or not hasattr(context.active_object, "lipsync2d_props")
or context.active_object.lipsync2d_props.lip_sync_2d_initialized == False # type: ignore
):
row = layout.row(align=True)
row.operator(
"object.set_lipsync_custom_properties", text="Add Lip Sync on Selection"
)
return
row = layout.row(align=True)
row.label(text="Animation type")
row.prop(props, "lip_sync_2d_lips_type", text="")
if self.animator_panel is None:
return
layout.separator()
self.animator_panel.draw_animator_section(context, layout)
self.animator_panel.draw_visemes_section(context, layout)
self.animator_panel.draw_animation_section(context, layout)
self.animator_panel.draw_bake_section(context, layout)
layout.separator()
self.animator_panel.draw_baking_section(context, layout)
@@ -0,0 +1,32 @@
import platform
import bpy
from ..LIPSYNC2D_Utils import get_package_name
from ..Preferences.LIPSYNC2D_AP_Preferences import LIPSYNC2D_AP_Preferences
class LIPSYNC2D_PT_Settings(bpy.types.Panel):
bl_idname="LIPSYNC2D_PT_Settings"
bl_label="Quick Setup"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Lip Sync'
platform = platform.system()
def draw(self, context: bpy.types.Context):
layout = self.layout
prefs = context.preferences.addons[get_package_name()].preferences # type: ignore
if not layout or prefs is None:
return
self.draw_espeak_model_settings(layout, prefs)
def draw_espeak_model_settings(self, layout: bpy.types.UILayout, prefs: bpy.types.AddonPreferences):
LIPSYNC2D_AP_Preferences.draw_online_access_warning(layout)
row = layout.row()
row.label(text="Language Model")
row.prop(prefs, "current_lang", text="")
LIPSYNC2D_AP_Preferences.draw_model_state(row) #type: ignore
@@ -0,0 +1,23 @@
from typing import Protocol
from ..lipsync_types import BpyContext, BpyUILayout
class LIPSYNC2D_AnimatorPanel(Protocol):
def draw_animation_section(self, context: BpyContext, layout: BpyUILayout):
pass
def draw_visemes_section(self, context: BpyContext, layout: BpyUILayout):
pass
def draw_edit_section(self, context: BpyContext, layout: BpyUILayout):
pass
def draw_baking_section(self, context: BpyContext, layout: BpyUILayout):
pass
def draw_animator_section(self, context: BpyContext, layout: BpyUILayout):
pass
def draw_bake_section(self, context: BpyContext, layout: BpyUILayout):
pass
@@ -0,0 +1,109 @@
import os
from pathlib import Path
from re import match
from typing import Literal
import bpy
from vosk import MODEL_DIRS
from ..lipsync_types import BpyContext
from ..Core.LIPSYNC2D_VoskHelper import LIPSYNC2D_VoskHelper
from ..LIPSYNC2D_Utils import get_package_name
class LIPSYNC2D_AP_Preferences(bpy.types.AddonPreferences):
bl_idname = get_package_name() # type: ignore
current_lang: bpy.props.EnumProperty(name="Lip Sync Lang", items=LIPSYNC2D_VoskHelper.get_available_languages, update=LIPSYNC2D_VoskHelper.install_model, default=0) # type: ignore
is_downloading: bpy.props.BoolProperty(name="Download Status", default=False) # type: ignore
def draw(self, context):
layout = self.layout
LIPSYNC2D_AP_Preferences.draw_online_access_warning(layout)
row = layout.row(align=True)
row.label(text="Language Model")
row.prop(self, "current_lang", text="")
LIPSYNC2D_AP_Preferences.draw_model_state(row)
LIPSYNC2D_AP_Preferences.draw_fetch_list_ops(layout)
@staticmethod
@LIPSYNC2D_VoskHelper.setextensionpath
def draw_model_state(row: bpy.types.UILayout) -> None:
"""
Updates the UI to display the current status of the selected language model.
:param row: bpy.types.UILayout
The UI layout row on which the display updates are made.
:param current_lang: str
The currently selected language code for the model.
:return: None
"""
installed = ""
model_status = LIPSYNC2D_AP_Preferences.get_model_state()
if model_status == "INSTALLED":
installed = " Installed"
row.enabled = True
elif model_status == "DOWNLOADING":
installed = " Downloading..."
row.enabled = False
row.label(text=installed)
@staticmethod
@LIPSYNC2D_VoskHelper.setextensionpath
def get_model_state() -> Literal["INSTALLED", "DOWNLOADING", ""]:
directory = MODEL_DIRS[3] if len(MODEL_DIRS) >= 4 else None
result = ""
prefs = bpy.context.preferences.addons[get_package_name()].preferences # type: ignore
if prefs is None:
return result
current_lang = LIPSYNC2D_AP_Preferences.get_current_lang_code()
if current_lang != "none":
if directory is not None and Path(directory).exists():
model_file_list = os.listdir(directory)
model_file = [model for model in model_file_list if match(f"vosk-model(-small)?-{current_lang}", model) and os.path.isdir(os.path.join(directory, model))]
if model_file:
result = "INSTALLED"
elif prefs.is_downloading: #type: ignore
result = "DOWNLOADING"
elif prefs.is_downloading: #type: ignore
result = "DOWNLOADING"
return result
@staticmethod
def draw_online_access_warning(layout: bpy.types.UILayout) -> None:
if not bpy.app.online_access:
row = layout.row(align=False)
row.label(text="Blender Online Access is required")
row = layout.row(align=True)
row.label(text="You will only see models in cache")
row = layout.row(align=True)
row.label(text="1. Enable Online Access: Preferences > System > Network")
row = layout.row(align=True)
row.label(text="2. Reload List: Preferences > Add-ons > Lip Sync > Reload")
@staticmethod
def draw_fetch_list_ops(layout: bpy.types.UILayout) -> None:
row = layout.row()
row.operator("wm.lipsync_download_list", text="Reload Models List")
row.enabled = bpy.app.online_access
@staticmethod
def get_current_lang_code() -> str:
prefs = bpy.context.preferences.addons[get_package_name()].preferences # type: ignore
return prefs.current_lang
@@ -0,0 +1,377 @@
from __future__ import annotations
from typing import cast
import bpy
from ..Utils.strings import intern_enum_items
from ..lipsync_types import BpyContext
from ..Core.phoneme_to_viseme import viseme_items_mpeg4_v2 as viseme_items
def update_rig_type_advanced(self, context):
if self.lip_sync_2d_rig_type_advanced:
self["lip_sync_2d_rig_type_basic"] = False
self["lip_sync_2d_rig_type_advanced"] = True
def update_rig_type_basic(self, context):
if self.lip_sync_2d_rig_type_basic:
self["lip_sync_2d_rig_type_advanced"] = False
self["lip_sync_2d_rig_type_basic"] = True
def update_sprite_sheet(self: bpy.types.bpy_struct, context: bpy.types.Context):
obj = context.active_object
mat: bpy.types.Material = obj.lipsync2d_props.lip_sync_2d_main_material # type: ignore
if mat is None or mat.node_tree is None or mat.node_tree.nodes is None:
return
main_group = cast(
bpy.types.ShaderNodeGroup, mat.node_tree.nodes.get("cgp_main_group")
)
if main_group is None or main_group.node_tree is None:
return
group_node = main_group.node_tree.nodes.get("cgp_spritesheet_reader")
if (
not isinstance(group_node, bpy.types.ShaderNodeGroup)
or group_node.node_tree is None
or group_node.node_tree.nodes is None
):
return
image_node = group_node.node_tree.nodes.get("CGP_LipSyncSpritesheet")
if not isinstance(image_node, bpy.types.ShaderNodeTexImage):
return
image_node.image = self["lip_sync_2d_sprite_sheet"]
return None
def update_sprite_sheet_format(self: bpy.types.bpy_struct, context: bpy.types.Context):
spritesheet_format = self["lip_sync_2d_sprite_sheet_format"]
if spritesheet_format == 0:
self["lip_sync_2d_sprite_sheet_rows"] = self["lip_sync_2d_sprite_sheet_columns"]
elif spritesheet_format == 2:
self["lip_sync_2d_sprite_sheet_rows"] = 1
elif spritesheet_format == 3:
self["lip_sync_2d_sprite_sheet_columns"] = 1
def update_sprite_sheet_rows(self: bpy.types.bpy_struct, context: bpy.types.Context):
if "lip_sync_2d_sprite_sheet_format" not in self:
return
spritesheet_format = self["lip_sync_2d_sprite_sheet_format"]
if spritesheet_format == 0:
self["lip_sync_2d_sprite_sheet_columns"] = self["lip_sync_2d_sprite_sheet_rows"]
def shape_keys_list(self: bpy.types.bpy_struct, context: bpy.types.Context | None):
result = [("NONE", "None", "None")]
if context is None or context.active_object is None:
return result
active_obj = context.active_object
if (
not isinstance(active_obj.data, bpy.types.Mesh)
or active_obj.data.shape_keys is None
):
return result
shape_keys = active_obj.data.shape_keys
key_blocks = active_obj.data.shape_keys.key_blocks
result = result + [
(s.name, s.name, s.name) for s in key_blocks if s != shape_keys.reference_key
]
return intern_enum_items(result)
def set_bake_end(self, value):
if value < self.lip_sync_2d_bake_start:
self["lip_sync_2d_bake_start"] = value
self["lip_sync_2d_bake_end"] = value
def get_bake_end(self):
try:
return self["lip_sync_2d_bake_end"]
except:
return 0
def set_bake_start(self, value):
if value > self.lip_sync_2d_bake_end:
self["lip_sync_2d_bake_end"] = value
self["lip_sync_2d_bake_start"] = value
def get_bake_start(self):
try:
return self["lip_sync_2d_bake_start"]
except:
return 0
def armature_prop_poll(self, obj):
return obj.type == "ARMATURE"
def get_lip_sync_type_items(self, context: BpyContext | None):
if context is None or context.active_object is None:
return []
items = [
(
"SPRITESHEET",
"Sprite Sheet",
"Use a Sprite Sheet containg all of your visemes",
),
("SHAPEKEYS", "Shape Keys", "Use your Shape Keys to animate mouth"),
]
if context.active_object.type == "ARMATURE":
items = [
("POSEASSETS", "Pose Assets", "Use Pose Library to animate mouth"),
]
return items
def poll_pose_assets(self, obj: bpy.types.ID):
return bool(obj.asset_data)
class LIPSYNC2D_PG_CustomProperties(bpy.types.PropertyGroup):
lip_sync_2d_initialized: bpy.props.BoolProperty(
name="Initilize Lip Sync",
description="Initilize Lip Sync on selection",
default=False,
) # type: ignore
lip_sync_2d_sprite_sheet: bpy.props.PointerProperty(
name="Sprite Sheet",
description="The name of the addon to reload",
type=bpy.types.Image,
update=update_sprite_sheet,
) # type: ignore
lip_sync_2d_main_material: bpy.props.PointerProperty(
name="Main Material",
description="Material containing Sprite sheet",
type=bpy.types.Material,
) # type: ignore
lip_sync_2d_sprite_sheet_columns: bpy.props.IntProperty(
name="Columns", description="Total of columns in sprite sheet", default=1
) # type: ignore
lip_sync_2d_sprite_sheet_rows: bpy.props.IntProperty(
name="Rows",
description="Total of rows in sprite sheet",
update=update_sprite_sheet_rows,
default=1,
) # type: ignore
lip_sync_2d_sprite_sheet_sprite_scale: bpy.props.FloatProperty(
name="Sprite",
description="Adjust sprite scale so it fits in mouth area",
default=1,
) # type: ignore
lip_sync_2d_sprite_sheet_main_scale: bpy.props.FloatProperty(
name="Lips", description="Adjust Lips scale", default=1
) # type: ignore
lip_sync_2d_sprite_sheet_index: bpy.props.IntProperty(
name="Sprite Index",
description="Sprite Index. Start at 0, from Bottom Left to Top Right",
default=1,
) # type: ignore
lip_sync_2d_sprite_sheet_format: bpy.props.EnumProperty(
name="Sprite sheet format",
description="Sprite sheet format can be square, rectangle or line.",
items=[
(
"SQUARE",
"Square",
"Sprites are placed in a square with same width and height",
),
(
"RECTANGLE",
"Rectangle",
"Sprites are placed in a rectangle with multiple columns and rows",
),
("HLINE", "Horizontal Line", "Sprites are placed horizontally"),
("VLINE", "Vertical Line", "Sprites are placed vertically"),
],
update=update_sprite_sheet_format,
default=3,
) # type: ignore
lip_sync_2d_lips_type: bpy.props.EnumProperty(
name="Animation type",
description="What kind of animation will you use.",
items=get_lip_sync_type_items,
update=update_sprite_sheet_format,
default=0,
) # type: ignore
lip_sync_2d_in_between_threshold: bpy.props.FloatProperty(
name="In between",
description="Minimum time gap required between two keyframes. Keyframes added closer than this will be removed.",
default=0.0417,
subtype="TIME",
unit="TIME_ABSOLUTE",
) # type: ignore
lip_sync_2d_sil_threshold: bpy.props.FloatProperty(
name="Silence",
description="Minimum time gap between keyframes required to insert a silent interval.",
default=0.22,
subtype="TIME",
unit="TIME_ABSOLUTE",
) # type: ignore
lip_sync_2d_sps_in_between_threshold: bpy.props.FloatProperty(
name="In between",
description="Minimum time gap required between two keyframes. Keyframes added closer than this will be removed.",
default=0.0417,
subtype="TIME",
unit="TIME_ABSOLUTE",
) # type: ignore
lip_sync_2d_sps_sil_threshold: bpy.props.FloatProperty(
name="Silence",
description="Minimum time gap between keyframes required to insert a silent interval.",
default=0.22,
subtype="TIME",
unit="TIME_ABSOLUTE",
) # type: ignore
lip_sync_2d_close_motion_duration: bpy.props.FloatProperty(
name="Lip Close Duration",
description="Duration of lip-closing animation during silent intervals",
default=0.2,
subtype="TIME",
unit="TIME_ABSOLUTE",
) # type: ignore
lip_sync_2d_remove_animation_data: bpy.props.BoolProperty(
name="Remove Animation",
description="Also remove action, action slot and keyframes",
default=True,
) # type: ignore
lip_sync_2d_remove_cgp_node_group: bpy.props.BoolProperty(
name="Remove Nodes",
description="Also remove node groups from Object's Materials",
default=True,
) # type: ignore
lip_sync_2d_use_clear_keyframes: bpy.props.BoolProperty(
name="Clear Keyframes",
description="Clear Keyframes before Bake",
default=True,
) # type: ignore
lip_sync_2d_use_bake_range: bpy.props.BoolProperty(
name="Use Range",
description="Only bake between specified range",
default=False,
) # type: ignore
lip_sync_2d_bake_start: bpy.props.IntProperty(
name="Bake Start",
description="Start Baking at this frame",
default=1,
min=0,
set=set_bake_start,
get=get_bake_start,
) # type: ignore
lip_sync_2d_bake_end: bpy.props.IntProperty(
name="Bake End",
description="End Baking at this frame",
default=250,
min=0,
set=set_bake_end,
get=get_bake_end,
) # type: ignore
lip_sync_2d_rig_type_basic: bpy.props.BoolProperty(
name="Basic Rig",
description=(
"Rig with basic bones animation.\n"
"As long as only basic bones are animated, this should be your default choice."
),
default=True,
update=update_rig_type_basic,
) # type: ignore
lip_sync_2d_rig_type_advanced: bpy.props.BoolProperty(
name="Advanced Rig",
description=(
"Rig with more complex animated elements like BBone or Custom Properties.\n"
"Since this inserts keyframes on ALL of your animated properties, it will be slower.\n"
"Only use this if Basic Rig is not working."
),
update=update_rig_type_advanced,
) # type: ignore
lip_sync_2d_prioritize_accuracy: bpy.props.BoolProperty(
name="Prioritize Accuracy",
description=(
"Animate all important visemes regardless of timing constraints. "
"Prevents critical mouth shapes (lip contact sounds like P, B, M, F, TH) "
"from being skipped when they occur in rapid succession."
),
default=False,
) # type: ignore
@classmethod
def register(cls):
visemes = viseme_items(None, None)
for v in visemes:
enum_id, name, desc = v
prop_name = f"lip_sync_2d_viseme_{enum_id}"
setattr(
cls,
prop_name,
bpy.props.IntProperty(
name=f"Viseme {name}", description=desc, min=0, max=99, default=-1
), # type: ignore
)
prop_name = f"lip_sync_2d_viseme_shape_keys_{enum_id}"
setattr(
cls,
prop_name,
bpy.props.EnumProperty(
name=f"Viseme {name}",
description=desc,
items=shape_keys_list,
default=0,
), # type: ignore
)
prop_name = f"lip_sync_2d_viseme_pose_{enum_id}"
setattr(
cls,
prop_name,
bpy.props.PointerProperty(
type=bpy.types.Action,
name=f"Viseme {name}",
description=desc,
poll=poll_pose_assets,
),
)
@@ -0,0 +1,76 @@
# 🗣️ Blender Lip Sync Addon
Official Documentation: [https://docs.cgpoly.io](https://docs.cgpoly.io/lip-sync-documentation)
A **Blender addon** for automatic lip-syncing based on audio input.
Cross-platform (Windows, macOS, Linux), works **out of the box** with **~25 languages**.
**Just install it from Blenders Add-ons panel and youre ready to go!**
## Video Demo
https://github.com/user-attachments/assets/cb90ea7b-02fc-4ca1-b19f-631024cd79cd
https://github.com/user-attachments/assets/57ea3912-2d50-4090-ba49-3035ab673a05
Animated Platformer Character by [Quaternius](https://poly.pizza/m/kKtL4zvS3n)
Wall Art 06 by Jarlan Perez [CC-BY](https://creativecommons.org/licenses/by/3.0/) via [Poly Pizza](https://poly.pizza/m/1U5roiXQZAM)
---
## ✨ Features
- 🎤 Converts voice audio into animated mouth shapes
- Interpolates between Shape Key to give natural lips motion
- 🖼️ Projects a viseme **spritesheet** onto your characters face (one spritesheet is shipped with the add-on, but you can use your own)
- 🧠 Uses offline speech recognition (Vosk + Phonemizer + eSpeak)
- 🖥️ Fully supported on Windows, macOS and Linux
- 🔜 Future upgrade: **Pose-based animation** for facial rigs
## 📦 Installation
1. Open Blender.
2. Go to **Edit > Preferences > Get Extensions**.
3. Look for **Lip Sync**
4. Install it done!
When you select a Language Model for the first time, Model file is downloaded and cached for future uses (~40Mo, depending on the language).
## 🛠️ How to Use (Spritesheet)
1. Import or create a 3D character.
2. Add your movie / sound clip in Video Sequencer
3. Go to the **Lip Sync** tab in the **N-panel**.
4. Select your Language among 30 available languages.
5. Click **Add Spritesheet on Selection**
6. Click **Set Mouth Area** from **Edit Mode**
7. Click **Analyze Audio** and wait few seconds your character now speaks!
## 🚧 Roadmap
- [x] Sprite-based viseme projection
- [x] Timeline keyframe baking
- [x] Shapekey-based viseme support
- [ ] Pose-based animation
## 🐞 Known Issues
- Characters require no rotation and applied Scale
## 🧩 Compatibility
- Blender **4.4+**
- Works on **Windows**, **macOS**, and **Linux**
## 🤝 Contribute
Found a bug or want to help improve the addon?
Open an issue or submit a pull request contributions are welcome!
## 📜 License
This project is licensed under the [GNU General Public License v3.0 or later](https://spdx.org/licenses/GPL-3.0-or-later.html).
---
Made with ❤️ by [Charley 3D](https://github.com/charley3d)
@@ -0,0 +1,33 @@
THIRD PARTY LICENSES
=====================
This software makes use of the following third-party libraries and tools.
Full license texts are available in the [`licenses/`](./licenses) folder.
---
Vosk Speech Recognition
------------------------
License: Apache License 2.0
Source: https://github.com/alphacep/vosk-api
---
eSpeak NG
---------
License: GNU General Public License v3.0 or later
Source: https://github.com/espeak-ng/espeak-ng
The getopt.c compatibility implementation for getopt support on Windows is taken from the NetBSD getopt_long implementation, which is licensed under a [2-clause BSD license](https://opensource.org/license/bsd-2-clause).
eSpeak NG also comes with a copy of [Unicode License](https://www.unicode.org/license.txt).
---
Phonemizer
----------
License: GNU General Public License v3.0 or later
Source: https://github.com/bootphon/phonemizer
Copyright 2015-2021 Mathieu Bernard
@@ -0,0 +1,21 @@
from typing import List, Tuple
# This cache is required as a workaround for character encoding issue
# when using dynamic EnumProperty items (https://docs.blender.org/api/master/bpy.props.html#bpy.props.EnumProperty).
# Do not remove it otherwise non ascii characters will be displayed as Mojibake (https://github.com/Charley3d/lip-sync/issues/14)
STRING_CACHE = {}
def intern_enum_items(items: List[Tuple[str, str, str]]) -> List[Tuple[str, str, str]]:
"""Cache strings to prevent memory issues"""
def intern_string(s):
if not isinstance(s, str):
return s
global STRING_CACHE
if s not in STRING_CACHE:
STRING_CACHE[s] = s
return STRING_CACHE[s]
return [tuple(intern_string(s) for s in item) for item in items]
@@ -0,0 +1,30 @@
import pathlib
import sys
from vosk import MODEL_DIRS, Model
def install_model(lang: str, vosk_cache: str) -> None:
"""
Download and/or Installs the specified language model for speech recognition. This function ensures
the target directory for the model exists and initializes the model using the
provided language and cache directory.
:param lang: The language code for the model to be installed.
:param vosk_cache: The directory path where the model should be cached.
:return: None
"""
MODEL_DIRS[3] = pathlib.Path(vosk_cache)
model_path = MODEL_DIRS[3]
if not model_path.exists():
model_path.mkdir(parents=True, exist_ok=True)
Model(lang=lang)
args = sys.argv[1:]
lang = args[0]
vosk_cache = args[1]
install_model(args[0], args[1])
@@ -0,0 +1,62 @@
import bpy
from .Operators.LIPSYNC2D_OT_refresh_pose_assets import LIPSYNC2D_OT_refresh_pose_assets
from .Core.LIPSYNC2D_EspeakInspector import LIPSYNC2D_EspeakInspector
from .Core.LIPSYNC2D_VoskHelper import LIPSYNC2D_VoskHelper
from .Operators.LIPSYNC2D_OT_AnalyzeAudio import LIPSYNC2D_OT_AnalyzeAudio
from .Operators.LIPSYNC2D_OT_DownloadModelsList import LIPSYNC2D_OT_DownloadModelsList
from .Operators.LIPSYNC2D_OT_RemoveAnimations import LIPSYNC2D_OT_RemoveAnimations
from .Operators.LIPSYNC2D_OT_RemoveLipSync import LIPSYNC2D_OT_RemoveLipSync
from .Operators.LIPSYNC2D_OT_RemoveNodeGroups import LIPSYNC2D_OT_RemoveNodeGroups
from .Operators.LIPSYNC2D_OT_SetCustomProperties import LIPSYNC2D_OT_SetCustomProperties
from .Operators.LIPSYNC2D_OT_SetMouthArea import LIPSYNC2D_OT_SetMouthArea
from .Panels.LIPSYNC2D_PT_Panel import LIPSYNC2D_PT_Panel
from .Panels.LIPSYNC2D_PT_Settings import LIPSYNC2D_PT_Settings
from .Panels.LIPSYNC2D_PT_Edit import LIPSYNC2D_PT_Edit
from .Preferences.LIPSYNC2D_AP_Preferences import LIPSYNC2D_AP_Preferences
from .Properties.LIPSYNC2D_PG_CustomProperties import LIPSYNC2D_PG_CustomProperties
def register():
if not LIPSYNC2D_EspeakInspector.is_espeak_already_extracted():
LIPSYNC2D_EspeakInspector.unzip_binaries()
LIPSYNC2D_EspeakInspector.set_espeak_backend()
if bpy.app.online_access:
LIPSYNC2D_VoskHelper.cache_online_langs_list()
bpy.utils.register_class(LIPSYNC2D_AP_Preferences)
bpy.utils.register_class(LIPSYNC2D_PG_CustomProperties)
bpy.utils.register_class(LIPSYNC2D_PT_Settings)
bpy.utils.register_class(LIPSYNC2D_PT_Panel)
bpy.utils.register_class(LIPSYNC2D_OT_SetMouthArea)
bpy.utils.register_class(LIPSYNC2D_OT_SetCustomProperties)
bpy.utils.register_class(LIPSYNC2D_OT_AnalyzeAudio)
bpy.utils.register_class(LIPSYNC2D_OT_DownloadModelsList)
bpy.utils.register_class(LIPSYNC2D_OT_RemoveLipSync)
bpy.utils.register_class(LIPSYNC2D_OT_RemoveNodeGroups)
bpy.utils.register_class(LIPSYNC2D_PT_Edit)
bpy.utils.register_class(LIPSYNC2D_OT_RemoveAnimations)
bpy.utils.register_class(LIPSYNC2D_OT_refresh_pose_assets)
bpy.types.Object.lipsync2d_props = bpy.props.PointerProperty(type=LIPSYNC2D_PG_CustomProperties) # type: ignore
def unregister():
bpy.utils.unregister_class(LIPSYNC2D_PG_CustomProperties)
bpy.utils.unregister_class(LIPSYNC2D_PT_Panel)
bpy.utils.unregister_class(LIPSYNC2D_OT_SetMouthArea)
bpy.utils.unregister_class(LIPSYNC2D_OT_SetCustomProperties)
bpy.utils.unregister_class(LIPSYNC2D_OT_AnalyzeAudio)
bpy.utils.unregister_class(LIPSYNC2D_AP_Preferences)
bpy.utils.unregister_class(LIPSYNC2D_PT_Settings)
bpy.utils.unregister_class(LIPSYNC2D_OT_DownloadModelsList)
bpy.utils.unregister_class(LIPSYNC2D_OT_RemoveLipSync)
bpy.utils.unregister_class(LIPSYNC2D_OT_RemoveNodeGroups)
bpy.utils.unregister_class(LIPSYNC2D_PT_Edit)
bpy.utils.unregister_class(LIPSYNC2D_OT_RemoveAnimations)
bpy.utils.unregister_class(LIPSYNC2D_OT_refresh_pose_assets)
del bpy.types.Object.lipsync2d_props # type: ignore
if __name__ == "__main__":
register()
@@ -0,0 +1,40 @@
schema_version = "1.0.0"
id = "iocgpoly_lip_sync"
version = "2.3.2"
name = "Lip Sync"
tagline = "Automatic lip sync for your Blender models"
maintainer = "Charley 3D <charley@cgpoly.fr>"
type = "add-on"
website = "https://github.com/Charley3d/lip-sync"
tags = ["Animation", "Sequencer"]
blender_version_min = "4.4.0"
license = [
"SPDX:GPL-3.0-or-later",
]
platforms = ["windows-x64", "macos-x64", "macos-arm64", "linux-x64"]
wheels = ["./wheels/attrs-25.3.0-py3-none-any.whl", "./wheels/babel-2.17.0-py3-none-any.whl", "./wheels/cffi-1.17.1-cp311-cp311-macosx_10_9_x86_64.whl", "./wheels/cffi-1.17.1-cp311-cp311-macosx_11_0_arm64.whl", "./wheels/cffi-1.17.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", "./wheels/cffi-1.17.1-cp311-cp311-win_amd64.whl", "./wheels/charset_normalizer-3.4.1-cp310-cp310-macosx_10_9_universal2.whl", "./wheels/charset_normalizer-3.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", "./wheels/csvw-3.5.1-py2.py3-none-any.whl", "./wheels/dlinfo-2.0.0-py3-none-any.whl", "./wheels/isodate-0.7.2-py3-none-any.whl", "./wheels/joblib-1.4.2-py3-none-any.whl", "./wheels/jsonschema-4.23.0-py3-none-any.whl", "./wheels/jsonschema_specifications-2024.10.1-py3-none-any.whl", "./wheels/language_tags-1.2.0-py3-none-any.whl", "./wheels/phonemizer-3.3.0-py3-none-any.whl", "./wheels/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", "./wheels/rdflib-7.1.4-py3-none-any.whl", "./wheels/referencing-0.36.2-py3-none-any.whl", "./wheels/regex-2024.11.6-cp311-cp311-macosx_10_9_universal2.whl", "./wheels/regex-2024.11.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", "./wheels/regex-2024.11.6-cp311-cp311-win_amd64.whl", "./wheels/rfc3986-1.5.0-py2.py3-none-any.whl", "./wheels/rpds_py-0.24.0-cp311-cp311-macosx_10_12_x86_64.whl", "./wheels/rpds_py-0.24.0-cp311-cp311-macosx_11_0_arm64.whl", "./wheels/rpds_py-0.24.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", "./wheels/rpds_py-0.24.0-cp311-cp311-win_amd64.whl", "./wheels/segments-2.3.0-py2.py3-none-any.whl", "./wheels/six-1.17.0-py2.py3-none-any.whl", "./wheels/tqdm-4.67.1-py3-none-any.whl", "./wheels/typing_extensions-4.13.2-py3-none-any.whl", "./wheels/uritemplate-4.1.1-py2.py3-none-any.whl", "./wheels/vosk-0.3.41-py3-none-macosx_10_6_universal2.whl", "./wheels/vosk-0.3.41-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", "./wheels/vosk-0.3.41-py3-none-win_amd64.whl"]
[permissions]
network = "Need to download Voices Models to enable lip sync"
files = "Import Models / Extract libs to disk"
[build]
paths_exclude_pattern = [
"__pycache__/",
"/.git/",
"/*.zip",
"dev_tools.py",
"/.idea/",
"/.venv/",
"/.venv311/",
".github/",
".gitignore",
"/scripts/",
".releaserc"
]
# BEGIN GENERATED CONTENT.
# This must not be included in source manifests.
[build.generated]
platforms = ["windows-x64"]
wheels = ["./wheels/attrs-25.3.0-py3-none-any.whl", "./wheels/babel-2.17.0-py3-none-any.whl", "./wheels/cffi-1.17.1-cp311-cp311-win_amd64.whl", "./wheels/csvw-3.5.1-py2.py3-none-any.whl", "./wheels/dlinfo-2.0.0-py3-none-any.whl", "./wheels/isodate-0.7.2-py3-none-any.whl", "./wheels/joblib-1.4.2-py3-none-any.whl", "./wheels/jsonschema-4.23.0-py3-none-any.whl", "./wheels/jsonschema_specifications-2024.10.1-py3-none-any.whl", "./wheels/language_tags-1.2.0-py3-none-any.whl", "./wheels/phonemizer-3.3.0-py3-none-any.whl", "./wheels/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", "./wheels/rdflib-7.1.4-py3-none-any.whl", "./wheels/referencing-0.36.2-py3-none-any.whl", "./wheels/regex-2024.11.6-cp311-cp311-win_amd64.whl", "./wheels/rfc3986-1.5.0-py2.py3-none-any.whl", "./wheels/rpds_py-0.24.0-cp311-cp311-win_amd64.whl", "./wheels/segments-2.3.0-py2.py3-none-any.whl", "./wheels/six-1.17.0-py2.py3-none-any.whl", "./wheels/tqdm-4.67.1-py3-none-any.whl", "./wheels/typing_extensions-4.13.2-py3-none-any.whl", "./wheels/uritemplate-4.1.1-py2.py3-none-any.whl", "./wheels/vosk-0.3.41-py3-none-win_amd64.whl"]
# END GENERATED CONTENT.
@@ -0,0 +1,176 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. this License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
@@ -0,0 +1,20 @@
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
@@ -0,0 +1,55 @@
Unicode Data Files include all data files under the directories
http://www.unicode.org/Public/, http://www.unicode.org/reports/,
http://www.unicode.org/cldr/data/, http://source.icu-project.org/repos/icu/, and
http://www.unicode.org/utility/trac/browser/.
Unicode Data Files do not include PDF online code charts under the
directory http://www.unicode.org/Public/.
Software includes any source code published in the Unicode Standard
or under the directories
http://www.unicode.org/Public/, http://www.unicode.org/reports/,
http://www.unicode.org/cldr/data/, http://source.icu-project.org/repos/icu/, and
http://www.unicode.org/utility/trac/browser/.
NOTICE TO USER: Carefully read the following legal agreement.
BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S
DATA FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"),
YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
TERMS AND CONDITIONS OF THIS AGREEMENT.
IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE
THE DATA FILES OR SOFTWARE.
COPYRIGHT AND PERMISSION NOTICE
Copyright © 1991-2018 Unicode, Inc. All rights reserved.
Distributed under the Terms of Use in http://www.unicode.org/copyright.html.
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Unicode data files and any associated documentation
(the "Data Files") or Unicode software and any associated documentation
(the "Software") to deal in the Data Files or Software
without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, and/or sell copies of
the Data Files or Software, and to permit persons to whom the Data Files
or Software are furnished to do so, provided that either
(a) this copyright and permission notice appear with all copies
of the Data Files or Software, or
(b) this copyright and permission notice appear in associated
Documentation.
THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS
NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THE DATA FILES OR SOFTWARE.
Except as contained in this notice, the name of a copyright holder
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in these Data Files or Software without prior
written authorization of the copyright holder.
@@ -0,0 +1,34 @@
# types.py
from typing import TYPE_CHECKING, TypeAlias
if TYPE_CHECKING:
from bpy.types import (
Action,
UILayout,
ActionKeyframeStrip,
Context,
RenderSettings,
Object,
PropertyGroup,
Operator,
ShapeKey,
ActionSlot,
Mesh,
ActionChannelbag,
Armature,
)
# Export commonly used types
BpyContext: TypeAlias = "Context"
BpyObject: TypeAlias = "Object"
BpyRenderSettings: TypeAlias = "RenderSettings"
BpyPropertyGroup: TypeAlias = "PropertyGroup"
BpyOperator: TypeAlias = "Operator"
BpyShapeKey: TypeAlias = "ShapeKey"
BpyActionSlot: TypeAlias = "ActionSlot"
BpyMesh: TypeAlias = "Mesh"
BpyAction: TypeAlias = "Action"
BpyActionKeyframeStrip: TypeAlias = "ActionKeyframeStrip"
BpyUILayout: TypeAlias = "UILayout"
BpyActionChannelbag: TypeAlias = "ActionChannelbag"
BpyArmature: TypeAlias = "Armature"