Soundbank Conversion Script
Tue, 2012-02-07 22:34
Hi!
I've written a small script to convert my Worms 2 soundbanks to Hedgewars. Maybe this is useful for somebody out there. The script needs Python and oggenc. I've tried it on Linux only.
Usage:
python worms2hedgewars.py [--debug]
Example:
python worms2hedgewars.py /path/to/worms/speech/Simpsons /path/to/hw/Data/Sound/voices/Simpsons
If you pass --debug, it won't actally do anything, just print out the oggenc calls it wants to make.
#!/usr/bin/python
import sys
import os.path
from subprocess import call
HW_TO_W2 = {
# Hedgewars # Worms 2
'amazing': ['amazing'],
'boring': ['boring'],
'brilliant': ['brilliant'],
'bugger': ['bummer'],
'bungee': ['bungee'],
'byebye': ['byebye'],
'comeonthen': ['comeonthen'],
'coward': ['coward'],
'cutitout': ['goaway'],
'drat': ['whatthe'],
'enemydown': ['fatality'],
'excellent': ['excellent'],
'fire': ['fire'],
'firepunch1': ['dragonpunch', 'fireball', 'fire'],
'firepunch2': ['fireball', 'fire', 'dragonpunch'],
'firepunch3': ['fire', 'dragonpunch', 'fireball'],
'firepunch4': ['dragonpunch', 'fireball', 'fire'],
'firepunch5': ['fireball', 'fire', 'dragonpunch'],
'firepunch6': ['fire', 'dragonpunch', 'fireball'],
'firstblood': ['firstblood'],
'flawless': ['flawless'],
'gonnagetyou': ['youllregretthat'],
'grenade': ['grenade'],
'hello': ['hello'],
'hmm': ['hmm'],
'hurry': ['hurry'],
'illgetyou': ['illgetyou'],
'incoming': ['incoming'],
'jump1': ['jump1'],
'jump2': ['jump2'],
'jump3': ['jump1'],
'justyouwait': ['justyouwait'],
'kamikaze': ['kamikaze'],
'laugh': ['laugh'],
'leavemealone': ['leavemealone'],
'melon': ['orders'], # doesn't match, was left over
'missed': ['missed'],
'nooo': ['nooo'],
'nutter': ['oinutter'],
'ohdear': ['ohdear'],
'ooff1': ['ooff1', 'ooff2', 'ooff3'],
'ooff2': ['ooff2', 'ooff3', 'ooff1'],
'ooff3': ['ooff3', 'ooff1', 'ooff2'],
'oops': ['oops'],
'ouch': ['ouch'],
'ow1': ['ow1', 'ow2', 'ow3'],
'ow2': ['ow2', 'ow3', 'ow1'],
'ow3': ['ow3', 'ow1', 'ow2'],
'ow4': ['ow1'],
'perfect': ['perfect'],
'reinforcements': ['drop'],
'revenge': ['revenge'],
'runaway': ['runaway'],
'sameteam': ['stupid'], # couldn't find anything better
'solong': ['byebye', 'solong'],
'stupid': ['stupid'],
'takecover': ['takecover'],
'thisoneismine': ['collect'], # No perfect match, but ok
'traitor': ['traitor'],
'uh-oh': ['uh-oh'],
'victory': ['victory'],
'watchit': ['stupid'],
'watchthis': ['watchthis'],
'whatthe': ['whatthe'],
'whoopsee': ['wobble', 'stupid'], # couldn't find anything better
'yessir': ['yessir'],
'youllregretthat': ['youllregretthat']
}
def get_w2_soundfile(hw_sound, directory):
files = os.listdir(directory)
for sound in HW_TO_W2[hw_sound]:
for file in files:
if file.lower() == sound + '.wav':
return file
return None
def ogg_encode(input_file, output_file, debug=True):
if debug:
print "oggenc '" + input_file + "' -o '" + output_file + "'"
else:
call(["oggenc", input_file, "-o", output_file])
# Main
if not (2 < len(sys.argv) < 5):
print "usage: worms2hedgewars.py [--debug]"
sys.exit(1)
w2_directory = sys.argv[1]
hw_directory = sys.argv[2]
debug = len(sys.argv) == 4 and sys.argv[3] == "--debug"
for hw_sound in HW_TO_W2.keys():
w2_soundfile = get_w2_soundfile(hw_sound, w2_directory)
if w2_soundfile:
w2_abs_soundfile = w2_directory + '/' + w2_soundfile
hw_abs_soundfile = hw_directory + '/' + hw_sound + '.ogg'
ogg_encode(w2_abs_soundfile, hw_abs_soundfile, debug)