Edit this Doc Audio Capture From iOS Simulators and Real Devices

Client Side API

Since Appium 1.18.0 there is 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.

mobile: startAudioRecording

Starts audio recording process on the given host audio input with the given audio compression parameters.

Supported arguments

mobile: stopAudioRecording

Stops the audio recording process previously started by startAudioRecording call. The result of the method call is a base64-encoded .mp4 file containing the audio content recorded since startAudioRecording was called. Subsequent method calls will return the same result. If startAudioRecording was not called before then an empty string is returned.

Usage Examples

driver.executeScript("mobile: startAudioRecording", ImmutableMap.of("audioInput", ":1"));
byte[] mp4Data = Base64.getMimeDecoder()
  .decode((String) driver.executeScript("mobile: stopAudioRecording"));
try (FileOutputStream fos = new FileOutputStream("out.mp4")) {
driver.execute_script('mobile: startAudioRecording', {'audioInput': ':1'})
base64_str = driver.execute_script('mobile: stopAudioRecording')
with open('out.mp4', 'wb') as f:
@driver.execute_script 'mobile: startAudioRecording', audioInput: ':0'
sleep 10
base64_str = @driver.execute_script 'mobile: stopAudioRecording'
File.write 'out.mp4', Base64.decode64(base64_str)

Server Requirements

Appium version should be 1.18.0 or newer.

It is mandatory that the host machine has FFMPEG installed and available in PATH. On macOS it could be installed via Brew: brew install ffmpeg.

macOS since version 10.15 requires applications that record Microphone audio to be explicitly enabled in System Preferences->Security & Privacy->Privacy->Microphone tab. Make sure either FFMPEG itself or the parent Appium process (e.g. Terminal) is present in that list.

The feature is potentially unsecure, so it must be explicitly allowed on the server side. The feature name is audio_record. See Security for more details.

Simulator Setup

The following steps are necessary to setup iOS Simulator audio capture:

Real Device Setup

The following steps are necessary to setup iOS Real Device audio capture:

Apple does not allow phone calls to be redirected this way. You can only record application or system sounds.

Further Reading