I'm using Selenium to emulate an user on a web that has audio chat. I need to emulate the user speaking through the microphone.
I only got questions about listening to the microphone in javascript, but none about sending sound through the microphone using javascript.
My current attempt looks like this:
First I check that AudioContext is available
private boolean isAudioContextSupported() {
JavascriptExecutor js = (JavascriptExecutor) getDriver();
Object response = js.executeAsyncScript(
"var callback = arguments[arguments.length - 1];" +
"var context;" +
"try {" +
" window.AudioContext = window.AudioContext||window.webkitAudioContext;" +
" context = new AudioContext();" +
" callback('');" +
"}" +
"catch(e) {" +
" callback('Web Audio API is not supported in this browser');" +
"}");
String responseAsString = response == null?"":(String)response;
return responseAsString.isEmpty();
}
Second I try to do this to get audio from an url
JavascriptExecutor js = (JavascriptExecutor) getDriver();
Object response = js.executeAsyncScript(
"var callback = arguments[arguments.length - 1];" +
"window.AudioContext = window.AudioContext || window.webkitAudioContext;" +
"var context = new AudioContext();" +
"var url = '<ogg file url>';" +
"var request = new XMLHttpRequest();" +
"request.open('GET', url, true);" +
"request.responseType = 'arraybuffer';" +
"request.onload = function() {" +
" context.decodeAudioData(request.response, function(buffer) {" +
" <send the buffer data through the microphone>" +
"}, callback(request.statusText));" +
"};" +
"request.send();" +
"callback('OK');"
);
The part I'm missing is how to send the buffer data (obtained from the ogg file) through the microphone.
EDIT:
The answer in Chrome: fake microphone input for test purpose does not answer this question, I already read that one.
EDIT 2:
There are some things to be considered:
1) The solution I'm looking can include using another language or tool.
2) I can't use hardware to emulate mic input (e.g.: output sound via speakers so the microphone can pick it up)