|
| 1 | +--- |
| 2 | +id: audio-injection |
| 3 | +title: Audio Injection on iOS Real Devices |
| 4 | +sidebar_label: Audio Injection |
| 5 | +description: Inject audio content in your tests with LambdaTest to simulate microphone inputs for automated testing, enhancing your app's audio capabilities. |
| 6 | + |
| 7 | +keywords: |
| 8 | + - audio injection |
| 9 | + - app test automation |
| 10 | + - microphone input |
| 11 | + - voice commands |
| 12 | + - audio recording |
| 13 | + - lambdatest audio testing |
| 14 | + - framework on lambdatest |
| 15 | + - app testing appium |
| 16 | + - app testing |
| 17 | + - real devices |
| 18 | +url: https://www.lambdatest.com/support/docs/audio-injection/ |
| 19 | +site_name: LambdaTest |
| 20 | +slug: audio-injection/ |
| 21 | +--- |
| 22 | + |
| 23 | +import CodeBlock from '@theme/CodeBlock'; |
| 24 | +import {YOUR_LAMBDATEST_USERNAME, YOUR_LAMBDATEST_ACCESS_KEY} from "@site/src/component/keys"; |
| 25 | + |
| 26 | +import Tabs from '@theme/Tabs'; |
| 27 | +import TabItem from '@theme/TabItem'; |
| 28 | + |
| 29 | +<script type="application/ld+json" |
| 30 | + dangerouslySetInnerHTML={{ __html: JSON.stringify({ |
| 31 | + "@context": "https://schema.org", |
| 32 | + "@type": "BreadcrumbList", |
| 33 | + "itemListElement": [{ |
| 34 | + "@type": "ListItem", |
| 35 | + "position": 1, |
| 36 | + "name": "Home", |
| 37 | + "item": "https://www.lambdatest.com" |
| 38 | + },{ |
| 39 | + "@type": "ListItem", |
| 40 | + "position": 2, |
| 41 | + "name": "Support", |
| 42 | + "item": "https://www.lambdatest.com/support/docs/" |
| 43 | + },{ |
| 44 | + "@type": "ListItem", |
| 45 | + "position": 3, |
| 46 | + "name": "Audio Injection", |
| 47 | + "item": "https://www.lambdatest.com/support/docs/audio-injection/" |
| 48 | + }] |
| 49 | + }) |
| 50 | + }} |
| 51 | +></script> |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +# Audio Injection on iOS Real Devices |
| 56 | + |
| 57 | +Audio Injection allows you to inject microphone input on real iOS devices in the LambdaTest Real Device Cloud. |
| 58 | +Use it to test audio-driven flows such as audio verification and in-app recording—without manual mic input. |
| 59 | + |
| 60 | +## Key Use Cases |
| 61 | +- In-app audio recording |
| 62 | +- Audio-based verification/KYC flows |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +> This feature is currently in Beta. We are actively refining it based on real-world usage and feedback. |
| 67 | +--- |
| 68 | +## Supported APIs & Devices |
| 69 | +- **API:** [AVAudioRecorder](https://developer.apple.com/documentation/avfaudio/avaudiorecorder) |
| 70 | +- **Supported Devices:** iOS **14 and above** |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## Step 1: Upload Audio File |
| 75 | +**Supported formats:** `.mp3`, `.wav` |
| 76 | +**Max size:** 15 MB , 100 MB respectively |
| 77 | + |
| 78 | +```bash |
| 79 | +curl -u "LT_USERNAME:LT_ACCESS_KEY" -X POST "https://api.lambdatest.com/mfs/v1.0/media/upload" -F "media_file=@/path/to/test.wav" -F "type=audio" -F "custom_id=SampleAudio" |
| 80 | +``` |
| 81 | + |
| 82 | +**Response** |
| 83 | +```json |
| 84 | +{ |
| 85 | + "media_url": "lt://MEDIAID", |
| 86 | + "status": "success" |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## Step 2: Enable Audio Injection via Capabilities |
| 93 | + |
| 94 | +`media` can be set here or injected later in the test. |
| 95 | + |
| 96 | +**Python** |
| 97 | +```python |
| 98 | +desired_caps = { |
| 99 | + "enableAudioInjection": True, |
| 100 | + "media": "lt://MEDIA123456789" # optional |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +## Step 3: Control Audio in Test |
| 107 | +Inject the uploaded audio file from LambdaTest into the recorder or app when you are at the dedicated space for microphone input. |
| 108 | + |
| 109 | +**Inject / Replace File** |
| 110 | +```python |
| 111 | +driver.execute_script('lambda-audio: {"action":"inject","arguments":{"media_url":"lt://MEDIA123..."}}') |
| 112 | +``` |
| 113 | + |
| 114 | +**Start Audio** |
| 115 | +```python |
| 116 | +driver.execute_script('lambda-audio: {"action":"start"}') |
| 117 | +``` |
| 118 | + |
| 119 | +**Stop Audio** |
| 120 | +```python |
| 121 | +driver.execute_script('lambda-audio: {"action":"stop"}') |
| 122 | +``` |
| 123 | +:::note |
| 124 | +The injected audio can come from a standalone audio file **or** from the audio track of a recorded video. |
| 125 | +::: |
| 126 | +--- |
0 commit comments