Capturing Audio Output During Testing: Part 1

June 03, 2026 · 14 min read · Testing Guide

HeadSpin Platform
Automated & amp; manual testing made easy through data science insights.
Differentiating capabilities:
  • Extensive end-to-end automation of QA process
  • Relative analysis of app performance against peers
  • Continuous monitoring of app performance using synthetic data for high availability of apps
  • Easy-to-use developer friendly platform
cloudtest go
Affordable Real Device Testing for Emerging Teams
cloudtest go
Affordable Real Device Testing for Digital Enterprises
cloudtest go
The Ultimate Solution for a Powerful Blend of Functional & amp; Performance Testing!
cyol
TEM
New
Centralized mobile examination execution in cloud
cyol
Enhance Your Accessibility Testing With HeadSpin
cyol
Automate camera-based testing

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

retail

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

capturing-audio-outputcapturing-audio-output

Capturing Audio Output During Testing: Part 1

Published on
May 15, 2019
Updated on
Published on
March 30, 2022
Updated on
 by 
 Jonathan LippsJonathan Lipps
Jonathan Lipps

HeadSpin & # x27; s custom Bluetooth board and analysis API allows testing vocalisation supporter, validating streaming medium, and working with phonation outcry on real devices.

testing-voice-assistants

One of the near common observations you can make while watching people utilise their wandering apps in the real world is that they much have phone plugged into them (or not, depending on their level ofcourage). We could talk more about uttermost headphone use as a societal phenomenon, but this is Appium Pro! As tester, we & # x27; re conceive to ourselves, & quot; Oh no, have we tested the audio playback portion of our app? & quot;

Audio playback examination is a hard concept to undertake, so we & # x27; re going to explore it over 2 editions. In this first edition, we & # x27; ll examine audiocapture, or how to make sure we can get audio file yield from real user scenario in our app. In the second component, we & # x27; ll look at audioverification, which is the real crucial piece. But of trend, we can & # x27; t control audio playback if we experience no way to capture the audio! So let & # x27; s figure this out.

HeadSpin ’ s AV solution enables testing by capturing the user experience of real media devices, include genuine screen and audio yield..

We have several different pick when it comes to gather audio, and the maiden is to choose whether we & # x27; re capturing from a real device or a practical device.

Capturing audio from a real device

To bewitch sound from a real wandering device, you & # x27; ll need a gimmick that has a headphone jack or adapter. Plug one end of a 3.5mm male-to-male headphone cable into the headphone jack, and the former into your digital sound input device. Many computers these days don & # x27; t support line in directly, so you may need an extraneous digital audio converter. Either way, remember which sound comment device the headphone is now associate to, and simply skip down to the ffmpeg setup instructions below.

Emulators & amp; Android Simulators.

Capturing audio from a virtual device

Virtual devices play audio using the system audio outputs, so for virtual devices we need a way to treat a system audio output as a kind of soundinput. I & # x27; m going to explain how to do this on a Mac; for other platforms, you & # x27; ll need to research how to achieve the like result.

Soundflower Setup

The first thing we need to do is getSoundflowerup and go. This is a kernel extension which adds a especial sound yield device and a exceptional sound input device called Soundflower (2ch). So go forward and follow the Soundflower installation instructions until this twist is visible in your system (restart probably required). To check whether the device is visible, go to the & quot; Sound & quot; preference pane in System Preferences, and you should see the devices under the & quot; Output & quot; and & quot; Input & quot; tabs.

Now, experiment with playing an sound file. While it & # x27; s playing, vary the yield device to the Soundflower output. You should try the audio cut out. That & # x27; s because the audio is now being redirected to the Soundflower device, which is not link to your verbalizer or earphone. It & # x27; s a virtual audio device, which we & # x27; ll use to record sound coming from practical mobile devices!

Android Emulator Setup

are a bit uncanny when it comes to audio. They set their system audio output channel when they reboot up for the first time, and at that pointonly. So they do not respect changes you make in the Sound preferences of your Mac. What this intend is that we want to get sure our audio setting are set up for internal audio capture via Soundflowerbeforewe establish our emulator. And not just before we launch it, but before itboots. This means that if you have an already-warm emulator, you & # x27; ll demand to completely shut it down, change sound preferences, and then perform a cold thrill on the emulator.

In add-on to the Soundflower choice delineate above, you & # x27; ll also want to go to the & quot; Sound Effects & quot; tab of the Sound preferences, and create sure that the output is set to mirror the system yield. That & # x27; s because some aper send all their sound through the Sound Effects channel, for some incomprehensible reason.

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

iOS Simulator Setup

Good intelligence -- -no extra setup is required for iOS!

ffmpeg Setup

To actually bewitch audio, we & # x27; re going to use a system library callffmpeg. ffmpeg doeslotsof stuff, but we only care about its ability to read from an audio gimmick and output an audio file. Our yield file is going to be a standard PCM WAV file, which will be great when it comes to doing the substantiation step later on. The easiest way to get ffmpeg on a Mac is via the Homebrew command brew install ffmpeg, but go ahead and read the ffmpeg docs to make sure it & # x27; s install fitly on your scheme. To quiz thing, out, run the command:

ffmpeg -f avfoundation -list_devices true -i `` ''

This command looks at the Apple audio device that are available and lists them out, with like IDs. This is the terminal part of the output I get on my machine:

[AVFoundation input device @ 0x7f9427501240] AVFoundation video devices: [AVFoundation input device @ 0x7f9427501240] [0] HD Pro Webcam C920 [AVFoundation input device @ 0x7f9427501240] [1] FaceTime HD Camera [AVFoundation input device @ 0x7f9427501240] [2] Capture screen 0 [AVFoundation input gimmick @ 0x7f9427501240] AVFoundation sound device: [AVFoundation input device @ 0x7f9427501240] [0] Built-in Microphone [AVFoundation input device @ 0x7f9427501240] [1] HD Pro Webcam C920 [AVFoundation input device @ 0x7f9427501240] [2] USB sound CODEC [AVFoundation input gimmick @ 0x7f9427501240] [3] Soundflower (64ch) [AVFoundation input device @ 0x7f9427501240] [4] Soundflower (2ch)

In our example, we don & # x27; t wish about video devices, only audio device. And the one I like about in particular is [4] Soundflower (2ch) (since I & # x27; m enter virtual gimmick audio -- -make modification according to your situation if you & # x27; re recording from an actual physical input). So I & # x27; ll need to remember that, from ffmpeg & # x27; s perspective, the Soundflower sound gimmick is turn 4. Now, wecoulduse ffmpeg from the command line to capture audio, but that doesn & # x27; t do us much good in the context of an machine-controlled trial. What we really want to do is phone ffmpeg from inside our trial code! So now let & # x27; s discuss how to integrate all of these thing within an to achieve audio seizure.

Capturing Audio in a Test

What we & # x27; re going ultimately going to test in this miniskirt serial is that the Amazon Music sampling audio clip for a vocal from my band & # x27; s old album actually sounds correct. In this edition, we & # x27; re just depart to work on charm a portion of the audio sample. Here are our test steps in bullet form:

  • Navigate tohttp: //splendourhyaline.com(my hastily-coded band page)
  • Click the initiatory link to buy the album on Amazon
  • Find the 2nd song in the song list, and tick the & quot; play & quot; push to start playing a sampling of it
  • At this point, become on ffmpeg to record audio from the Soundflower twist, which should be teem the audio from the Android imitator
  • Wait enough clip to capture a good amount of audio
  • Stop the ffmpeg recording
  • Verify that the ffmpeg recording in fact generated a WAV file

And then we & # x27; ll get a TODO for next time which will be all about comparing a captured WAV file with a aureate standard, to make sure the sound was what we expected. In this case, we & # x27; ll be capturing music, but we could be capturing text-to-speech, voice help output, or whatever & # x27; s appropriate for your app.

Test your mobile apps on real devices in 50+ locations worldwide..

Let & # x27; s first have a look at the standard Appium web automation code:

WebDriverWait wait = new WebDriverWait (driver, 10); // navigate to band homepage driver.get (`` http: //www.splendourhyaline.com ''); // click the amazon store icon for the first album WebElement storage = wait.until (ExpectedConditions.presenceOfElementLocated (By.cssSelector (`` img [src='/img/store-amazon.png '] ''))); driver.executeScript (`` window.scrollBy (0, 100); ''); store.click (); // start play a sample of the first lead WebElement play = wait.until (ExpectedConditions.presenceOfElementLocated (By.xpath (`` //div [@ data-track-number= ' 2 '] //div [@ data-action='dm-playable '] ''))); driver.executeScript (`` window.scrollBy (0, 150); ''); // start the song sample play.click ();

Basically all this codification just gets us to the point where we should really be hearing euphony acting. What we desire now is to start capturing sound to a file, and so assert that that file actually be when done. Here & # x27; s how we & # x27; re going to do this on a comparatively abstract point:

File audioCapture = new File (`` /Users/jlipps/Desktop/capture.wav ''); captureForDuration (audioCapture, 10000); assert (audioCapture.exists ());

In other words, I define a place on my system to capture the sound (of course you & # x27; ll want an appropriate path for your scheme), then I call a helper method captureForDuration, into which I legislate my coveted audio file way, and the amount of clip I want to beguile audio for (in this case 10 sec). After this, I simply do an assertion that the captured file exists. (In the next edition, we & # x27; ll update this to be a confirmation of the content of the audio file).

Check out:

How do we go about implement captureForDuration? Well, foremost of all we know that we & # x27; ll require to run ffmpeg as a sub-process. That means dealing with Threads, Runnables, and ProcessBuilder! (At least in Java -- -every language has its own specific way of dealing with subprocesses). What I & # x27; ve done, therefore, is to create an FFmpeg grade to encapsulate all these province:

form FFmpeg implements Runnable {private Process proc; private File captureFile; private int deviceId; FFmpeg (File captureFile, int deviceId) {this.proc = null; this.captureFile = captureFile; this.deviceId = deviceId;} public void run () {ArrayListcmd = new ArrayList < > (); cmd.add (`` ffmpeg ''); // binary should be on path cmd.add (`` -y ''); // always overwrite files cmd.add (`` -f ''); // arrange cmd.add (`` avfoundation ''); // apple 's system audio -- -something else for windows cmd.add (`` -i ''); // input cmd.add (``: '' + deviceId); // device id returned by ffmpeg list cmd.add (captureFile.getAbsolutePath ()); ProcessBuilder pb = new ProcessBuilder (cmd); pb.redirectErrorStream (true); pb.redirectOutput (Redirect.PIPE); StringJoiner out = new StringJoiner (`` \n ''); try {proc = pb.start (); try (BufferedReader reader = new BufferedReader (new InputStreamReader (proc.getInputStream ()))) {reader.lines () .forEach (out: :add);} proc.waitFor ();} haul (IOException | InterruptedException ign) {} System.out.println (`` FFMpeg yield was: `` + out.toString ());} public void stopCollection () throws IOException {BufferedWriter writer = new BufferedWriter (new OutputStreamWriter (proc.getOutputStream ())); writer.write (`` q ''); writer.flush (); writer.close ();}}

Explaining how this work in detail is beyond the orbit of our Appium usage. But basically what we & # x27; re doing is calling the ffmpeg binary (which we assume exists on the system and is available on the path) with the appropriate arguments to start an audio capture. What it would appear like if we were running it instantly on the command line (assuming a value of 4 for the deviceId -- -you & # x27; ll need to use whatever you saw in the previous command output):

ffmpeg -y -f avfoundation -i `` :4 '' /Users/jlipps/Desktop/capture.wav

So that is the command that we start utilise pb.start. This command would commonly run forever (or until we run out of disk space), so we need some way to state ffmpeg to stop recording. That & # x27; s the role of the stopCollection method, which we & # x27; ll call from outside the class. This method simply sends the letter & quot; q & quot; to the process, which (because of the way ffmpeg is design) stops recording and ends the process. We make certain to look for the process to end flawlessly (using proc.waitFor ()), and we evidence the output of the ffmpeg command in the console so if there were any errors we can have a face at them.

Also chit:

With this class in script, we & # x27; re ready to implement captureForDuration:

private nothingness captureForDuration (File audioCapture, int durationMs) throws Exception {FFmpeg seizure = new FFmpeg (audioCapture, 4); Thread t = new Thread (capture); t.start (); // waiting for sufficient amount of song to play Thread.sleep (durationMs); // recount ffmpeg to stop sampling capture.stopCollection (); // wait for ffmpeg yarn to end on its own t.join ();}

You can see here that we create an instance of our FFmpeg class, and so begin the subprocess in a new Thread. This allows the ffmpeg process to hoard audio data while we await for a predetermined sum of time. After that time has lapse, we name the stopCollection method to tell ffmpeg to stop collecting data, and then we wait for the subprocess to end before moving on (that & # x27; s the purpose of Thread.join).

Obviously, we could make our Thread logic and FFmpeg subprocess handling logic much more robust and safe. But for now, it serves the aim of showing how we can capture sound in our test for an arbitrary amount of time! Stay tuned for the next edition in which we discourse how to use this captured audio to do verifications about it, which is sort of the unhurt point! In the meantime, sense complimentary to check out thetotal code exampleon GitHub to see all of these part put together in a working context. Oh -- -and don & # x27; t forget to vary your scheme audio output back to whatever it was before you changed it to Soundflower! Otherwise you won & # x27; t be able to catch the audio of your preferred euphony with your own ears!

Author & # x27; s Profile

Jonathan Lipps

LinkedIn
Author & # x27; s Profile

Piali Mazumdar

Lead, Content Marketing, HeadSpin Inc.

Piali is a active and results-driven Content Marketing Specialist with 8+ geezerhood of experience in crafting engaging narratives and marketing collateral across diverse industries. She excels in collaborating with cross-functional team to acquire innovative substance strategies and deliver compelling, authentic, and impactful content that resonates with target audiences and enhances brand authenticity.

LinkedIn

Capturing Audio Output During Testing: Part 1

4 Parts

regression intelligence blog
-

Regression Intelligence virtual guide for advanced users (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence pragmatic guidebook for advanced users (Part 4)

Coming Soon

Discover how HeadSpin can empower your business with superior testing capabilities

Our Platform enable you to:
accelerate time-to-market
Accelerate time-to-market, gaining a private-enterprise edge
faster development cycles
Boost developer/QA productivity with faster development cycles
automated buil-over-build regression testing
Automate build-over-build regression examine for consistent termination
gain better visibility into functional & performance issues
Gain better profile into functional and performance issues
reduce mean time
Reduce mean time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and content quality of experience (QoE) effortlessly
The trusted alternative for global endeavor
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
Close

Discover how HeadSpin can empower your business with superior quiz capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productiveness with quicker growth cycles
automated buil-over-build regression testing
Automate build-over-build regression examine for consistent results
gain better visibility into functional & performance issues
Gain better profile into functional and performance matter
reduce mean time
Reduce hateful time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate sound, video, and content quality of experience (QoE) effortlessly
The sure choice for global enterprises
Close

Discover how HeadSpin can empower your line with superior quiz capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productivity with faster ontogenesis round
automated buil-over-build regression testing
Automate build-over-build regression testing for coherent results
gain better visibility into functional & performance issues
Gain better visibleness into functional and performance issue
reduce mean time
Reduce mean clip to identify/resolve during exam, QA, and production
evaluate audio, video & qoe
Evaluate sound, picture, and contented quality of experience (QoE) effortlessly
The sure choice for global enterprises
Close

Connet Now

Wipro LogoVMLYR Logo
Close
Book a Meeting
Products
footer down arrow
Solutions
footer down arrow
Industries
footer down arrow
Features
footer down arrow
Support
footer down arrow
Resource Center
footer down arrow
Why Choose HeadSpin?
footer down arrow
Copyright © 2026 HeadSpin, Inc. All Rights Reserved.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free