using Puppeteersharp to implement fake-audio-capture to use an audio file as my microphone input

186 Views Asked by At

I want to use Puppeteersharp to implement --fake-audio-capture to use an audio file as my microphone input.

I want it to get that audio file(locally saved) as input whenever the microphone it activated, it gets input from that audio file.

I am using Chrome and PuppeteerSharp, and I am willing to downgrade to a different version of chromium or Puppeteersharp.

I tried it using my following code, none of the posts on stackoverflow answered it correctly:

using System;
using System.IO;
using System.Threading.Tasks;
using PuppeteerSharp;

namespace PuppeteerProgram
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var launchOptions = new LaunchOptions
            {
                ExecutablePath = @"C:\Program Files\Google\Chrome\Application\chrome.exe",
                Args = new[] {
                    "--use-fake-ui-for-media-stream",
                    "--use-fake-device-for-media-stream",
                    "--use-file-for-fake-audio-capture='V:\\puppeteerprogram\\voice.wav'",
                    "--allow-file-access",
                    "--mute-audio"
                }
            };

            var browserWSEndpoint = "ws://localhost:9223/devtools/browser/f8564ed5-23e5-4bea-a058-c646b56c575f";
            var options = new ConnectOptions
            {
                BrowserWSEndpoint = browserWSEndpoint
            };

            var browser = await Puppeteer.LaunchAsync(launchOptions);

            var pages = await browser.PagesAsync();
            var page = pages[0];

            Console.WriteLine("Clicking on microphone button...");
            await page.ClickAsync("div.record-btn"); // clicking record btn on some website

            Console.WriteLine("Stop Recording...");
            await page.ClickAsync("div.record-btn"); // clicking record btn again to stop recording

            Console.WriteLine("Voice recorded successfully.");

            Console.WriteLine("Waiting for 10 seconds...");
            await Task.Delay(10000);

            //await browser.CloseAsync(); // commented since I don't want the browser to close
        }
    }
}

Any help will be appreciated. Thanks

0

There are 0 best solutions below