Capturing Audio Output During Testing: Part 1
HeadSpin & # x27; s custom Bluetooth board and analysis API allows testing vocalisation supporter, validating streaming medium, and working with phonation outcry on real devices. 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. 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. 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. 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. 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! 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. Good intelligence -- -no extra setup is required for iOS! 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: 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: 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. 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: 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. Let & # x27; s first have a look at the standard Appium web automation code: 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: 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). 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: 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): 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. With this class in script, we & # x27; re ready to implement captureForDuration: 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! 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. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts..png)



Capturing Audio Output During Testing: Part 1
AI-Powered Key Takeaways

HeadSpin ’ s AV solution enables testing by capturing the user experience of real media devices, include genuine screen and audio yield..
Capturing audio from a real device
Emulators & amp; Android Simulators.
Capturing audio from a virtual device
Soundflower Setup
Android Emulator Setup
iOS Simulator Setup
ffmpeg Setup
ffmpeg -f avfoundation -list_devices true -i `` ''[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)Capturing Audio in a Test
Test your mobile apps on real devices in 50+ locations worldwide..
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 ();File audioCapture = new File (`` /Users/jlipps/Desktop/capture.wav ''); captureForDuration (audioCapture, 10000); assert (audioCapture.exists ());Check out:
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 () {ArrayListffmpeg -y -f avfoundation -i `` :4 '' /Users/jlipps/Desktop/capture.wavAlso chit:
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 ();}Piali Mazumdar
Capturing Audio Output During Testing: Part 1
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence virtual guide for advanced users (Part 3)
-1280X720-Final-2.jpg)
Regression Intelligence pragmatic guidebook for advanced users (Part 4)
Discover how HeadSpin can empower your business with superior testing capabilities







Discover how HeadSpin can empower your business with superior quiz capabilities
Discover how HeadSpin can empower your line with superior quiz capabilities
Connet Now


Automate This With SUSA
Test Your App Autonomously







.png)












