mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 10:21:11 +00:00
Maybe fix VOX, attempt 2. (#24536)
This commit is contained in:
committed by
Kurfursten
parent
bc50ba9afd
commit
8ca9e6a899
4519
code/defines/vox_sound_lengths.dm
Normal file
4519
code/defines/vox_sound_lengths.dm
Normal file
File diff suppressed because it is too large
Load Diff
@@ -236,8 +236,8 @@ var/VOX_AVAILABLE_VOICES = list(
|
||||
to_chat(M, "<span class='notice'>[src] announces: <span class='big'>\"[message]\"</span>.</span>")
|
||||
|
||||
for(var/word in words)
|
||||
play_vox_word(word, vox_voice, src.z, null)
|
||||
sleep(1)
|
||||
play_vox_word(word, vox_voice, src.z, null, TRUE)
|
||||
|
||||
/*
|
||||
/mob/living/silicon/ai/verb/announcement()
|
||||
set name = "Announcement"
|
||||
@@ -297,12 +297,15 @@ var/list/vox_units=list(
|
||||
/proc/vox_num2list(var/number)
|
||||
return num2words(number, zero='sound/vox_fem/zero.ogg', minus='sound/vox_fem/minus.ogg', hundred='sound/vox_fem/hundred.ogg', digits=vox_digits, tens=vox_tens, units=vox_units)
|
||||
|
||||
/proc/play_vox_word(var/word, var/voice, var/z_level, var/mob/only_listener)
|
||||
word = lowertext(word)
|
||||
if(vox_sounds[voice][word])
|
||||
return play_vox_sound(vox_sounds[voice][word],z_level,only_listener)
|
||||
return 0
|
||||
/proc/play_vox_word(var/word, var/voice, var/z_level, var/mob/only_listener, var/do_sleep=FALSE)
|
||||
. = TRUE
|
||||
|
||||
word = lowertext(word)
|
||||
var/soundFile = vox_sounds[voice][word]
|
||||
if(soundFile)
|
||||
. = play_vox_sound(soundFile,z_level,only_listener)
|
||||
if (do_sleep)
|
||||
sleep(vox_sound_lengths[soundFile] SECONDS)
|
||||
|
||||
/proc/play_vox_sound(var/sound_file, var/z_level, var/mob/only_listener)
|
||||
var/sound/voice = sound(sound_file, wait = 1, channel = VOX_CHANNEL)
|
||||
@@ -318,4 +321,5 @@ var/list/vox_units=list(
|
||||
M << voice
|
||||
else
|
||||
only_listener << voice
|
||||
return 1
|
||||
|
||||
return TRUE
|
||||
|
||||
78
tools/vox_sound_lengths.py
Executable file
78
tools/vox_sound_lengths.py
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Uses ffprobe to read sound file length.
|
||||
# So uh, have ffprobe accessible somehow.
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
from typing import Dict, Awaitable
|
||||
|
||||
|
||||
DIRECTORIES = [
|
||||
"vox",
|
||||
"vox_fem",
|
||||
"vox_sfx",
|
||||
"vox_mas"
|
||||
]
|
||||
|
||||
PROCESS_BATCH_COUNT = 32
|
||||
|
||||
async def main() -> Awaitable[None]:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("outfile", help="The .dm file to output the length info to.")
|
||||
parser.add_argument("sounds_directory", default="../sound/", help="The sound/ directory")
|
||||
args = parser.parse_args()
|
||||
|
||||
sounds_directory = args.sounds_directory
|
||||
outfile = args.outfile
|
||||
|
||||
durations = {}
|
||||
tasks = []
|
||||
|
||||
count = 0
|
||||
|
||||
for directory_name in DIRECTORIES:
|
||||
directory = os.path.join(sounds_directory, directory_name)
|
||||
|
||||
for filename in os.listdir(directory):
|
||||
print(filename)
|
||||
|
||||
tasks.append(do_work(sounds_directory, directory_name, filename, durations))
|
||||
|
||||
count += 1
|
||||
# We have to process these in batches.
|
||||
# We can't just start 5000 ffprobe processes.
|
||||
if count == PROCESS_BATCH_COUNT:
|
||||
await asyncio.gather(*tasks)
|
||||
count = 0
|
||||
tasks = []
|
||||
|
||||
if tasks:
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
with open(outfile, "w") as f:
|
||||
f.write("// Automatically generated by vox_sound_lengths.py\n")
|
||||
f.write("var/list/vox_sound_lengths = list()\n")
|
||||
# We can't put this stuff inside a regular list() call because it's too damn big apparently.
|
||||
f.write("/__vox_sound_lengths_init/New()\n")
|
||||
for (name, length) in durations.items():
|
||||
f.write(f"\tvox_sound_lengths['{name}'] = {length}\n")
|
||||
f.write("/var/__vox_sound_lengths_init/__vox_sound_lengths_init_instance = new\n")
|
||||
|
||||
async def do_work(sound_dir: str, dir_name: str, file_name: str, durations: Dict[str, float]) -> Awaitable[None]:
|
||||
file_path = os.path.join(sound_dir, dir_name, file_name)
|
||||
duration = await get_audio_file_length(file_path)
|
||||
durations[f"sound/{dir_name}/{file_name}"] = duration
|
||||
|
||||
async def get_audio_file_length(file_name: str) -> Awaitable[float]:
|
||||
ffprobe_args = ["-i", file_name, "-show_entries", "format=duration", "-v", "quiet", "-of", "json"]
|
||||
proc = await asyncio.create_subprocess_exec("ffprobe", *ffprobe_args, stdout=subprocess.PIPE, encoding="utf-8")
|
||||
await proc.wait()
|
||||
|
||||
j = json.loads(await proc.stdout.read())
|
||||
return float(j["format"]["duration"])
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -465,6 +465,7 @@
|
||||
#include "code\defines\byondtools.dm"
|
||||
#include "code\defines\obj.dm"
|
||||
#include "code\defines\vox_sounds.dm"
|
||||
#include "code\defines\vox_sound_lengths.dm"
|
||||
#include "code\defines\obj\weapon.dm"
|
||||
#include "code\defines\procs\AStar.dm"
|
||||
#include "code\defines\procs\biohazard_alert.dm"
|
||||
|
||||
Reference in New Issue
Block a user