Skip to content

Commit

Permalink
BugFix: TTS whisper does not work correctly (#6267)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladisvell committed Dec 24, 2024
2 parents 3c68ade + e25d03b commit 9863891
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
14 changes: 8 additions & 6 deletions code/controllers/subsystem/text_to_speech.dm
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ SUBSYSTEM_DEF(tts)

var/dirty_text = message
var/text = sanitize_tts_input(dirty_text)
var/whisper = FALSE

if(!text || length_char(text) > MAX_MESSAGE_LEN)
return
Expand All @@ -304,17 +305,18 @@ SUBSYSTEM_DEF(tts)

if(traits & TTS_TRAIT_PITCH_WHISPER)
text = provider.pitch_whisper(text)
whisper = TRUE

var/hash = rustg_hash_string(RUSTG_HASH_MD5, lowertext(text))
var/filename = "sound/tts_cache/[seed.name]/[hash]"

if(fexists("[filename].ogg"))
tts_reused++
tts_rrps_counter++
play_tts(speaker, listener, filename, is_local, effect, preSFX, postSFX)
play_tts(speaker, listener, filename, is_local, effect, preSFX, postSFX, whisper)
return

var/datum/callback/play_tts_cb = CALLBACK(src, PROC_REF(play_tts), speaker, listener, filename, is_local, effect, preSFX, postSFX)
var/datum/callback/play_tts_cb = CALLBACK(src, PROC_REF(play_tts), speaker, listener, filename, is_local, effect, preSFX, postSFX, whisper)

if(LAZYLEN(tts_queue[filename]))
tts_reused++
Expand Down Expand Up @@ -371,7 +373,7 @@ SUBSYSTEM_DEF(tts)
tts_queue -= filename


/datum/controller/subsystem/tts/proc/play_tts(atom/speaker, mob/listener, filename, is_local = TRUE, effect = SOUND_EFFECT_NONE, preSFX = null, postSFX = null)
/datum/controller/subsystem/tts/proc/play_tts(atom/speaker, mob/listener, filename, is_local = TRUE, effect = SOUND_EFFECT_NONE, preSFX = null, postSFX = null, whisper = FALSE)
if(isnull(listener) || !listener.client)
return

Expand All @@ -393,7 +395,7 @@ SUBSYSTEM_DEF(tts)
CRASH("Invalid sound effect chosen.")
if(effect != SOUND_EFFECT_NONE)
if(!fexists(voice))
var/datum/callback/play_tts_cb = CALLBACK(src, PROC_REF(play_tts), speaker, listener, filename, is_local, effect, preSFX, postSFX)
var/datum/callback/play_tts_cb = CALLBACK(src, PROC_REF(play_tts), speaker, listener, filename, is_local, effect, preSFX, postSFX, whisper)
if(LAZYLEN(tts_effects_queue[voice]))
LAZYADD(tts_effects_queue[voice], play_tts_cb)
return
Expand All @@ -411,7 +413,7 @@ SUBSYSTEM_DEF(tts)
var/volume = 100
var/channel = CHANNEL_TTS_RADIO
if(is_local)
volume = 100 * listener.client.prefs.get_channel_volume(CHANNEL_TTS_LOCAL)
volume = 100 * listener.client.prefs.get_channel_volume(CHANNEL_TTS_LOCAL) / (whisper ? 3 : 1)
channel = get_local_channel_by_owner(speaker)

var/sound/output = sound(voice)
Expand All @@ -420,7 +422,7 @@ SUBSYSTEM_DEF(tts)
if(isnull(speaker))
output.wait = TRUE
output.channel = channel
output.volume = volume * listener.client.prefs.get_channel_volume(CHANNEL_GENERAL) * listener.client.prefs.get_channel_volume(channel)
output.volume = volume * listener.client.prefs.get_channel_volume(CHANNEL_GENERAL) * listener.client.prefs.get_channel_volume(channel) / (whisper ? 3 : 1)
output.environment = -1

if(output.volume <= 0)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/flufftext/Hallucination.dm
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ GLOBAL_LIST_INIT(non_fakeattack_weapons, list(/obj/item/gun/projectile, /obj/ite
if(person) //Basic talk
var/image/speech_overlay = image('icons/mob/talk.dmi', person, "h0", layer = ABOVE_MOB_LAYER)
SET_PLANE_EXPLICIT(speech_overlay, ABOVE_GAME_PLANE, src)
target.hear_say(message_to_multilingual(pick(speak_messages), safepick(person.languages)), speaker = person)
target.hear_say(message_to_multilingual(pick(speak_messages), safepick(person.languages)), speaker = person, is_whisper = TRUE)
if(target.client)
target.client.images |= speech_overlay
sleep(30)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/mob/hear_say.dm
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@
return message
return "[verb], \"[message]\""

/mob/proc/hear_say(list/message_pieces, verb = "says", italics = FALSE, mob/speaker = null, sound/speech_sound, sound_vol, sound_frequency, use_voice = TRUE)
/mob/proc/hear_say(list/message_pieces, verb = "says", italics = FALSE, mob/speaker = null, sound/speech_sound, sound_vol, sound_frequency, use_voice = TRUE, is_whisper = FALSE)
if(!client)
return 0

var/is_whisper = verb == "whispers"


if(isobserver(src) && client.prefs.toggles & PREFTOGGLE_CHAT_GHOSTEARS)
if(speaker && !speaker.client && !(speaker in view(src)))
Expand Down
6 changes: 3 additions & 3 deletions code/modules/mob/living/living_say.dm
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ GLOBAL_LIST_EMPTY(channel_to_radio_key)
var/speech_bubble_test = say_test(message)

for(var/mob/M in listening)
M.hear_say(message_pieces, verb, italics, src, speech_sound, sound_vol, sound_frequency)
M.hear_say(message_pieces, verb, italics, src, speech_sound, sound_vol, sound_frequency, FALSE)
if(M.client)
speech_bubble_recipients.Add(M.client)

Expand Down Expand Up @@ -550,14 +550,14 @@ GLOBAL_LIST_EMPTY(channel_to_radio_key)
var/speech_bubble_test = say_test(message)

for(var/mob/M in listening)
M.hear_say(message_pieces, verb, italics, src, use_voice = FALSE)
M.hear_say(message_pieces, verb, italics, src, use_voice = FALSE, is_whisper = TRUE)
if(M.client)
speech_bubble_recipients.Add(M.client)

if(eavesdropping.len)
stars_all(message_pieces) //hopefully passing the message twice through stars() won't hurt... I guess if you already don't understand the language, when they speak it too quietly to hear normally you would be able to catch even less.
for(var/mob/M in eavesdropping)
M.hear_say(message_pieces, verb, italics, src, use_voice = FALSE)
M.hear_say(message_pieces, verb, italics, src, use_voice = FALSE, is_whisper = TRUE)
if(M.client)
speech_bubble_recipients.Add(M.client)

Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/silicon/ai/freelook/eye.dm
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
to_chat(src, span_notice("You move down."))


/mob/camera/aiEye/hear_say(list/message_pieces, verb = "says", italics = 0, mob/speaker = null, sound/speech_sound, sound_vol, sound_frequency, use_voice = TRUE)
/mob/camera/aiEye/hear_say(list/message_pieces, verb = "says", italics = 0, mob/speaker = null, sound/speech_sound, sound_vol, sound_frequency, use_voice = TRUE, is_whisper = FALSE)
if(relay_speech)
if(istype(ai))
ai.relay_speech(speaker, message_pieces, verb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
return ..()


/mob/living/simple_animal/hostile/gorilla/hear_say(list/message_pieces, verb = "says", italics = FALSE, mob/speaker = null, sound/speech_sound, sound_vol, sound_frequency, use_voice = TRUE)
/mob/living/simple_animal/hostile/gorilla/hear_say(list/message_pieces, verb = "says", italics = FALSE, mob/speaker = null, sound/speech_sound, sound_vol, sound_frequency, use_voice = TRUE, is_whisper = FALSE)
if(client || !can_befriend || !ishuman(speaker) || speaker == src || incapacitated() || is_on_cooldown())
return ..()

Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/simple_animal/parrot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@
used_radios += ears


/mob/living/simple_animal/parrot/hear_say(list/message_pieces, verb = "says", italics = 0, mob/speaker = null, sound/speech_sound, sound_vol, sound_frequency, use_voice = TRUE)
/mob/living/simple_animal/parrot/hear_say(list/message_pieces, verb = "says", italics = 0, mob/speaker = null, sound/speech_sound, sound_vol, sound_frequency, use_voice = TRUE, is_whisper = FALSE)
if(speaker != src && prob(50))
parrot_hear(html_decode(multilingual_to_message(message_pieces)))
..()
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/simple_animal/slime/say.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/mob/living/simple_animal/slime/hear_say(list/message_pieces, verb = "says", italics = 0, mob/speaker = null, sound/speech_sound, sound_vol, sound_frequency, use_voice = TRUE)
/mob/living/simple_animal/slime/hear_say(list/message_pieces, verb = "says", italics = 0, mob/speaker = null, sound/speech_sound, sound_vol, sound_frequency, use_voice = TRUE, is_whisper = FALSE)
if(speaker != src && !stat)
if(speaker in Friends)
speech_buffer = list()
Expand Down

0 comments on commit 9863891

Please sign in to comment.