Upload audio files and simulate microphone
- This feature is currently a Private Beta service and available only under Desktop and Mobile Pro, and Enterprise Pro plans. For more details, check out our pricing page.
- Audio Injection supports only Android 11 and above, Windows 10 and above, and macOS devices.
BrowserStack Automate enables you to upload audio files to your test sessions to verify various use cases, such as testing web apps that require access to microphone and audio output, linking the microphone to your web app, testing the microphone recording feature, etc.
In this guide, you will learn how to:
- Supported OS and devices
- Upload your audio files
- Inject the Audio file using the Automate capability
Supported OS and browsers
Supported Platform | Versions and Browsers |
---|---|
Android | 11 and above |
Windows | 10 and above with Google Chrome and Edge only |
macOS | Google Chrome and Edge only |
Upload your audio files
Prior to starting the test execution, upload the audio files using media REST APIs.
curl -u "username:accesskey" -X POST "https://api-cloud.browserstack.com/automate/upload-media" -F "file=@/path/to/app/file/test.mp3"
- Maximum file size - 15 MB for Android, 2 MB for Windows and macOS.
- Allowed file formats for audio -
.mp3
and.wav
. - You can upload only one audio file at a time.
- Uploaded files will persist on the BrowserStack server only for 30 days.
The REST API returns a response media_url
for each successful file upload.
{
"media_url": "media://<hashedid>"
}
The media_url
received is used to refer the audio file in test script.
Inject the Audio file using the Automate capability
Use the following code snippet to upload audio files to your test sessions:
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
The following table provides information about the enableAudioInjection
capability:
Capability | Description |
---|---|
enableAudioInjection |
Set this capability to "true" if you want to use your audio files in the test. |
DesiredCapabilities capabilities = new DesiredCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
// Ensure to use Android version 11 or above. Passing an invalid version (below Android 11 or non-Android OS) drops the session.
browserstackOptions.put("osVersion", "12.0");
browserstackOptions.put("deviceName", "Samsung Galaxy S22");
browserstackOptions.put("enableAudioInjection", "true");
capabilities.setCapability("bstack:options", browserstackOptions);
var capabilities = {
'bstack:options' : {
// Ensure to use Android version 11 or above. Passing an invalid version (below Android 11 or non-Android OS) drops the session.
"osVersion" : "12.0",
"deviceName" : "Samsung Galaxy S22"
"enableAudioInjection" : "true"
}
}
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("enableAudioInjection", "true");
// Ensure to use Android version 11 or above. Passing an invalid version (below Android 11 or non-Android OS) drops the session.
browserstackOptions.Add("osVersion", "12.0");
browserstackOptions.Add("deviceName", "Samsung Galaxy S22");
capabilities.AddAdditionalOption("bstack:options", browserstackOptions);
desired_cap = {
'bstack:options' : {
# Ensure to use Android version 11 or above. Passing an invalid version (below Android 11 or non-Android OS) drops the session.
"osVersion" : "12.0",
"deviceName" : "Samsung Galaxy S22",
"enableAudioInjection" : "true",
},
}
capabilities = {
'bstack:options' => {
# Ensure to use Android version 11 or above. Passing an invalid version (below Android 11 or non-Android OS) drops the session.
"osVersion" => "12.0",
"deviceName" => "Samsung Galaxy S22",
"enableAudioInjection" => "true",
},
}
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
The following table provides information about the browserstack.enableAudioInjection
capability:
Capability | Description |
---|---|
browserstack.enableAudioInjection |
Set this capability to "true" if you want to use your audio files in the test. |
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("browserstack.enableAudioInjection","true");
// Ensure to use Android version 11 or above. Passing an invalid version (below Android 11 or non-Android OS) drops the session.
caps.setCapability("os_version", "12.0");
caps.setCapability("device", "Samsung Galaxy S22");
var capabilities = {
"browserstack.enableAudioInjection" : "true"
// Ensure to use Android version 11 or above. Passing an invalid version (below Android 11 or non-Android OS) drops the session.
"os_version" : "12.0",
"device" : "Samsung Galaxy S22",
}
ChromeOptions capability = new ChromeOptions();
capability.AddAdditionalCapability("browserstack.enableAudioInjection", "true");
// Ensure to use Android version 11 or above. Passing an invalid version (below Android 11 or non-Android OS) drops the session.
capability.AddAdditionalCapability("os_version", "12.0");
capability.AddAdditionalCapability("device", "Samsung Galaxy S22");
desired_cap = {
"browserstack.enableAudioInjection" = "true",
# Ensure to use Android version 11 or above. Passing an invalid version (below Android 11 or non-Android OS) drops the session.
"os_version" : "12.0",
"device" : "Samsung Galaxy S22",
}
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["browserstack.enableAudioInjection"] = "true"
# Ensure to use Android version 11 or above. Passing an invalid version (below Android 11 or non-Android OS) drops the session.
caps["os_version"] = "12.0"
caps["device"] = "Samsung Galaxy S22"
Add audio injection logic for Android
The uploaded audio file is played on the remote device using custom JavaScript Executors. Your test script must be modified to add these custom executors along with the logic to click the UI element that in the webapp that triggers the microphone and plays the audio in a specified order.
Ensure that the following order is maintained in your script:
- Add the inject audio executor statement
- Add framework logic to click a UI element
- Add the start audio executor statement
- Add the implicit wait to play complete audio
- Add the stop audio executor statement
Inject audio
Specify the audio file to play during the test using the following custom executor. Set the audioUrl
argument with the media_url
you received on successful upload of the audio file.
driver.execute_script('browserstack_executor: {\"action\":\"injectAudio\", \"arguments\": {\"audioUrl\" : \"media://<hashedid>\"}}')
Add framework command to click UI element
Your script must include the logic to handle any permission-related popups that might be encountered. Check out Handle pop-ups, permissions, and notifications for more information.
Start audio
After you click the UI element, the device starts listening for input. Use the startAudio
action to play the audio.
driver.execute_script('browserstack_executor: {\"action\":\"startAudio\"}')
Add the implicit wait to play complete audio
Ensure that you add the logic to add implicit waits in your script such that the stopAudio
action occurs only after the complete audio is played.
The default idle timeout for a session is 90 sec. The idle timeout can be extended to 5 minutes using these workarounds.
Stop audio
Use the stopAudio
action to stop the audio.
driver.execute_script("browserstack_executor: {\"action\":\"stopAudio\"}")
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
The following table provides information about the enableAudioInjection
capability:
Capability | Description |
---|---|
enableAudioInjection |
Set this capability to "true" if you want to use your audio files in the test. |
MutableCapabilities capabilities = new MutableCapabilities();
capabilities.setCapability("browserName", "Chrome");
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("os", "Windows");
browserstackOptions.put("osVersion", "10");
browserstackOptions.put("browserVersion", "110.0");
browserstackOptions.put("enableAudioInjection", "true");
browserstackOptions.put("audioInjectionURL", "media://575927ad18ae787c065e680dc3ee864725cd809e");
capabilities.setCapability("bstack:options", browserstackOptions);
// Input capabilities
var capabilities = {
'bstack:options' : {
"os" : "Windows",
"osVersion" : "10",
"projectName" : "Audio Injection",
"buildName" : "audio_test_1",
"userName" : "YOUR_USERNAME",
"accessKey" : "YOUR_ACCESS_KEY",
"enableAudioInjection": true,
"audioInjectionURL" : "media://575927ad18ae787c065e680dc3ee864725cd809e",
},
"browserName" : "Chrome",
"browserVersion" : "110.0",
}
// Your test logic
ChromeOptions capabilities = new ChromeOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("os", "Windows");
browserstackOptions.Add("osVersion", "10");
browserstackOptions.Add("browserVersion", "110.0");
browserstackOptions.Add("userName", "USERNAME");
browserstackOptions.Add("accessKey", "KEY");
browserstackOptions.Add("browserName", "Chrome");
browserstackOptions.Add("enableAudioInjection", "true");
browserstackOptions.Add("audioInjectionURL", "media://575927ad18ae787c065e680dc3ee864725cd809e");
capabilities.AddAdditionalOption("bstack:options", browserstackOptions);
desired_cap = {
'bstack:options' : {
"os" : "Windows",
"osVersion" : "10",
"browserVersion" : "110.0",
"projectName" : "Audio Injection",
"buildName" : "audio_test_1",
"userName" : "YOUR_USERNAME",
"accessKey" : "YOUR_ACCESS_KEY",
"enableAudioInjection" : true,
"audioInjectionURL" : "media://575927ad18ae787c065e680dc3ee864725cd809e",
},
"browserName" : "Chrome",
}
capabilities = {
'bstack:options' => {
"os" => "Windows",
"osVersion" => "10",
"browserVersion" => "110.0"
"projectName" => "Audio Injection",
"buildName" : "audio_test_1",
"userName" => "YOUR_USERNAME",
"accessKey" => "YOUR_ACCESS_KEY",
"enableAudioInjection"=> true,
"audioInjectionURL" => "media://575927ad18ae787c065e680dc3ee864725cd809e",
},
"browserName" => "Chrome",
}
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
The following table provides information about the browserstack.enableAudioInjection
capability:
Capability | Description |
---|---|
browserstack.enableAudioInjection |
Set this capability to "true" if you want to use your audio files in the test. |
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "10");
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "110.0");
caps.setCapability("browserstack.enableAudioInjection", "true");
caps.setCapability("browserstack.audioInjectionURL", "media://575927ad18ae787c065e680dc3ee864725cd809e");
var capabilities = {
"os" : "Windows",
"os_version" : "10",
"browserName" : "Chrome",
"browser_version" : "110.0",
"browserstack.enableAudioInjection" : "true",
"browserstack.audioInjectionURL" : "media://575927ad18ae787c065e680dc3ee864725cd809e",
"browserstack.user" : "USERNAME",
"browserstack.key" : "ACCESS_KEY"
}
ChromeOptions capability = new ChromeOptions();
capability.AddAdditionalCapability("os", "Windows", true);
capability.AddAdditionalCapability("os_version", "10", true);
capability.AddAdditionalCapability("browser", "Chrome", true);
capability.AddAdditionalCapability("browser_version", "110.0", true);
capability.AddAdditionalCapability("browserstack.user", "USERNAME");
capability.AddAdditionalCapability("browserstack.key", "ACCESS_KEY");
capability.AddAdditionalCapability("browserstack.enableAudioInjection","true")
capability.AddAdditionalCapability("browserstack.audioInjectionURL","media://575927ad18ae787c065e680dc3ee864725cd809e")
desired_cap = {
"os" : "Windows",
"os_version" : "10",
"browser" : "Chrome",
"browser_version" : "110.0",
"browserstack.enableAudioInjection" : "true",
"browserstack.audioInjectionURL" : "media://575927ad18ae787c065e680dc3ee864725cd809e",
}
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["os"] = "Windows"
caps["os_version"] = "10"
caps["browser"] = "Chrome"
caps["browser_version"] = "110.0"
caps["browserstack.enableAudioInjection"] = "true"
caps["browserstack.audioInjectionURL"] = "media://575927ad18ae787c065e680dc3ee864725cd809e"
Audio injection logic for Windows
The uploaded audio file is played manually on the remote device. Modify your test script to include steps to play audio in the web app UI, triggering the microphone and playing the audio in a specific order.
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
The following table provides information about the enableAudioInjection
capability:
Capability | Description |
---|---|
enableAudioInjection |
Set this capability to "true" if you want to use your audio files in the test. |
MutableCapabilities capabilities = new MutableCapabilities();
capabilities.setCapability("browserName", "Edge");
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("os", "OS X");
browserstackOptions.put("osVersion", "Monterey");
browserstackOptions.put("browserVersion", "110.0");
browserstackOptions.put("enableAudioInjection", "true");
browserstackOptions.put("audioInjectionURL", "media://575927ad18ae787c065e680dc3ee864725cd809e");
capabilities.setCapability("bstack:options", browserstackOptions);
// Input capabilities
var capabilities = {
'bstack:options' : {
"os" : "OS X",
"osVersion" : "Monterey",
"browserVersion" : "110.0",
"projectName" : "Audio Injection",
"buildName" : "audio_test_1",
"userName" : "YOUR_USERNAME",
"accessKey" : "YOUR_ACCESS_KEY",
"enableAudioInjection": true,
"audioInjectionURL" : "media://575927ad18ae787c065e680dc3ee864725cd809e",
},
"browserName" : "Edge",
}
// Your test logic
EdgeOptions capabilities = new EdgeOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("os", "OS X");
browserstackOptions.Add("osVersion", "Monterey");
browserstackOptions.Add("browserVersion", "110.0");
browserstackOptions.Add("userName", "USERNAME");
browserstackOptions.Add("accessKey", "KEY");
browserstackOptions.Add("browserName", "Edge");
browserstackOptions.Add("enableAudioInjection", "true");
browserstackOptions.Add("audioInjectionURL", "media://575927ad18ae787c065e680dc3ee864725cd809e");
capabilities.AddAdditionalOption("bstack:options", browserstackOptions);
desired_cap = {
'bstack:options' : {
"os" : "OS X",
"osVersion" : "Monterey",
"browserVersion" : "110.0",
"projectName" : "Audio Injection",
"buildName" : "audio_test_1",
"userName" : "YOUR_USERNAME",
"accessKey" : "YOUR_ACCESS_KEY",
"enableAudioInjection" : true,
"audioInjectionURL" : "media://575927ad18ae787c065e680dc3ee864725cd809e",
},
"browserName" : "Edge",
}
capabilities = {
'bstack:options' => {
"os" => "OS X",
"osVersion" => "Monterey",
"browserVersion" => "110.0",
"projectName" => "Audio Injection",
"buildName" : "audio_test_1",
"userName" => "YOUR_USERNAME",
"accessKey" => "YOUR_ACCESS_KEY",
"enableAudioInjection"=> true,
"audioInjectionURL" => "media://575927ad18ae787c065e680dc3ee864725cd809e",
},
"browserName" => "Edge",
}
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
The following table provides information about the browserstack.enableAudioInjection
capability:
Capability | Description |
---|---|
browserstack.enableAudioInjection |
Set this capability to "true" if you want to use your audio files in the test. |
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("os", "OS X");
caps.setCapability("os_version", "Monterey");
caps.setCapability("browser", "Edge");
caps.setCapability("browser_version", "108.0");
caps.setCapability("browserstack.enableAudioInjection", "true");
caps.setCapability("browserstack.audioInjectionURL", "media://575927ad18ae787c065e680dc3ee864725cd809e");
var capabilities = {
"os" : "OS X",
"os_version" : "Monterey",
"browserName" : "Edge",
"browser_version" : "108.0",
"browserstack.enableAudioInjection" : "true",
"browserstack.audioInjectionURL" : "media://575927ad18ae787c065e680dc3ee864725cd809e",
"browserstack.user" : "USERNAME",
"browserstack.key" : "ACCESS_KEY"
}
EdgeOptions capability = new EdgeOptions();
capability.AddAdditionalCapability("os", "OS X");
capability.AddAdditionalCapability("os_version", "Monterey");
capability.AddAdditionalCapability("browser", "Edge");
capability.AddAdditionalCapability("browser_version", "108.0");
capability.AddAdditionalCapability("browserstack.user", "USERNAME");
capability.AddAdditionalCapability("browserstack.key", "ACCESS_KEY");
capability.AddAdditionalCapability("browserstack.enableAudioInjection","true")
capability.AddAdditionalCapability("browserstack.audioInjectionURL","media://575927ad18ae787c065e680dc3ee864725cd809e")
desired_cap = {
"os" : "OS X",
"os_version" : "Monterey",
"browser" : "Edge",
"browser_version" : "108.0",
"browserstack.enableAudioInjection" : "true",
"browserstack.audioInjectionURL" : "media://575927ad18ae787c065e680dc3ee864725cd809e",
}
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["os"] = "OS X"
caps["os_version"] = "Monterey"
caps["browser"] = "Edge"
caps["browser_version"] = "108.0"
caps["browserstack.enableAudioInjection"] = "true"
caps["browserstack.audioInjectionURL"] = "media://575927ad18ae787c065e680dc3ee864725cd809e"
Audio injection logic for macOS
The uploaded audio file is played manually on the remote device. Modify your test script to include steps to play audio in the web app UI, triggering the microphone and playing the audio in a specific order.
Related topics
Check this page for a list of various JavaScript Executors that BrowserStack offers.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!