Audiokinetic's Community Q&A is the forum where users can ask and answer questions within the Wwise and Strata communities. If you would like to get an answer from Audiokinetic's Technical support team, make sure you use the Support Tickets page.

0 votes

Hello! I'm using Wwise 2017, 2019.

I have a situation where I need to automate the process of converting wav files to wem. Now it is a manual process. I have an unusual situation where the audio file must have a strict size, so I have to convert the same file several times but with different Vorbis quality values.

I want to try using waapi. I was already able to import the file into the project using a python script. But I can't find information anywhere on how to start the Conversion?

in General Discussion by Starter G. (100 points)
I solved this issue with the help of WwiseCLI. This python script worked for me.

import os
import subprocess
import glob
import xml.etree.ElementTree as ET

# Конфигурация
WWISE_CLI_PATH = "C:/Program Files (x86)/Audiokinetic/Wwise2019.2.15.7667/Authoring/x64/Release/bin/WwiseConsole.exe"
INPUT_WAV_DIR = "E:/AI/NierAudio/Temp/WwiseCLI/wav_files"
OUTPUT_WEM_DIR = "E:/AI/NierAudio/Temp/WwiseCLI/wem_files"
PROJECT_PATH = "E:/AI/NierAudio/Wwise/NierA_19/NierA_19.wproj"
WSOURCES_PATH = "E:/AI/NierAudio/Temp/WwiseCLI/external_sources.wsources"
CONVERSION_SETTING = "Vorbis Quality High"  # Соответствует настройке проекта

def create_wsources_file():
    """Создаёт файл .wsources для указания WAV-файлов."""
    wav_files = glob.glob(os.path.join(INPUT_WAV_DIR, "*.wav"))
    if not wav_files:
        raise FileNotFoundError(f"WAV-файлы не найдены в папке: {INPUT_WAV_DIR}")
    
    print("Найдены WAV-файлы:")
    for wav in wav_files:
        print(f"  - {wav}")
    
    # Создаём XML-структуру для .wsources
    root = ET.Element("ExternalSourcesList", SchemaVersion="1")
    for wav_file in wav_files:
        source = ET.SubElement(root, "Source")
        source.set("Path", os.path.abspath(wav_file).replace("\\", "/"))
        source.set("Conversion", CONVERSION_SETTING)
    
    # Сохраняем .wsources файл
    os.makedirs(os.path.dirname(WSOURCES_PATH), exist_ok=True)
    tree = ET.ElementTree(root)
    tree.write(WSOURCES_PATH, encoding="utf-8", xml_declaration=True)
    print(f"Создан файл .wsources: {WSOURCES_PATH}")
    
    # Выводим содержимое .wsources для отладки
    with open(WSOURCES_PATH, "r", encoding="utf-8") as f:
        print("Содержимое .wsources:")
        print(f.read())

def convert_external_source():
    """Конвертирует WAV-файлы в WEM с помощью convert-external-source."""
    try:
        result = subprocess.run(
            [
                WWISE_CLI_PATH, "convert-external-source", PROJECT_PATH,
                "--platform", "Windows",
                "--source-by-platform", "Windows", WSOURCES_PATH,
                "--output", "Windows", OUTPUT_WEM_DIR,
                "--verbose"
            ],
            check=True, capture_output=True, text=True
        )
        print(f"WEM-файлы созданы в: {OUTPUT_WEM_DIR}")
        print(f"Вывод команды: {result.stdout}")
    except subprocess.CalledProcessError as e:
        print(f"Ошибка при конвертации в WEM: {e}")
        print(f"Вывод команды: {e.stdout}")
        print(f"Ошибки команды: {e.stderr}")
        raise

def check_wem_files():
    """Проверяет наличие WEM-файлов в OUTPUT_WEM_DIR."""
    try:
        wem_files = glob.glob(os.path.join(OUTPUT_WEM_DIR, "*.wem"))
        if not wem_files:
            print(f"WEM-файлы не найдены в: {OUTPUT_WEM_DIR}")
            return False
        
        for wem_file in wem_files:
            print(f"Найден WEM-файл: {os.path.basename(wem_file)} в {OUTPUT_WEM_DIR}")
        return True
    except Exception as e:
        print(f"Ошибка при проверке WEM-файлов: {str(e)}")
        return False

def main():
    try:
        # Проверяем существование WwiseConsole.exe
        if not os.path.isfile(WWISE_CLI_PATH):
            raise FileNotFoundError(f"WwiseConsole.exe не найден: {WWISE_CLI_PATH}")
        
        # Проверяем существование проекта
        if not os.path.isfile(PROJECT_PATH):
            raise FileNotFoundError(f"Проект Wwise не найден: {PROJECT_PATH}")
        
        # Проверяем существование папки с WAV-файлами
        if not os.path.isdir(INPUT_WAV_DIR):
            raise FileNotFoundError(f"Папка с WAV-файлами не найдена: {INPUT_WAV_DIR}")
        
        # Создаём папку для выходных WEM-файлов
        os.makedirs(OUTPUT_WEM_DIR, exist_ok=True)
        
        # Создаём .wsources файл
        create_wsources_file()
        
        # Выполняем конвертацию
        convert_external_source()
        
        # Проверяем наличие WEM-файлов в OUTPUT_WEM_DIR
        if check_wem_files():
            print("Конвертация завершена успешно!")
        else:
            print("Ошибка: WEM-файлы не созданы в {OUTPUT_WEM_DIR}.")
    except Exception as e:
        print(f"Ошибка: {str(e)}")

if __name__ == "__main__":
    main()

Please sign-in or register to answer this question.

...