Thats great! the API Doc is difficult to understand for me
And I tried to used python to add audio information to usdc files then zip them with usdz tool, but the embeded sound still is silent.
I thought it is possible that VT value issue, because I did not use it on my python code, but the doc request that it needs Vt value, but I don’t understand what is Vt value and how to use it
This is the result usdz file after zipping with usdzip image5.usdz (5.8 MB)
And I just want to know if there is particular api doc for python, because the official API doc is sooooo difficult for me to understand, especially I’m a beginner of both USD and Coder who has no knowledge about C languages
Hi @micsir
Welcome to the forum! I moved your post to a new topic so it can get more eyes on it, as it was only tangentially related to the previous topic.
I’m not at my computer right now to test your code, but I can help answer your questions:
Unfortunately there aren’t Python specific documentation. It’s not ideal, but learning to convert from the C++ APIs is the best option right now. There is the ability to generate Python typing for autocomplete during the build which can help a bit.
You mentioned that the audio is silent. What application are you trying to play in? Audio support is dependent on the app and right now only very few applications support it. QuickLook on the Mac/iPhone are the few that do
A VtValue is what USD uses to wrap around all the attribute value types. In Python it often auto converts to the actual type , but for C++ it means you don’t need a function for every single possible type, and instead can have one wrapper type.
The device I used is iPhone 13, the 16.8 iOS system, when I open the USDZ file with QuickLook, there is silent, I will read the doc again to see if I can find the solution, regarding the VtValue, I’m not sure if it is convenient for you to provide a Python code, that will be more helpful for me to understand it.
Such as, as the API doc stated, the method to create file path attribute is USDMEDIA_API UsdAttribute CreateFilePathAttr (VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const. How should I do it with Python code and Vt Library
In Python this would usually auto convert. The file path attribute is a string and for this you can basically provide it any python string and it should be fine. Your current code does that already and should be fine
However, note the def Xform "audio". I suspect the issue might be there and that the USDZ player does not recognize the SpatialAudio because it’s not defined like that.
Could you try:
from pxr import UsdMedia
UsdMedia.SpatialAudio.Define(stage, "/audio")
So that it applies the correct type definition, generating something like this:
NVIDIA recently published these Python API docs: UsdMedia module — pxr-usd-api 105.0.2 documentation. They’re programmatically translated from the C++ docs so it’s not perfect and in this particular case it still requires that C++ understanding of VtValue.
You might find it useful in other cases though. Let me know if you use it and have any feedback.
@mati-nvidia is that something that could be added to the mainline USD repo? Since its programatic, it would be nice to be able to have them synced with the Pixar builds or generate locally too.