-2

I'm trying to create an extension that can launch sounds through the microphone, mp3 sounds.

For example I want that a user enters a google meet call or any other service and that by pressing a button in the** popup.html** a sound is triggered that all the people in the conversation can hear.

GiR
  • 9
  • 3
  • It seems that what they said about some stackoverflow users is true, don't worry, don't come back to this post, thanks. – GiR Jul 08 '23 at 15:59
  • 1
    Hi. Welcome to SO. You haven't asked a question. Code that you have worked on to solve the problem be included in your question as a [mcve]. You can use the snippet tool `[<>]` in the question edit toolbar to help you. You might find reading the site [help section](https://stackoverflow.com/help) useful when it comes to [asking a good question](https://stackoverflow.com/help/how-to-ask), and this [question checklist](https://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist). – Andy Jul 08 '23 at 16:00
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Ali Bahrami Jul 09 '23 at 08:15

1 Answers1

0

Use software to redirect sound from speakers to microphone on your sound card (there are many apps) or you can create your own with c#

to play sound from the chrome extension use offscreen

manifest.json

"permissions": ["offscreen"]

background.js

/**
 * Plays audio files from extension service workers
 * @param {string} source - path of the audio file
 * @param {number} volume - volume of the playback
 */
async function playSound(source = 'default.wav', volume = 1) {
    await createOffscreen();
    await chrome.runtime.sendMessage({ play: { source, volume } });
}

// Create the offscreen document if it doesn't already exist
async function createOffscreen() {
    if (await chrome.offscreen.hasDocument()) return;
    await chrome.offscreen.createDocument({
        url: 'offscreen.html',
        reasons: ['AUDIO_PLAYBACK'],
        justification: 'testing' // details for using the API
    });
}

offscreen.html

<script src="offscreen.js"></script>
offscreen.js

// Listen for messages from the extension
chrome.runtime.onMessage.addListener(msg => {
    if ('play' in msg) playAudio(msg.play);
});

// Play sound with access to DOM APIs
function playAudio({ source, volume }) {
    const audio = new Audio(source);
    audio.volume = volume;
    audio.play();
}
Christa
  • 398
  • 7