added shot/bgm convert script

This commit is contained in:
UnitedAirforce
2025-01-30 08:13:06 +08:00
parent 6b34608ab3
commit 0ddc36d58f
2 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import numpy as np
import scipy.io.wavfile as wav
import os
file1 = input("Enter the first WAV file (music track): ").strip()
file2 = input("Enter the second WAV file (SFX track): ").strip()
rate1, data1 = wav.read(file1)
rate2, data2 = wav.read(file2)
if rate1 != rate2:
raise ValueError("Sample rate mismatch!")
if data1.ndim != data2.ndim:
raise ValueError("Channel count mismatch!")
# Convert to int32, addition (not normalization), then cap values.
data1 = data1.astype(np.int32)
data2 = data2.astype(np.int32)
mixed = data1 + data2
mixed = np.clip(mixed, -32768, 32767)
mixed = mixed.astype(np.int16)
dir_name, base_name = os.path.split(file2)
output_file = os.path.join(dir_name, "1_" + base_name)
wav.write(output_file, rate1, mixed)
print(f"Mixing complete! Saved as {output_file}")

View File

@@ -0,0 +1,4 @@
The 2 platform uses BGM + SHOT, but mobile uses BGM or SHOT.
This requires reprocessing the SHOT audio.
Layering the audios directly (in audition, for example) won't work because the volume won't be preserved due to potential overflow of int16.
This script preserves the volume by calculating things in int32 before capping everything back, ensuring that the audio volume stays consistent.