Skip to content

Commit

Permalink
Fix mob_Hear runtimes (Skyrat-SS13#60)
Browse files Browse the repository at this point in the history
Fix build error (Skyrat-SS13#59)
Fix TTS voicing empty custom say emotes (Skyrat-SS13#50)
Rework TTS options with sliders (#42)
TTS fixes (#41)

* Fix TTS subsystem initialization status

* Fix TTS statistics message
TTS volume preferences (#36)

* Add TTS volume preferences

* Prevent mocked mobs from hearing TTS

* Skip TTS logic if TTS subsystem is disabled
Make humans without tts_seed fallback to Arthas (#38)
Silero TTS integration (#9)

* Update rust_g 1.0.2 -> 1.0.4-ss220

* Add TTS sound cache folder to .gitignore

* Port Silero TTS to the build

* Add TTS seed selection UI and saving

* making tts module

* added line

* Update rust_g.dm

* undefs

* small fix

* another fix

* another include fix

* Remove redundant var argument prefix

* Fix TypeScript issues

* Add TEMPORARY playsound_local override with wait support

* Fix overriden mob/living/Hear

* Fix TTS messages sanitization

* regex optimization

* Add languageless sounds case handling

* Add non-understandable messages TTS case handling

* Remove broken ffmpeg paths sanitization

* Fix messages queue

Fix observers not hearing TTS (#33)
Add TTS as separate ss220 config (#29)
TTS fixes (#30)

* Fix TTS broadcasting to unconsious mobs

* Silent scrambled whisper
TTS fixes (#21)

* Make pluses cut from chat messages instead of TTS input

* Half radio loudness

---------

Co-authored-by: Vallat <[email protected]>
  • Loading branch information
2 people authored and Dimach committed Apr 24, 2024
1 parent 2a8c983 commit 9df38d4
Show file tree
Hide file tree
Showing 22 changed files with 4,996 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,7 @@ define_sanity_output.txt

# Running OpenDream locally
tgstation.json

# Ignore cached sound files.
/sound/tts_cache/**/*
/sound/tts_scrambled/**/*
2 changes: 1 addition & 1 deletion code/__DEFINES/sound.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//THIS SHOULD ALWAYS BE THE LOWEST ONE!
//KEEP IT UPDATED

#define CHANNEL_HIGHEST_AVAILABLE 1005 //NOVA EDIT CHANGE - JUKEBOX > ORIGINAL VALUE 1015
#define CHANNEL_HIGHEST_AVAILABLE 1004 //NOVA EDIT CHANGE - JUKEBOX > ORIGINAL VALUE 1015

#define MAX_INSTRUMENT_CHANNELS (128 * 6)

Expand Down
1 change: 1 addition & 0 deletions config/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $include comms.txt
$include logging.txt
$include resources.txt
$include nova/config_nova.txt
$include ss220/ss220_config.txt
$include interviews.txt
$include lua.txt
$include auxtools.txt
Expand Down
4 changes: 4 additions & 0 deletions config/ss220/ss220_config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Text-to-speech
#TTS_TOKEN_SILERO mytoken
#TTS_ENABLED
#TTS_CACHE
78 changes: 78 additions & 0 deletions modular_ss220/modules/tts/code/_tts_defines.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#define SOUND_EFFECT_NONE 0
#define SOUND_EFFECT_RADIO 1
#define SOUND_EFFECT_ROBOT 2
#define SOUND_EFFECT_RADIO_ROBOT 3
#define SOUND_EFFECT_MEGAPHONE 4
#define SOUND_EFFECT_MEGAPHONE_ROBOT 5

#define CHANNEL_TTS_RADIO 1004

#define TTS_TRAIT_PITCH_WHISPER (1<<1)
#define TTS_TRAIT_RATE_FASTER (1<<2)
#define TTS_TRAIT_RATE_MEDIUM (1<<3)

#define rustg_file_write_b64decode(text, fname) RUSTG_CALL(RUST_G, "file_write")(text, fname, "true")

// Hashing Operations //
#define rustg_hash_string(algorithm, text) RUSTG_CALL(RUST_G, "hash_string")(algorithm, text)
#define rustg_hash_file(algorithm, fname) RUSTG_CALL(RUST_G, "hash_file")(algorithm, fname)

#define RUSTG_HASH_MD5 "md5"

#ifdef RUSTG_OVERRIDE_BUILTINS
#define md5(thing) (isfile(thing) ? rustg_hash_file(RUSTG_HASH_MD5, "[thing]") : rustg_hash_string(RUSTG_HASH_MD5, thing))
#endif

// Text Operations //
#define rustg_cyrillic_to_latin(text) RUSTG_CALL(RUST_G, "cyrillic_to_latin")("[text]")
#define rustg_latin_to_cyrillic(text) RUSTG_CALL(RUST_G, "latin_to_cyrillic")("[text]")

#define TTS_CATEGORY_OTHER "Другое"
#define TTS_CATEGORY_WARCRAFT3 "WarCraft 3"
#define TTS_CATEGORY_HALFLIFE2 "Half-Life 2"
#define TTS_CATEGORY_STARCRAFT "StarCraft"
#define TTS_CATEGORY_PORTAL2 "Portal 2"
#define TTS_CATEGORY_STALKER "STALKER"
#define TTS_CATEGORY_DOTA2 "Dota 2"
#define TTS_CATEGORY_LOL "League of Legends"
#define TTS_CATEGORY_FALLOUT "Fallout"
#define TTS_CATEGORY_FALLOUT2 "Fallout 2"
#define TTS_CATEGORY_POSTAL2 "Postal 2"
#define TTS_CATEGORY_TEAMFORTRESS2 "Team Fortress 2"
#define TTS_CATEGORY_ATOMIC_HEART "Atomic Heart"
#define TTS_CATEGORY_OVERWATCH "Overwatch"
#define TTS_CATEGORY_SKYRIM "Skyrim"
#define TTS_CATEGORY_RITA "Rita"
#define TTS_CATEGORY_METRO "Metro"
#define TTS_CATEGORY_HEROESOFTHESTORM "Heroes of the Storm"
#define TTS_CATEGORY_HEARTHSTONE "Hearthstone"
#define TTS_CATEGORY_VALORANT "Valorant"
#define TTS_CATEGORY_EVILISLANDS "Evil Islands"

#define TTS_GENDER_ANY "Любой"
#define TTS_GENDER_MALE "Мужской"
#define TTS_GENDER_FEMALE "Женский"

#define TTS_PHRASES list(\
"Так звучит мой голос.",\
"Так я звучу.",\
"Я.",\
"Поставьте свою подпись.",\
"Пора за работу.",\
"Дело сделано.",\
"Станция Нанотрейзен.",\
"Офицер СБ.",\
"Капитан.",\
"Вульпканин.",\
"Съешь же ещё этих мягких французских булок, да выпей чаю.",\
"Клоун, прекрати разбрасывать банановые кожурки офицерам под ноги!",\
"Капитан, вы уверены что хотите назначить клоуна на должность главы персонала?",\
)

#define LOCAL_TTS_VOLUME(mob) mob.client.prefs.read_preference(/datum/preference/numeric/sound_tts_local)
#define RADIO_TTS_VOLUME(mob) mob.client.prefs.read_preference(/datum/preference/numeric/sound_tts_radio)
#define LOCAL_TTS_ENABLED(mob) LOCAL_TTS_VOLUME(mob)
#define RADIO_TTS_ENABLED(mob) RADIO_TTS_VOLUME(mob)

/proc/error(msg)
log_world("## ERROR: [msg]")
57 changes: 57 additions & 0 deletions modular_ss220/modules/tts/code/providers/silero.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/datum/tts_provider/silero
name = "Silero"
is_enabled = TRUE

/datum/tts_provider/silero/request(text, datum/tts_seed/silero/seed, datum/callback/proc_callback)
if(throttle_check())
return FALSE

var/api_url = "https://api-tts.silero.ai/voice"
var/ssml_text = {"<speak>[text]</speak>"}

var/list/req_body = list()
req_body["api_token"] = CONFIG_GET(string/tts_token_silero)
req_body["text"] = ssml_text
req_body["sample_rate"] = 24000
req_body["ssml"] = TRUE
req_body["speaker"] = seed.value
req_body["lang"] = "ru"
req_body["remote_id"] = "[world.port]"
req_body["put_accent"] = TRUE
req_body["put_yo"] = FALSE
req_body["symbol_durs"] = list()
req_body["format"] = "ogg"
req_body["word_ts"] = FALSE
// var/json_body = json_encode(req_body)
// log_debug(json_body)

var/datum/http_request/request = new()
request.prepare(RUSTG_HTTP_METHOD_POST, api_url, json_encode(req_body), list("content-type" = "application/json"))
spawn(0)
request.begin_async()
UNTIL(request.is_complete())
var/datum/http_response/response = request.into_response()
proc_callback.Invoke(response)

return TRUE

/datum/tts_provider/silero/process_response(datum/http_response/response)
var/data = json_decode(response.body)
// log_debug(response.body)

if(data["timings"]["003_tts_time"] > 3)
is_throttled = TRUE
throttled_until = world.time + 15 SECONDS

return data["results"][1]["audio"]

//var/sha1 = data["original_sha1"]

/datum/tts_provider/silero/pitch_whisper(text)
return {"<prosody pitch="x-low">[text]</prosody>"}

/datum/tts_provider/silero/rate_faster(text)
return {"<prosody rate="fast">[text]</prosody>"}

/datum/tts_provider/silero/rate_medium(text)
return {"<prosody rate="medium">[text]</prosody>"}
Loading

0 comments on commit 9df38d4

Please sign in to comment.