feat: add selectable animalese voice sets

This commit is contained in:
Alexander Sellite 2026-08-16 12:26:05 -04:00
parent 364e7dc282
commit ce733818e2
247 changed files with 2675 additions and 302 deletions

View file

@ -77,7 +77,11 @@ func is_sender_filtered(fingerprint: String) -> bool:
)
func send_local_message(body: String) -> bool:
func send_local_message(
body: String,
voice_id: String = VoiceProfilesType.DEFAULT_ID,
sample_set_id: String = VoiceProfilesType.DEFAULT_SAMPLE_SET_ID,
) -> bool:
if (
_session == null
or not _session.is_gameplay_session_active()
@ -99,6 +103,10 @@ func send_local_message(body: String) -> bool:
"session_id": _session.get_session_id(),
"body": clean,
"sender_fingerprint": _session.get_local_identity_fingerprint(),
"voice_id": VoiceProfilesType.sanitized_id(voice_id),
"sample_set_id": VoiceProfilesType.sanitized_sample_set_id(
sample_set_id
),
}
request["sender_signature"] = _session.sign_local_action(
"chat_send", NetworkChatProtocol.signature_fields(request)
@ -482,7 +490,13 @@ func _handle_request(peer_id: int, data: Dictionary) -> void:
NetworkChatProtocol.Kind.PLAYER,
peer_id,
record.display_name,
NetworkChatProtocol.sanitize_body(data["body"])
NetworkChatProtocol.sanitize_body(data["body"]),
VoiceProfilesType.sanitized_id(str(data.get(
"voice_id", VoiceProfilesType.DEFAULT_ID
))),
VoiceProfilesType.sanitized_sample_set_id(str(data.get(
"sample_set_id", VoiceProfilesType.DEFAULT_SAMPLE_SET_ID
))),
)
message["request_id"] = request_id
message["sender_fingerprint"] = data["sender_fingerprint"]
@ -499,6 +513,8 @@ func _make_message(
peer_id: int,
display_name: String,
body: String,
voice_id: String = VoiceProfilesType.DEFAULT_ID,
sample_set_id: String = VoiceProfilesType.DEFAULT_SAMPLE_SET_ID,
) -> Dictionary:
_sequence += 1
var message := {
@ -511,6 +527,10 @@ func _make_message(
"sender_display_name": display_name.left(24),
"body": body,
"sender_fingerprint": _session.get_host_identity_fingerprint(),
"voice_id": VoiceProfilesType.sanitized_id(voice_id),
"sample_set_id": VoiceProfilesType.sanitized_sample_set_id(
sample_set_id
),
}
if kind == NetworkChatProtocol.Kind.SYSTEM:
message["sender_signature"] = _session.sign_host_action(

View file

@ -10,6 +10,7 @@ var display_name: String = "Player"
var voice_id: String = VoiceProfilesType.DEFAULT_ID
var speech_speed_id: String = VoiceProfilesType.DEFAULT_SPEED_ID
var call_id: String = VoiceProfilesType.DEFAULT_CALL_ID
var sample_set_id: String = VoiceProfilesType.DEFAULT_SAMPLE_SET_ID
var created_at_unix: int = 0
var _profile_path := ""
var _expected_hash := ""
@ -57,12 +58,19 @@ func load_or_create() -> bool:
voice_id = VoiceProfilesType.DEFAULT_ID
speech_speed_id = VoiceProfilesType.DEFAULT_SPEED_ID
call_id = VoiceProfilesType.DEFAULT_CALL_ID
sample_set_id = VoiceProfilesType.DEFAULT_SAMPLE_SET_ID
created_at_unix = int(Time.get_unix_time_from_system())
return _save_atomic()
func set_display_name(value: String) -> bool:
return set_profile_identity(value, voice_id, speech_speed_id, call_id)
return set_profile_identity(
value,
voice_id,
speech_speed_id,
call_id,
sample_set_id,
)
func set_profile_identity(
@ -70,6 +78,7 @@ func set_profile_identity(
selected_voice_id: String,
selected_speech_speed_id: String,
selected_call_id: String,
selected_sample_set_id: String = VoiceProfilesType.DEFAULT_SAMPLE_SET_ID,
) -> bool:
var clean_name: String = value.strip_edges()
if (
@ -77,22 +86,26 @@ func set_profile_identity(
or not VoiceProfilesType.is_valid(selected_voice_id)
or not VoiceProfilesType.is_valid_speed(selected_speech_speed_id)
or not VoiceProfilesType.is_valid_call(selected_call_id)
or not VoiceProfilesType.is_valid_sample_set(selected_sample_set_id)
):
return false
var previous_name: String = display_name
var previous_voice_id: String = voice_id
var previous_speech_speed_id: String = speech_speed_id
var previous_call_id: String = call_id
var previous_sample_set_id: String = sample_set_id
display_name = clean_name
voice_id = selected_voice_id
speech_speed_id = selected_speech_speed_id
call_id = selected_call_id
sample_set_id = selected_sample_set_id
if _save_atomic():
return true
display_name = previous_name
voice_id = previous_voice_id
speech_speed_id = previous_speech_speed_id
call_id = previous_call_id
sample_set_id = previous_sample_set_id
return false
@ -150,6 +163,12 @@ func _load_existing() -> bool:
call_id = VoiceProfilesType.sanitized_call_id(
str(data.get("call_id", VoiceProfilesType.DEFAULT_CALL_ID))
)
sample_set_id = VoiceProfilesType.sanitized_sample_set_id(
str(data.get(
"sample_set_id",
VoiceProfilesType.DEFAULT_SAMPLE_SET_ID,
))
)
created_at_unix = int(data["created_at_unix"])
return true
@ -162,6 +181,7 @@ func _save_atomic() -> bool:
"voice_id": voice_id,
"speech_speed_id": speech_speed_id,
"call_id": call_id,
"sample_set_id": sample_set_id,
"created_at_unix": created_at_unix,
}
var result := PortableFileGuard.write_guarded(

View file

@ -25,6 +25,7 @@ var _pending_apply: Dictionary[String, Dictionary] = {}
var _pending_voice_ids: Dictionary[String, String] = {}
var _pending_speech_speed_ids: Dictionary[String, String] = {}
var _pending_call_ids: Dictionary[String, String] = {}
var _pending_sample_set_ids: Dictionary[String, String] = {}
var _host_pending_apply: Dictionary[String, Dictionary] = {}
var _latest_check_id: String = ""
var _latest_check_name: String = ""
@ -70,6 +71,10 @@ func get_persisted_call_id() -> String:
return _preferences.call_id
func get_persisted_sample_set_id() -> String:
return _preferences.sample_set_id
func get_identity_fingerprint() -> String:
return (
_session.get_local_identity_fingerprint()
@ -151,6 +156,7 @@ func apply_profile(
voice_id: String = VoiceProfilesType.DEFAULT_ID,
speech_speed_id: String = VoiceProfilesType.DEFAULT_SPEED_ID,
call_id: String = VoiceProfilesType.DEFAULT_CALL_ID,
sample_set_id: String = VoiceProfilesType.DEFAULT_SAMPLE_SET_ID,
) -> bool:
var clean_name := display_name.strip_edges()
if (
@ -159,6 +165,7 @@ func apply_profile(
or not VoiceProfilesType.is_valid(voice_id)
or not VoiceProfilesType.is_valid_speed(speech_speed_id)
or not VoiceProfilesType.is_valid_call(call_id)
or not VoiceProfilesType.is_valid_sample_set(sample_set_id)
):
apply_finished.emit(false, "Check the player name and appearance choices.")
return false
@ -178,6 +185,7 @@ func apply_profile(
_pending_voice_ids[request_id] = voice_id
_pending_speech_speed_ids[request_id] = speech_speed_id
_pending_call_ids[request_id] = call_id
_pending_sample_set_ids[request_id] = sample_set_id
if _session == null or not _session.is_gameplay_session_active():
_apply_local_result(request_id, true, "", false, PackedStringArray())
elif _session.is_host():
@ -371,6 +379,7 @@ func _apply_local_result(
_pending_voice_ids.erase(request_id)
_pending_speech_speed_ids.erase(request_id)
_pending_call_ids.erase(request_id)
_pending_sample_set_ids.erase(request_id)
conflict_result.emit(request_id, conflict, suggestions)
apply_finished.emit(false, message)
return
@ -378,6 +387,7 @@ func _apply_local_result(
var previous_voice_id := _preferences.voice_id
var previous_speech_speed_id := _preferences.speech_speed_id
var previous_call_id := _preferences.call_id
var previous_sample_set_id := _preferences.sample_set_id
var requested_voice_id: String = _pending_voice_ids.get(
request_id,
VoiceProfilesType.DEFAULT_ID,
@ -390,16 +400,22 @@ func _apply_local_result(
request_id,
VoiceProfilesType.DEFAULT_CALL_ID,
)
var requested_sample_set_id: String = _pending_sample_set_ids.get(
request_id,
VoiceProfilesType.DEFAULT_SAMPLE_SET_ID,
)
if not _preferences.set_profile_identity(
str(request["display_name"]),
requested_voice_id,
requested_speech_speed_id,
requested_call_id,
requested_sample_set_id,
):
_pending_apply.erase(request_id)
_pending_voice_ids.erase(request_id)
_pending_speech_speed_ids.erase(request_id)
_pending_call_ids.erase(request_id)
_pending_sample_set_ids.erase(request_id)
apply_finished.emit(false, "Profile could not be saved.")
return
if not _appearance_store.save_snapshot(request["appearance"]):
@ -408,17 +424,20 @@ func _apply_local_result(
previous_voice_id,
previous_speech_speed_id,
previous_call_id,
previous_sample_set_id,
)
_pending_apply.erase(request_id)
_pending_voice_ids.erase(request_id)
_pending_speech_speed_ids.erase(request_id)
_pending_call_ids.erase(request_id)
_pending_sample_set_ids.erase(request_id)
apply_finished.emit(false, "Profile could not be saved.")
return
_pending_apply.erase(request_id)
_pending_voice_ids.erase(request_id)
_pending_speech_speed_ids.erase(request_id)
_pending_call_ids.erase(request_id)
_pending_sample_set_ids.erase(request_id)
if _session != null:
_session.set_local_appearance_snapshot(_appearance_store.get_snapshot())
if _session != null and _session.is_gameplay_session_active():
@ -600,6 +619,7 @@ func _on_session_state_changed(state: NetworkSession.State) -> void:
_pending_voice_ids.clear()
_pending_speech_speed_ids.clear()
_pending_call_ids.clear()
_pending_sample_set_ids.clear()
_host_pending_apply.clear()
_latest_check_id = ""
_latest_check_name = ""
@ -676,6 +696,7 @@ func _apply_local_voice_to_avatar() -> void:
var avatar := _spawn_service.get_avatar(local_peer_id)
if avatar != null:
avatar.apply_animalese_voice_id(_preferences.voice_id)
avatar.apply_animalese_sample_set_id(_preferences.sample_set_id)
func _new_id() -> String: