# iOS Recording from Microphone in Unity

**URL:** <https://qa.fmod.com/t/ios-recording-from-microphone-in-unity/11906>\
**Category:** Unity\
**Created:** [May 5, 2015, 5:46pm UTC](https://qa.fmod.com/t/ios-recording-from-microphone-in-unity/11906 "2015-05-05T17:46:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![drapple1](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@drapple1](https://qa.fmod.com/u/drapple1)\
**Post date:** [May 5, 2015, 5:46pm UTC](https://qa.fmod.com/t/ios-recording-from-microphone-in-unity/11906/1 "2015-05-05T17:46:40Z")

</div>

I’m trying to record audio from the microphone on iOS. However, system.recordStart(…) is returning ERR\_RECORD when I run on a device (specifically, an iPad 3). It works when running in play mode in Unity, but not on the device. I’ve included my simplified code below.

All this code does is create an FMOD system, gets some driver information, then tries to record 1 second of looping into a sound. I properly get the single device’s capabilities (Rate = 48000, Channels = 1), but the recordStart(…) call fails.

I’ve disabled Unity’s audio, since I’m using the FMOD low level integration myself. Enabling Unity’s audio makes the call work, but I get no audio playback.

Thanks for any help. I’ve been banging my head against this for too long!

-Doug

```

using UnityEngine;
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text;

public class RecordTest : MonoBehaviour 
{
  private FMOD.System mSystem = null;

  private int mDeviceIndex = 0;
  private int mRate = 0;
  private int mChannels = 0;

  private uint mByteCount = 0;
  private byte[] mBytes;
  private FMOD.Sound mSound = null;
  
  private const float kRecordSeconds = 1.0f;
  
  void Start () 
  {
    FmodCheck( FMOD.Factory.System_Create( out mSystem ) );

    FmodCheck( mSystem.init( 128, FMOD.INITFLAGS.NORMAL, (System.IntPtr)null ) );

    int numDrivers, numConnected;
    FmodCheck( mSystem.getRecordNumDrivers( out numDrivers, out numConnected ) );

    Guid guid;
    StringBuilder nameBuilder = new StringBuilder();
    FMOD.SPEAKERMODE speakerMode;
    FMOD.DRIVER_STATE driverState;
    FmodCheck( mSystem.getRecordDriverInfo( mDeviceIndex, nameBuilder, 0,
                                            out guid, out mRate, out speakerMode,
                                            out mChannels, out driverState ) );
    
    Debug.Log( "Drivers = " + numDrivers + ", Connected = " + numConnected );
    Debug.Log( "Rate = " + mRate + ", Channels = " + mChannels );

    // 2.0f for the byte size of PCM16.
    mByteCount = (uint)( kRecordSeconds*2.0f*(float)( mChannels*mRate ) );
    mBytes = new byte[mByteCount];
    
    FMOD.CREATESOUNDEXINFO info = new FMOD.CREATESOUNDEXINFO();
    info.cbsize = Marshal.SizeOf( info );
    info.numchannels = mChannels;
    info.defaultfrequency = mRate;
    info.format = FMOD.SOUND_FORMAT.PCM16;
    info.length = mByteCount;

    FmodCheck( mSystem.createSound( mBytes, FMOD.MODE.OPENMEMORY_POINT | FMOD.MODE.OPENRAW, ref info, out mSound ) );

    const bool kLoop = true;
    FmodCheck( mSystem.recordStart( mDeviceIndex, mSound, kLoop ) );
  }

  private void FmodCheck( FMOD.RESULT iResult )
  {
    if ( iResult != FMOD.RESULT.OK )
      Debug.Log( "FMOD Error = " + iResult );
  }
}

```

---

<div class="post-metadata">

**Author:** ![drapple1](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@drapple1](https://qa.fmod.com/u/drapple1)\
**Post date:** [May 14, 2015, 8:25pm UTC](https://qa.fmod.com/t/ios-recording-from-microphone-in-unity/11906/2 "2015-05-14T20:25:11Z")

</div>

Looks like I just needed to set the audio session category to be **AVAudioSessionCategoryPlayAndRecord**. Easy!

---

<div class="post-metadata">

**Author:** ![Luai](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@Luai](https://qa.fmod.com/u/Luai)\
**Post date:** [April 7, 2016, 12:36pm UTC](https://qa.fmod.com/t/ios-recording-from-microphone-in-unity/11906/3 "2016-04-07T12:36:19Z")

</div>

Hello  
I’m facing the same problem.  
Can you please tell me how to set the audio session category to :AVAudioSessionCategoryPlayAndRecord  
Thanks

---

<div class="post-metadata">

**Author:** ![mathew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mathew/32/431_2.png) [@mathew](https://qa.fmod.com/u/mathew)\
**Post date:** [April 8, 2016, 6:03am UTC](https://qa.fmod.com/t/ios-recording-from-microphone-in-unity/11906/4 "2016-04-08T06:03:38Z")

</div>

> [@](#):
>
> Hello  
> I’m facing the same problem.  
> Can you please tell me how to set the audio session category to :AVAudioSessionCategoryPlayAndRecord  
> Thanks

Please see the ‘recording’ section of our iOS basics documentation:  
[http://www.fmod.org/documentation/#content/generated/platform\_ios/basics.html](http://www.fmod.org/documentation/#content/generated/platform_ios/basics.html)

---

<div class="post-metadata">

**Author:** ![bin.jia](https://avatars.discourse-cdn.com/v4/letter/b/9fc29f/32.png) [@bin.jia](https://qa.fmod.com/u/bin.jia)\
**Post date:** [June 8, 2020, 8:45am UTC](https://qa.fmod.com/t/ios-recording-from-microphone-in-unity/11906/5 "2020-06-08T08:45:24Z")

</div>

I meet same problem, but I can’t to get you give the help link(page not found),so how to get it?

---

<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:** [June 22, 2020, 3:10am UTC](https://qa.fmod.com/t/ios-recording-from-microphone-in-unity/11906/6 "2020-06-22T03:10:29Z")

</div>

You can find the Recording section in the new link below:

[https://www.fmod.com/resources/documentation-api?version=2.1&page=platforms-ios.html#recording](https://www.fmod.com/resources/documentation-api?version=2.1&page=platforms-ios.html#recording)
