tencent cloud

Feedback

Electron

Last updated: 2023-09-28 11:45:46

    Pain Points and Solutions

    It is often necessary to share system audio in scenarios such as screen sharing, but the sound cards of Mac computers do not allow the capturing of system audio when the application is packaged by Electron, making it impossible to share system audio on Mac computers. To solve this problem, TRTC has introduced a feature that records system audio on Mac computers. See below for details on how to enable the feature.
    

    Step 1. Start capturing system audio

    Call the startSystemAudioLoopback API to start system audio capturing and mix the audio into the upstream audio stream. The result is called back via onSystemAudioLoopbackError.
    import TRTCCloud, { TRTCAudioQuality } from 'trtc-electron-sdk';
    const rtcCloud = new TRTCCloud();
    function onSystemAudioLoopbackError(errCode) {
    if (errCode === 0) {
    console.log('Started successfully');
    }
    if (errCode === -1330) {
    console.log('Failed to enable system sound recording; for example, the audio driver plugin was unavailable');
    }
    if (errCode === -1331) {
    console.log('No permission to install the audio driver plugin');
    }
    if (errCode === -1332) {
    console.log('Failed to install the audio driver plugin');
    }
    }
    
    trtcCloud.on('onSystemAudioLoopbackError', onSystemAudioLoopbackError);
    trtcCloud.startLocalAudio(TRTCAudioQuality.TRTCAudioQualityDefault);
    trtcCloud.startSystemAudioLoopback();
    
    
    notice
    When you call startSystemAudioLoopback for the first time, the SDK will request root access. After being granted root access, the SDK will start installing the virtual sound card plugin to the computer automatically.
    

    Step 2. Stop capturing system audio

    Call the stopSystemAudioLoopback API to stop system audio capturing.
    trtcCloud.stopSystemAudioLoopback();
    

    Step 3. Set the volume of system audio capturing

    Call the setSystemAudioLoopbackVolume API to set the volume of system audio capturing.
    trtcCloud.setSystemAudioLoopbackVolume(60);

    Summary

    TRTC records system audio on Mac computers using the virtual sound card plugin TRTCAudioPlugin.driver. For the plugin to work, you need to copy it to the system directory /Library/Audio/Plug-Ins/HAL and restart the audio service. You can check whether the plug is installed successfully using the Audio MIDI Setup app, which can be found in the Other folder of Launchpad. The presence of a device named "TRTC Audio Device" in the device list of the app indicates that the plugin is installed successfully.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support