Skip to content

Commit

Permalink
TTS integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Watermelon914 authored and Watermelon914 committed Sep 2, 2024
1 parent 13f70c3 commit 898ea17
Show file tree
Hide file tree
Showing 9 changed files with 569 additions and 33 deletions.
11 changes: 11 additions & 0 deletions code/__DEFINES/tts.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
///TTS preference is disbaled entirely, no sound will be played.
#define TTS_SOUND_OFF "Disabled"
///TTS preference is enabled, and will give full text-to-speech.
#define TTS_SOUND_ENABLED "Enabled"
///TTS preference is set to only play blips of a sound, rather than speech.
#define TTS_SOUND_BLIPS "Blips Only"

///TTS filter to activate start/stop radio clicks on speech.
#define TTS_FILTER_RADIO "radio"
///TTS filter to activate a silicon effect on speech.
#define TTS_FILTER_SILICON "silicon"
80 changes: 80 additions & 0 deletions code/__HELPERS/heap.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//////////////////////
//datum/heap object
//////////////////////

/datum/heap
var/list/L
var/cmp

/datum/heap/New(compare)
L = new()
cmp = compare

/datum/heap/Destroy(force)
for(var/i in L) // because this is before the list helpers are loaded
qdel(i)
L = null
return ..()

/datum/heap/proc/is_empty()
return !length(L)

//insert and place at its position a new node in the heap
/datum/heap/proc/insert(A)

L.Add(A)
swim(length(L))

//removes and returns the first element of the heap
//(i.e the max or the min dependant on the comparison function)
/datum/heap/proc/pop()
if(!length(L))
return 0
. = L[1]

L[1] = L[length(L)]
L.Cut(length(L))
if(length(L))
sink(1)

//Get a node up to its right position in the heap
/datum/heap/proc/swim(index)
var/parent = round(index * 0.5)

while(parent > 0 && (call(cmp)(L[index],L[parent]) > 0))
L.Swap(index,parent)
index = parent
parent = round(index * 0.5)

//Get a node down to its right position in the heap
/datum/heap/proc/sink(index)
var/g_child = get_greater_child(index)

while(g_child > 0 && (call(cmp)(L[index],L[g_child]) < 0))
L.Swap(index,g_child)
index = g_child
g_child = get_greater_child(index)

//Returns the greater (relative to the comparison proc) of a node children
//or 0 if there's no child
/datum/heap/proc/get_greater_child(index)
if(index * 2 > length(L))
return 0

if(index * 2 + 1 > length(L))
return index * 2

if(call(cmp)(L[index * 2],L[index * 2 + 1]) < 0)
return index * 2 + 1
else
return index * 2

//Replaces a given node so it verify the heap condition
/datum/heap/proc/resort(A)
var/index = L.Find(A)

swim(index)
sink(index)

/datum/heap/proc/List()
. = L.Copy()
4 changes: 4 additions & 0 deletions code/__HELPERS/tts.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/proc/tts_speech_filter(text)
// Only allow alphanumeric characters and whitespace
var/static/regex/bad_chars_regex = regex("\[^a-zA-Z0-9 ,?.!'&-]", "g")
return bad_chars_regex.Replace(text, " ")
12 changes: 12 additions & 0 deletions code/controllers/configuration/entries/game_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@

/datum/config_entry/flag/emojis

/datum/config_entry/string/tts_http_url
protection = CONFIG_ENTRY_LOCKED

/datum/config_entry/string/tts_http_token
protection = CONFIG_ENTRY_LOCKED|CONFIG_ENTRY_HIDDEN

/datum/config_entry/number/tts_max_concurrent_requests
default = 4
min_val = 1

/datum/config_entry/str_list/tts_voice_blacklist

/datum/config_entry/string/alert_delta
config_entry_value = "Destruction of the station is imminent. All crew are instructed to obey all instructions given by heads of staff. Any violations of these orders can be punished by death. This is not a drill."

Expand Down
Loading

0 comments on commit 898ea17

Please sign in to comment.