forked from Sunbird-ALL/all-learner-ai-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fc4e45
commit d589dbd
Showing
6 changed files
with
65 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
chrome.runtime.onInstalled.addListener(() => { | ||
console.log("Microphone Simulation Extension Installed"); | ||
console.log("My Microphone Simulator Extension Installed"); | ||
|
||
// Add other background tasks or listeners here if needed | ||
}); | ||
|
||
chrome.action.onClicked.addListener((tab) => { | ||
chrome.scripting.executeScript({ | ||
target: { tabId: tab.id }, | ||
files: ['content.js'] | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
function simulateMicrophoneInput(audioFilePath) { | ||
const context = new AudioContext(); | ||
fetch(audioFilePath) | ||
.then(response => response.arrayBuffer()) | ||
.then(arrayBuffer => context.decodeAudioData(arrayBuffer)) | ||
.then(audioBuffer => { | ||
const source = context.createBufferSource(); | ||
source.buffer = audioBuffer; | ||
source.connect(context.destination); | ||
source.start(); | ||
}) | ||
.catch(console.error); | ||
} | ||
console.log("My Microphone Simulator Content Script Loaded"); | ||
|
||
// Function to check if the microphone button is clicked | ||
function waitForMicButtonClick(selector) { | ||
document.querySelector(selector).addEventListener('click', function() { | ||
console.log("Microphone button clicked"); | ||
const audioFilePath = chrome.runtime.getURL("output_audio.wav"); | ||
simulateMicrophoneInput(audioFilePath); | ||
}); | ||
// Simulate microphone input | ||
function simulateMicrophoneInput(audioFile) { | ||
navigator.mediaDevices.getUserMedia = function(constraints) { | ||
return new Promise((resolve, reject) => { | ||
if (constraints.audio) { | ||
const audioContext = new AudioContext(); | ||
fetch(audioFile) | ||
.then(response => response.arrayBuffer()) | ||
.then(data => audioContext.decodeAudioData(data)) | ||
.then(buffer => { | ||
const source = audioContext.createBufferSource(); | ||
source.buffer = buffer; | ||
const destination = audioContext.createMediaStreamDestination(); | ||
source.connect(destination); | ||
source.start(); | ||
resolve(destination.stream); | ||
}) | ||
.catch(err => reject(err)); | ||
} else { | ||
reject(new Error("Only audio constraints are supported.")); | ||
} | ||
}); | ||
}; | ||
} | ||
|
||
// Start checking for the microphone button click | ||
waitForMicButtonClick('.MuiBox-root.css-1l4w6pd'); // Adjust the selector to match your microphone button | ||
// Use the function to simulate microphone input with your audio file | ||
simulateMicrophoneInput(chrome.runtime.getURL("output_audio.wav")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.