Audio Capture
Appium XCUITest driver provides a possibility to record iOS audio stream and save it to a file, which could be then retrieved on the client side. Apple does not provide any API to directly retrieve the audio stream from a Simulator or a real device, but it is possible to redirect that stream to the host machine, where it could be captured.
Server Requirements¶
- The host machine must have
ffmpeg
installed and added to PATH. It can be installed viabrew
:brew install ffmpeg
. -
For macOS 10.15+, applications recording Microphone audio need to be explicitly granted this permission. This can be done in the following settings menu:
- macOS < 13: System Preferences -> Security & Privacy -> Privacy -> Microphone
- macOS 13+: System Settings -> Privacy & Security -> Microphone
Ensure that either
ffmpeg
itself or the parent Appium process (e.g. Terminal) is present in that list. -
As this is a potentially insecure feature, it must be explicitly allowed on the server side. See the Appium documentation on Security for more details. The feature name is
audio_record
.
Simulator Setup¶
The following steps are necessary to setup iOS Simulator audio capture:
- Install Soundflower
- Redirect Simulator audio output to Soundflower: from the main Simulator menu, select I/O -> Audio Output -> Soundflower (2ch)
- In terminal, run
ffmpeg -f avfoundation -list_devices true -i ""
to get the identifier of theSoundflower (2ch)
device. This identifier prefixed with:
will be then used asaudioInput
argument tomobile: startAudioRecording
call - Test that your setup works as expected. Run any audio playback in Simulator and execute the
following command in Terminal, replacing the
-i
argument value with the one you got from the previous step: After 5 seconds, a file namedout.mp4
should be created on your desktop, containing the recorded audio stream.
Real Device Setup¶
The following steps are necessary to setup iOS Real Device audio capture:
- Connect your device to the Mac host with a cable
- Open the Audio MIDI Setup application
- Via Finder: Applications -> Utilities -> Audio MIDI Setup
- Via terminal:
open -a /System/Applications/Utilities/Audio\ MIDI\ Setup.app
- Find your phone in the list of devices there and click
Enable
next to it - In terminal, run
ffmpeg -f avfoundation -list_devices true -i ""
to get the identifier of your device in theAVFoundation audio devices
list. This identifier prefixed with:
will be then used asaudioInput
argument tomobile: startAudioRecording
call - Test that your setup works as expected. Run any audio playback on the device and execute the
following command in Terminal, replacing the
-i
argument value with the value you got from the previous step: After 5 seconds, a file namedout.mp4
should be created on your desktop, containing the recorded audio stream.
Note
Apple does not allow phone calls to be redirected this way. You can only record application or system sounds.