How to play sounds?

I was wondering the best way to play sounds using normcore in my game, as I found no official documentation for this. Is using RPC events the best option?
10 Replies
kapa.ai
kapa.ai3mo ago
Hi @Horse Eater Beater. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Normcore provides high-quality, low-latency audio streams via the CreateAudioInputStream() API. This API returns an AudioInputStream that can be used to send audio data to all clients. Once called, all clients will be able to retrieve a corresponding AudioOutputStream object using the GetAudioOutputStream() API along with the clientID and streamID from the AudioInputStream object. This is how you can send and receive audio data in Normcore. For voice chat, Normcore includes a component called RealtimeAvatarVoice. This component works on any realtime prefab as long as the RealtimeView component has an owner. If the component is owned locally, a microphone stream is created, and if it is owned by a remote client, an AudioOutput component is created to play back audio. By default, RealtimeAvatarVoice will create an AudioSource component, but you can create an AudioSource manually if you want to set custom spatialization settings. As for RPC events, they are available as a last resort. If you have players that can join a room late, RPC messages make consistent synchronization difficult. Any state modified in response to an RPC message will need to be manually synchronized by your own code. So, it's not recommended to use RPC events for playing sounds. You can find more information about audio streams and voice chat in the Normcore Documentation (https://normcore.io/documentation/room/room#media-streams) and RealtimeAvatarVoice (https://normcore.io/documentation/realtime/xr/voicechat) respectively. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@444173592205459466> kapa.ai is still learning and improving, please let us know how it did by reacting below
maxweisel
maxweisel3mo ago
I think it depends on what you’re trying to play. for one-shots we usually just instantiate a prefab that’s set to play on awake then have the owner destroy it after but the timer recipe is great for synchronizing music playback
Horse Eater Beater
When playing a prefab how to I avoid latency?
maxweisel
maxweisel3mo ago
how do you mean?
Horse Eater Beater
Whenever I spawn the object theres a solid 0.5 second delay before the sounds played And it's simply a realtime view with an audio source attached
maxweisel
maxweisel3mo ago
you may have to mess with the playback settings is it loading the clip from disk?
Horse Eater Beater
Yes I believe so
maxweisel
maxweisel3mo ago
maybe set that to be in memory?
Mechabit
Mechabit3mo ago
or preload the sound at the start of the game