# Playing Unity AudioClip in FMOD as Programmer Sound

**URL:** https://qa.fmod.com/t/playing-unity-audioclip-in-fmod-as-programmer-sound/19479
**Category:** Unity
**Tags:** csharp
**Created:** [November 4, 2022, 9:34pm UTC](https://qa.fmod.com/t/playing-unity-audioclip-in-fmod-as-programmer-sound/19479 "2022-11-04T21:34:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MegahammerStudios](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MegahammerStudios](https://qa.fmod.com/u/MegahammerStudios)
#### Post date: [November 4, 2022, 9:34pm UTC](https://qa.fmod.com/t/playing-unity-audioclip-in-fmod-as-programmer-sound/19479/1 "2022-11-04T21:34:17Z")

</div>

Hello,

I am a bit lost on how exactly FMOD can receive information taken from an AudioClip in Unity, and how this can be used to eventually create a Programmer Sound.

I’ve followed the general advice here: [How to create programmer sound from AUDIOCLIP](https://qa.fmod.com/t/how-to-create-programmer-sound-from-audioclip/19466)

But I’m still not sure what to put as the SoundRequirements parameters in the attached image.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/f/f341ad0aed8a490a9242000df644c85f9fab4307.png)

Also attached is the full script I’m attempting to use based off the above post.

Thank you!

[AudioClipTest.txt](https://qa.fmod.com/uploads/short-url/nWVZVYPjoTwuT7yOxlLXzmLvguA.txt) (7.9 KB)

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [November 7, 2022, 4:55am UTC](https://qa.fmod.com/t/playing-unity-audioclip-in-fmod-as-programmer-sound/19479/2 "2022-11-07T04:55:29Z")

</div>

Hi,

Thank you for adding the full script.

I have updated your code with some more comments explaining what is going on in a bit more detail.

> **PlayClipInFmod**
>
> ```auto
> public void PlayClipInFmod(AudioClip audioclip)
> {
> UnityEngine.Debug.Log("PlayClipinFmod " + audioclip.name);
> // Get the sample data from the clip and assign in to an array 
> float[] audioclip_data = new float[audioclip.samples * audioclip.channels];
> audioclip.GetData(audioclip_data, 0);
> 
> // We no longer require the 'key' parameter as it was used to access the FMOD audio table. 
> // string key = audioclip.name; 
> 
> // We are getting the information out of the Unity Audio clip passed into the function 
> SoundRequirements sound_requirements = new SoundRequirements(
> // The name of the clip we are playing, makes it easier to identify when in code  
> audioclip.name,
> // Parameters required to create sound exit info: https://fmod.com/docs/2.02/api/core-api-system.html#fmod_createsoundexinfo
> audioclip.samples, 
> audioclip.channels, 
> FMOD.SOUND_FORMAT.PCMFLOAT, 
> audioclip.frequency, 
> // The sample data that will be copied into the sound when we create it 
> audioclip_data);
> //
> 
> // Renamed this for clarity. 
> var audioClipInstance = FMODUnity.RuntimeManager.CreateInstance(EventName);
> 
> // Instead of passing in the key we will pass in the sound requirements that we have created. 
> GCHandle stringHandle = GCHandle.Alloc(sound_requirements);
> audioClipInstance.setUserData(GCHandle.ToIntPtr(stringHandle));
> 
> // The callback to make the create the sound and assign it to the instance 
> audioClipInstance.setCallback(dialogueCallback);
> 		
> // Play the sound 
> audioClipInstance.start();
> 
> // Release the memory, however if you would like to access parameters or other functions of the instane, 
> // you don't have to release it now. 
> audioClipInstance.release();
> }
> 
> ```

I have also uploaded the edited script.  
[AudioClipTest.txt](https://qa.fmod.com/uploads/short-url/inND5MwPTS5YEiN2wUysB8VGwSn.txt) (7.4 KB)

Hope this helps!

---

<div class="post-metadata">

### Author: ![MegahammerStudios](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MegahammerStudios](https://qa.fmod.com/u/MegahammerStudios)
#### Post date: [November 8, 2022, 4:00pm UTC](https://qa.fmod.com/t/playing-unity-audioclip-in-fmod-as-programmer-sound/19479/3 "2022-11-08T16:00:27Z")

</div>

A great help!

Thank you!
