diff tools/cut_sounds.py @ 32:85d23328a215 0.10.0

added intro music, logic for browser audio triggering on splash screen
author ark
date 2026-10-20 18:39 +0200
parents 2d46729a022e
children a464bd43b76c
line wrap: on
line diff
--- a/tools/cut_sounds.py	Tue Oct 20 17:58:10 2026 +0200
+++ b/tools/cut_sounds.py	Tue Oct 20 18:39:22 2026 +0200
@@ -13,6 +13,10 @@
 mp3. a recording is split at its longest pauses: as many as it takes to give
 the listed number of variants. pauses inside one sound are left alone.
 
+a recording listed in SKIP loses its start up to the given time before any of
+this. a sound listed in LOOP_GAP is meant to play in a loop: that much silence
+is added after its end, so the loop has a pause where it starts again.
+
 requires ffmpeg with libmp3lame, which the build does not need: the build
 reads art/sounds/ only. run this script by hand after a recording changes.
 """
@@ -37,6 +41,16 @@
     "monster_die": 4,
 }
 
+# seconds cut off the start of a recording: intro has a burp before the music
+SKIP = {
+    "intro": 3.0,
+}
+
+# seconds of silence after a looping sound. to adjust by ear
+LOOP_GAP = {
+    "intro": 0.3,
+}
+
 RATE = 44100
 BITRATE = "64k"
 # remove rumble below this frequency, Hz
@@ -148,7 +162,8 @@
 def process(path):
     name = path.stem
     count = VARIANTS.get(name, 1)
-    samples = decode(path)
+    skip = int(SKIP.get(name, 0) * RATE)
+    samples = decode(path)[skip:]
     runs = voice(samples)
     if not runs:
         sys.exit(f"{name}: no voice found")
@@ -157,9 +172,11 @@
         old.unlink()
     for i, (start, end) in enumerate(sounds, start=1):
         dst = SOUNDS / (f"{name}_{i}.mp3" if count > 1 else f"{name}.mp3")
-        encode(shape(samples, start, end), dst)
-        print(f"  {dst.name}: {start / RATE:.2f}-{end / RATE:.2f} s of the recording,"
-              f" {(end - start) / RATE:.2f} s")
+        sound = shape(samples, start, end)
+        sound.extend([0] * int(LOOP_GAP.get(name, 0) * RATE))
+        encode(sound, dst)
+        print(f"  {dst.name}: {(skip + start) / RATE:.2f}-{(skip + end) / RATE:.2f} s of the"
+              f" recording, {(end - start) / RATE:.2f} s")
 
 
 def main(names):