-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwwise.py
105 lines (76 loc) · 3.11 KB
/
wwise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#
# wwise.py
#
# Author: Jon Evans
# Modified: Oct 19, 2020
#
# This document provides the a custom OOP approach to the use of the Wise Authoring API.
#
#
from waapi import WaapiClient, CannotConnectToWaapiException, WaapiRequestFailed
from pathlib import PureWindowsPath
import os
from dir_ import Dir
class WAAPI(WaapiClient):
"""
Establishes the connection with the WAAPI Client and inherits from the WaapiClient module
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)
print('WAAPI initialised')
def __del__(self):
self.disconnect()
print('WAAPI closed safely')
def get_wwise_mac_path(self, path: str) -> str:
"""Convert path to Wwise for Mac
Args:
path (str): Any path in any format
Returns:
str: Windows path formatted for Wwise for mac
"""
win_path = PureWindowsPath(f'{path}')
win_path = win_path.joinpath()
return str(win_path)
def get_audio_import_list(self, file_list: list, abv_dict: dict) -> list:
"""Create a list of dictionaries containing the audio files to be handed
to the import_files_to_wwise() function
Args:
file_list (list): A list of all the audio file paths
abv_dict (dict): A dictionary of common audio abbreviations
Returns:
list: list of dictionaries containing the audio files and target Wwise object paths
"""
audio_import_list = []
for file in file_list:
assert os.path.exists(file)
filename = os.path.basename(file)
object_path = '\\Actor-Mixer Hierarchy\\Default Work Unit'
# Split the filename at the '_', check to see if the element is an abbreviation,
# Add it to the object_path with the Wwise container type, titled
for ww_folder in filename.split('_'):
if ww_folder[-4:] != '.wav' :
ww_folder = abv_dict[ww_folder] if ww_folder in abv_dict else ww_folder
object_path += f'\\<Folder>{ww_folder.title()}'
else:
object_path += f'\\<Sound>{filename.strip(".wav")}'
audio_import_list.append({'audioFile': f'{os.path.basename(file)}',
'objectPath': object_path})
return audio_import_list
def import_files_to_wwise(self, file_list: list, abv_dict: dict) -> None:
"""Sends a json of all the files to Wwise to be imported
Args:
file_list (list): A list of dictionaries of all the files that need to be added to Wwise
abv_dict (dict): A dictionary of common audio abbreviations
"""
audio_import_list = self.get_audio_import_list(file_list, abv_dict)
args = {
"importOperation": "useExisting",
"default": {
"importLanguage": "SFX"
},
"imports": audio_import_list,
}
self.call('ak.wwise.core.audio.import', args)
# Running as script not permitted
if __name__ == "__main__":
pass