初始化工程
info
|
Note: 如果您使用的是 Python 2.7,那么您需要安装 Python 2.7 的 Microsoft Visual C++ Compiler。 |
从任意目录运行以下命令来安装依赖:
如果您使用的是 Python 2.7,请运行以下命令来安装额外的包:
pip install trollius futures
工程代码
info
|
Note: 命令行 from waapi import WAAPI_URI 会导入 API 路径声明。
它位于 <Wwise 安装路径>/SDK/include/AK/WwiseAuthoringAPI/py 。通过在该示例中扩展 sys.path,该文件的位置被动态添加到 Python 的路径中,但你也可以将 waapi.py 文件通过复制粘贴放到示例文件的相同目录下。
请注意 ak_authobahn.py 这个额外文件提供了一个特殊组件类型,该类型支持将自定义选项发送到 WAAPI。我们在示例目录中提供了该文件。
|
Python 2.7
找到示例文件 <Wwise 安装路径>/SDK/samples/WwiseAuthoringAPI/python/hello-wwise-wamp/main_py2.py
的位置。
该文件包含以下代码,让您能连接到 Wwise Authoring API。
import os
import sys
import trollius as asyncio
from trollius import From
from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner
sys.path.append(os.path.join(os.path.dirname(__file__), '../../../../include/AK/WwiseAuthoringAPI/py'))
from waapi import WAAPI_URI
class MyComponent(ApplicationSession):
def onJoin(self, details):
try:
res = yield From(self.call(WAAPI_URI.ak_wwise_core_getinfo))
except Exception as ex:
print("call error: {}".format(ex))
else:
print("Hello {} {}".format(res.kwresults['displayName'], res.kwresults['version']['displayName']))
self.leave()
def onDisconnect(self):
print("The client was disconnected.")
asyncio.get_event_loop().stop()
if __name__ == '__main__':
runner = ApplicationRunner(url=u"ws://127.0.0.1:8080/waapi", realm=u"realm1")
try:
runner.run(MyComponent)
except Exception as e:
print(type(e).__name__ + ": Is Wwise running and Wwise Authoring API enabled?")
Python 3.6
找到示例文件 <Wwise installation path>/SDK/samples/WwiseAuthoringAPI/python/hello-wwise-wamp/main_py3.py
.
该文件包含以下代码,让您能连接到 Wwise Authoring API。
import os
import sys
import asyncio
from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner
sys.path.append(os.path.join(os.path.dirname(__file__), '../../../../include/AK/WwiseAuthoringAPI/py'))
from waapi import WAAPI_URI
class MyComponent(ApplicationSession):
def onJoin(self, details):
try:
res = yield from self.call(WAAPI_URI.ak_wwise_core_getinfo)
except Exception as ex:
print("call error: {}".format(ex))
else:
print("Hello {} {}".format(res.kwresults['displayName'], res.kwresults['version']['displayName']))
self.leave()
def onDisconnect(self):
print("The client was disconnected.")
asyncio.get_event_loop().stop()
if __name__ == '__main__':
runner = ApplicationRunner(url=u"ws://127.0.0.1:8080/waapi", realm=u"realm1")
try:
runner.run(MyComponent)
except Exception as e:
print(type(e).__name__ + ": Is Wwise running and Wwise Authoring API enabled?")
运行工程
使用以下命令从示例文件的目录中运行该示例文件:
Python 2.7:
Python 3.6:
如果 Wwise Authoring API 成功地连接到 Wwise,您会看到以下输出结果: