Node.js desktopCapturer-如何证明音频通过?

Node.js desktopCapturer-如何证明音频通过?,node.js,electron,desktopcapturer,Node.js,Electron,Desktopcapturer,我有以下代码试图从windows桌面上运行的特定应用程序捕获音频/视频: <!DOCTYPE html> <html> <head> <meta charset = "UTF-8"> <title>Audio and Video</title> </head> <body> <video autoplay>&

我有以下代码试图从windows桌面上运行的特定应用程序捕获音频/视频:

<!DOCTYPE html>
<html>
   <head>
      <meta charset = "UTF-8">
      <title>Audio and Video</title>
   </head>
   
   <body>
      <video autoplay></video>
      <script type = "text/javascript">
         var desktopCapturer = require('electron').desktopCapturer;
         console.log("are you here?")
         console.log(desktopCapturer)

         desktopCapturer.getSources({ types: ['window', 'screen'] }).then(async sources => {
            for (const source of sources) {
               if (source.name === 'MyStreamingApp') {
                  try {
                  const stream = await navigator.mediaDevices.getUserMedia({
                     audio: {
                        mandatory: {
                        chromeMediaSource: 'desktop',
                        chromeMediaSourceId: source.id,
                        }
                     },
                     video: {
                        mandatory: {
                        chromeMediaSource: 'desktop',
                        chromeMediaSourceId: source.id,
                        minWidth: 1280,
                        maxWidth: 1280,
                        minHeight: 720,
                        maxHeight: 720
                        }
                     }
                  })
                  handleStream(stream)
                  } catch (e) {
                  handleError(e)
                  }
                  return
               }
            }
            })

            function handleStream (stream) {
            const video = document.querySelector('video')
            video.srcObject = stream
            video.onloadedmetadata = (e) => video.play()
            }

            function handleError (e) {
            console.log(e)
            }
      </script>
   </body>
</html>
现在。。。当我启动electron应用程序并启动av应用程序时,electron应用程序会发送切碎的音频。它被弄坏了,我什么都看不出来。。。 同时,我仍然可以听到来自源应用程序的音频。所以我想我已经证明了它捕捉到了一些音频。。。但它太糟糕了,无法使用

根据文档中的注释,事实上它说在流式传输音频时不要指定sourceID,我猜您可以使用electron as从特定的windows应用程序获取音频。您只能请求整个桌面音频。但如果有经验丰富的人能证实这一点,那就太好了

谢谢

              const stream = await navigator.mediaDevices.getUserMedia({
                 audio: {
                    mandatory: {
                    chromeMediaSource: 'desktop',
                    //when capturing audio, need to remove the sourceid constraint.
                    //chromeMediaSourceId: source.id,
                    }
                 },
                 video: {
                    mandatory: {
                    chromeMediaSource: 'desktop',
                    chromeMediaSourceId: source.id,
                    minWidth: 1280,
                    maxWidth: 1280,
                    minHeight: 720,
                    maxHeight: 720
                    }
                 }
              })