# How to use sound.readData?

**URL:** <https://qa.fmod.com/t/how-to-use-sound-readdata/17494>\
**Category:** Unity\
**Created:** [July 29, 2021, 7:25pm UTC](https://qa.fmod.com/t/how-to-use-sound-readdata/17494 "2021-07-29T19:25:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)\
**Post date:** [July 29, 2021, 7:25pm UTC](https://qa.fmod.com/t/how-to-use-sound-readdata/17494/1 "2021-07-29T19:25:43Z")

</div>

Hi,  
I would like to know what I’m doing wrong.  
I got a C# script from a website that is recording the user input from his mic, and then waits one second and plays it.  
If the sound plays, which it does, I tried it on Unity, then the sound file does exist, so now I want to take the data out of this file and analyze it. I see that there is a function on the sound object called readData, I’m trying to use it but I’m probably doing something wrong, here is my script, any help would be appreciated.

```auto
...
    private FMOD.RESULT soundResult; 
    System.IntPtr BufferPtr;
    uint LenRead;
    FMOD.RESULT dataReadResult;
...
        soundResult = RuntimeManager.CoreSystem.createSound(exinfo.userdata, FMOD.MODE.LOOP_NORMAL | FMOD.MODE.OPENUSER, 
            ref exinfo, out sound);

        //Step 5: Start recording through our chosen device into our Sound object.

        RuntimeManager.CoreSystem.recordStart(RecordingDeviceIndex, sound, true);

        // Step 6: Start a Corutine that will tell our Sound object to play after a ceratin amount of time.

        StartCoroutine(Wait());
    }

    IEnumerator Wait()
    {
        yield return new WaitForSeconds(Latency);
        RuntimeManager.CoreSystem.playSound(sound, channelGroup, true, out channel);
        playOkay = true;
        Debug.Log("Ready To Play");

        if (soundResult == FMOD.RESULT.OK)
        {

            BufferPtr = new System.IntPtr(exinfo.length);

            dataReadResult = sound.seekData(0);
            dataReadResult = sound.readData(BufferPtr, exinfo.length, out LenRead);
            bool flag = (dataReadResult == FMOD.RESULT.OK);
            print(""+ flag);
        }
    }

```

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [August 4, 2021, 2:05am UTC](https://qa.fmod.com/t/how-to-use-sound-readdata/17494/2 "2021-08-04T02:05:46Z")

</div>

The `sound.readData` is for reading from files, not for recorded user sounds. It would be better to use `sound.lock` and `sound.unlock` instead:

[https://www.fmod.com/resources/documentation-api?version=2.02&page=core-api-sound.html#sound\_lock](https://www.fmod.com/resources/documentation-api?version=2.02&page=core-api-sound.html#sound_lock)

[https://www.fmod.com/resources/documentation-api?version=2.02&page=core-api-sound.html#sound\_unlock](https://www.fmod.com/resources/documentation-api?version=2.02&page=core-api-sound.html#sound_unlock)
