iOS STT doesn't work with Unity Audio Source

I observed 2 issues. Xcode project attached here. You should be able to reproduce the problem.

Issue 1 [Mic -> Play wav]
... initialize all objects
run [micClient startMicAndRecognition]
run Unity AudioSource.PlayOneShot(AudioClip)
There is no error, however I can't hear the audio clip.
 
Issue 2 [Mic -> Play wav -> ActiveAudioSession ->Mic]
run [micClient startMicAndRecognition]
run UnitySetAudioSessionActive(1)
run Unity AudioSource.PlayOneShot(AudioClip)
Audio Clip can't be heard
run [micClient startMicAndRecognition]
Error -
2016-07-08 14:24:57.506 mobile[3460:1752563] 14:24:57.506 ERROR:   [0x1a1d9e000] AVAudioSession.mm:692: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.

2016-07-08 14:25:07.946 mobile[3460:1752563] Contact violation
2016-07-08 14:25:08.076 mobile[3460:1752563] (
  0 SpeechSDK                         0x0000000103f69e00 +[Contract fail] + 48
  1 SpeechSDK                         0x0000000103f6abf8 -[MicrophoneRecognitionClient startMicAndRecognition] + 56
  2 mobile                             0x00000001000ca6f0 -[iPhone_SpeechToText StartToRecord] + 708
  3 mobile                             0x00000001000cbf0c _startRecognize + 52
  4 mobile                             0x00000001001c3da0 DemoUnityMsSTT__startRecognize_m1386651401 + 108
  5 mobile                             0x00000001001c4718 DemoUnityMsSTT_onMicClick_m1323015428 + 280
  6 mobile                             0x00000001008778dc UnityAction_Invoke_m1979593925 + 376
  7 mobile                             0x0000000100877758 InvokableCall_Invoke_m1513455731 + 144
  8 mobile                             0x0000000100491258 _ZN18VirtActionInvoker1IP22ObjectU5BU5D_t11523773E6InvokeEjPvS1_ + 88
  9 mobile                             0x0000000100878040 InvokableCallList_Invoke_m575840373 + 400
  10 mobile                             0x000000010087a37c UnityEventBase_Invoke_m3681078084 + 92
  11 mobile                             0x000000010087a314 UnityEvent_Invoke_m2672830205 + 60
  12 mobile                             0x00000001007e44a8 Button_Press_m3889091706 + 168
  13 mobile                             0x00000001007e4518 Button_OnPointerClick_m2363576585 + 100
  14 mobile                             0x000000010082d558 _ZN23InterfaceActionInvoker1IP28PointerEventData_t3205101634E6InvokeEjP8TypeInfoPvS1_ + 96
  15 mobile                             0x00000001007d2ce0 ExecuteEvents_Execute_m153166907 + 252
  16 mobile                             0x0000000100498aa4 EventFunction_1_Invoke_m1750245256_gshared + 428
  17 mobile                             0x0000000100c9b130 ExecuteEvents_Execute_TisIl2CppObject_m1533897725_gshared + 1440
  18 mobile                             0x00000001007de3bc StandaloneInputModule_ProcessTouchPress_m2953705401 + 2944
  19 mobile                             0x00000001007dd66c StandaloneInputModule_ProcessTouchEvents_m3567487943 + 524
  20 mobile                             0x00000001007dc6c0 StandaloneInputModule_Process_m3720469665 + 284
  21 mobile                             0x0000000100144e98 _ZN18VirtActionInvoker06InvokeEjPv + 72
  22 mobile                             0x00000001007d1108 EventSystem_Update_m242895889 + 1192
  23 mobile                             0x0000000100ed74d8 _Z31RuntimeInvoker_Void_t2779279689PK10MethodInfoPvPS2_ + 60
  24 mobile                             0x000000010177b5c4 _ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP12Il2CppObject + 68
  25 mobile                             0x00000001010c55c8 _ZN25ScriptingInvocationNoArgs6InvokeEPP18ScriptingException + 60
  26 mobile                             0x00000001010c5580 _ZN25ScriptingInvocationNoArgs6InvokeEv + 32
  27 mobile                             0x00000001010bab9c _ZN13MonoBehaviour16CallUpdateMethodEi + 228
  28 mobile                             0x0000000100f94720 _ZN20BaseBehaviourManager12CommonUpdateI16BehaviourManagerEEvv + 72
  29 mobile                             0x00000001010762f0 _Z10PlayerLoopbbP10IHookEvent + 1076
  30 mobile                             0x00000001012b14a8 _ZL19UnityPlayerLoopImplb + 20
  31 mobile                             0x00000001000a6e70 UnityRepaint + 120
  32 mobile                             0x00000001000a6dec -[UnityAppController(Rendering) repaint] + 96
  33 mobile                             0x00000001000a6d4c -[UnityAppController(Rendering) repaintDisplayLink] + 120
  34 libglInterpose.dylib               0x0000000103e7f768 -[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 172
  35 QuartzCore                         0x0000000186814234 <redacted> + 40
  36 QuartzCore                         0x00000001868140e8 <redacted> + 424
  37 IOKit                             0x0000000183f51e54 IODispatchCalloutFromCFMessage + 372
  38 CoreFoundation                     0x0000000183c79030 <redacted> + 180
  39 CoreFoundation                     0x0000000183c917d4 <redacted> + 56
  40 CoreFoundation                     0x0000000183c90f0c <redacted> + 436
  41 CoreFoundation                     0x0000000183c8ec64 <redacted> + 1800
  42 CoreFoundation                     0x0000000183bb8c50 CFRunLoopRunSpecific + 384
  43 GraphicsServices                   0x00000001854a0088 GSEventRunModal + 180
  44 UIKit                             0x0000000188ea2088 UIApplicationMain + 204
  45 mobile                             0x000000010009b270 main + 208
  46 libdyld.dylib                     0x00000001837568b8 <redacted> + 4
)

Resolution

In the method where you start the mic and recognition, add these lines before you call startMicAndRecognition

AVAudioSession * _aSession= [AVAudioSession sharedInstance];
[_aSession setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
[_aSession setActive:YES error:nil];
MicrophoneRecognitionClient* micClient = [SpeechRecognitionServiceFactory createMicrophoneClient:(SpeechRecognitionMode_ShortPhrase)
withLanguage:(self.defaultLocale)
withPrimaryKey:(self.subscriptionKey)
withSecondaryKey:(self.subscriptionKey)
withProtocol:(self)];

[micClient startMicAndRecognition];
In the method where you get the final message do something like this -

[micClient endMicAndRecognition];
UnitySetAudioSessionActive(1);








Feedback and Knowledge Base