Audio

Similar to Game Engines like Unity and Unreal, Audio in Omniverse, is location based. This means that in order to play an AudioClip, you need to first attach it to a prim. Once this clip is attached, attributes can be tweaked in order to achieve specific effects.

Play an Audio Clip Once

Use a Prim to play an Audio Clip once.

import omni

usd_context = omni.usd.get_context()
stage = usd_context.get_stage()
my_audio_prim = stage.GetPrimAtPath(my_audio_prim_path)
my_audio_prim.GetAttribute("loopCount").Set(0)

audio = omni.usd.audio.get_stage_audio_interface()
audio.spawn_voice(my_audio_prim)

Play a Looping audio clip

Use a Prim to play a looping Audio Clip.

audio = omni.usd.audio.get_stage_audio_interface()
my_audio_prim.GetAttribute("loopCount").Set(-1)
audio.spawn_voice(prim)

Set the loop count

The loopCount attribute tells the audio engine how many times to loop a sound. The value -1 is used to loop a sound indefinitely, 0 is used to play the audio clip just once, 1 and up plays it n+1 times (where n is the value of loopCount)

my_audio_prim.GetAttribute("loopCount").Set(-1)

Set the Pitch

# double the pitch
pitch_multiplier = 2.0
my_audio_prim.GetAttribute("timeScale").Set(pitch_multiplier)

Set the Volume

# set to half volume
volume_multiplier = 0.5
my_audio_prim.GetAttribute("gain").Set(volume_multiplier)