trtc-electron-sdk 11.4.502-beta.0 → 11.4.502-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/liteav/trtc.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
3
  import { VodPlayer } from './vod_player';
4
- import { AudioMusicParam, Rect, TRTCAppScene, TRTCAudioEffectParam, TRTCAudioQuality, TRTCBeautyStyle, TRTCDeviceState, TRTCDeviceType, TRTCLogLevel, TRTCRenderParams, TRTCRoleType, TRTCSwitchRoomParam, TRTCVideoBufferType, TRTCVideoFillMode, TRTCVideoPixelFormat, TRTCVideoRotation, TRTCVideoStreamType, TRTCWaterMarkSrcType, PluginInfo, TRTCAudioRecordingParams, TRTCScreenCaptureSourceInfo, TRTCScreenCaptureProperty, TRTCSpeedTestParams, TRTCRecordType, TRTCDeviceInfo, TRTCCameraCaptureParams, TRTCImageBuffer, TRTCInitConfig, TRTCAudioParallelParams } from './trtc_define';
4
+ import { AudioMusicParam, Rect, TRTCAppScene, TRTCAudioEffectParam, TRTCAudioQuality, TRTCBeautyStyle, TRTCDeviceState, TRTCDeviceType, TRTCLogLevel, TRTCRenderParams, TRTCRoleType, TRTCSwitchRoomParam, TRTCVideoBufferType, TRTCVideoFillMode, TRTCAudioFrame, TRTCVideoPixelFormat, TRTCVideoRotation, TRTCVideoStreamType, TRTCWaterMarkSrcType, PluginInfo, TRTCAudioRecordingParams, TRTCScreenCaptureSourceInfo, TRTCScreenCaptureProperty, TRTCSpeedTestParams, TRTCRecordType, TRTCDeviceInfo, TRTCCameraCaptureParams, TRTCImageBuffer, TRTCInitConfig, TRTCAudioParallelParams } from './trtc_define';
5
5
  export * from './trtc_define';
6
6
  export * from './trtc_code';
7
7
  export * from './vod_player';
@@ -12,7 +12,7 @@ export * from './vod_player';
12
12
  * @example
13
13
  * // 创建/使用/销毁 TRTCCloud 对象的示例代码:
14
14
  * import TRTCCloud from 'trtc-electron-sdk';
15
- * this.rtcCloud = new TRTCCloud();
15
+ * this.rtcCloud = TRTCCloud.getTRTCShareInstance();
16
16
  * // 获取 SDK 版本号
17
17
  * let version = this.rtcCloud.getSDKVersion();
18
18
  *
@@ -66,7 +66,7 @@ declare class TRTCCloud extends EventEmitter {
66
66
  * @example
67
67
  * // Enable 'debug' mode
68
68
  * const TRTCCloud = require('trtc-electron-sdk');
69
- * const rtcCloud = new TRTCCloud();
69
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
70
70
  * rtcCloud.getConfigObject().setDebugMode(true);
71
71
  *
72
72
  * @returns {TRTCConfig}
@@ -84,7 +84,7 @@ declare class TRTCCloud extends EventEmitter {
84
84
  * @example
85
85
  * // 创建/使用/销毁 TRTCCloud 对象的示例代码:
86
86
  * import TRTCCloud from 'trtc-electron-sdk';
87
- * this.rtcCloud = new TRTCCloud();
87
+ * this.rtcCloud = TRTCCloud.getTRTCShareInstance();
88
88
  *
89
89
  * // 注册回调的方法,事件关键字详见下方"通用事件回调"
90
90
  * subscribeEvents = (rtcCloud) => {
@@ -1618,7 +1618,7 @@ declare class TRTCCloud extends EventEmitter {
1618
1618
  * TRTCScreenCaptureProperty
1619
1619
  * } from 'trtc-electron-sdk';
1620
1620
  *
1621
- * const rtcCloud = new TRTCCloud();
1621
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
1622
1622
  *
1623
1623
  * const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
1624
1624
  *
@@ -1645,7 +1645,7 @@ declare class TRTCCloud extends EventEmitter {
1645
1645
  * // 示例2: 选择要分享的窗口或屏幕,9.3 及之前版本只能使用此方式
1646
1646
  * import TRTCCloud, { Rect } from 'trtc-electron-sdk';
1647
1647
  *
1648
- * const rtcCloud = new TRTCCloud();
1648
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
1649
1649
  *
1650
1650
  * const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
1651
1651
  *
@@ -1683,7 +1683,7 @@ declare class TRTCCloud extends EventEmitter {
1683
1683
  * TRTCVideoResolutionMode
1684
1684
  * } from 'trtc-electron-sdk';
1685
1685
  *
1686
- * const rtcCloud = new TRTCCloud();
1686
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
1687
1687
  *
1688
1688
  * const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
1689
1689
  *
@@ -1785,6 +1785,112 @@ declare class TRTCCloud extends EventEmitter {
1785
1785
  * @note 该方法只有在 TRTCScreenCaptureSourceInfo 中的 type 指定为 TRTCScreenCaptureSourceTypeScreen 时生效,即分享屏幕时生效
1786
1786
  */
1787
1787
  removeAllExcludedShareWindow(): void;
1788
+ /**
1789
+ * 将指定窗口加入屏幕分享的包含列表中(该接口仅支持桌面系统)
1790
+ *
1791
+ * @param {String} win - 希望被分享出去的窗口(Windows 平台下为窗口句柄: HWND)
1792
+ * - 该方法只有在 TRTCScreenCaptureSourceInfo 中的 type 指定为 TRTCScreenCaptureSourceTypeWindow 时生效,即分享窗口内容时,额外包含指定窗口的功能才生效。
1793
+ * - 您在 startScreenCapture 之前和之后调用均可。
1794
+ * - 通过该方法添加到包含列表中的窗口,会在退出房间后被 SDK 自动清除。
1795
+ */
1796
+ addIncludedShareWindow(win: string): void;
1797
+ /**
1798
+ * 将指定窗口从屏幕分享的包含列表中移除(该接口仅支持桌面系统)
1799
+ *
1800
+ * @param {String} win - 希望被分享出去的窗口(Mac 平台: 窗口 ID;Windows 平台: HWND)
1801
+ * - 该方法只有在 TRTCScreenCaptureSourceInfo 中的 type 指定为 TRTCScreenCaptureSourceTypeWindow 时生效,即分享窗口内容时,额外包含指定窗口的功能才生效。
1802
+ */
1803
+ removeIncludedShareWindow(win: string): void;
1804
+ /**
1805
+ * 将全部窗口从屏幕分享的包含列表中移除(该接口仅支持桌面系统)
1806
+ *
1807
+ * @note 该方法只有在 TRTCScreenCaptureSourceInfo 中的 type 指定为 TRTCScreenCaptureSourceTypeWindow 时生效,即分享窗口内容时,额外包含指定窗口的功能才生效。
1808
+ */
1809
+ removeAllIncludedShareWindow(): void;
1810
+ /**
1811
+ * 启用音频自定义采集模式
1812
+ *
1813
+ * 开启该模式后,SDK 不在运行原有的音频采集流程,即不再继续从麦克风采集音频数据,而是只保留音频编码和发送能力。
1814
+ * 您需要通过 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 不断地向 SDK 塞入自己采集的音频数据。
1815
+ *
1816
+ * 注意:
1817
+ * - 音频自定义采集与 SDK 默认的麦克疯音频采集互斥。因此,调用 `enableCustomAudioCapture(true)` 开启音频自定义采集前,需要先调用 [stopLocalAudio]{@link TRTCCloud#stopLocalAudio} 接口关闭默认的麦克风音频上行,否则不生效;调用 `enableCustomAudioCapture(false)` 关闭自定义采集后,要调用 [startLocalAudio]{@link TRTCCloud#startLocalAudio} 接口才能开启 SDK 默认的麦克风音频采集。
1818
+ * - 由于回声抵消(AEC)需要严格的控制声音采集和播放的时间,所以开启自定义音频采集后,AEC 能力可能会失效。
1819
+ *
1820
+ * @param {Boolean} enable - 是否启用,默认值:false。
1821
+ */
1822
+ enableCustomAudioCapture(enable: boolean): void;
1823
+ /**
1824
+ * 向 SDK 投送自己采集的音频数据
1825
+ *
1826
+ * 参数 {@link TRTCAudioFrame} 推荐下列填写方式(其他字段不需要填写):
1827
+ * - audioFormat:音频数据格式,仅支持 TRTCAudioFrameFormatPCM。
1828
+ * - data:音频帧 buffer。音频帧数据只支持 PCM 格式,支持[5ms ~ 100ms]帧长,推荐使用 20ms 帧长,长度计算方法:【48000采样率、单声道的帧长度:48000 × 0.02s × 1 × 16bit = 15360bit = 1920字节】。
1829
+ * - sampleRate:采样率,支持:16000、24000、32000、44100、48000。
1830
+ * - channel:声道数(如果是立体声,数据是交叉的),单声道:1; 双声道:2。
1831
+ * - timestamp:时间戳,单位为毫秒(ms),请使用音频帧在采集时被记录下来的时间戳(可以在采集到一帧音频帧之后,通过调用 [generateCustomPTS]{@link TRTCCloud#generateCustomPTS} 获取时间戳)。
1832
+ *
1833
+ * 注意:请您精准地按每帧时长的间隔调用本接口,数据投送间隔不均匀时极易触发声音卡顿。
1834
+ *
1835
+ * @param {TRTCAudioFrame} frame - 音频数据
1836
+ */
1837
+ sendCustomAudioData(frame: TRTCAudioFrame): void;
1838
+ /**
1839
+ * 启用/关闭自定义音轨
1840
+ *
1841
+ * 开启后,您可以通过本接口向 SDK 混入一条自定义的音轨。通过两个布尔型参数,您可以控制该音轨是否要在远端和本地播放。
1842
+ *
1843
+ * 注意: 如果您指定参数 enablePublish 和 enablePlayout 均为 false,代表完全关闭您的自定义音轨。
1844
+ * @param {Boolean} enablePublish - 控制混入的音轨是否要在远端播放,默认值:false。
1845
+ * @param {Boolean} enablePlayout - 控制混入的音轨是否要在本地播放,默认值:false。
1846
+ *
1847
+ */
1848
+ enableMixExternalAudioFrame(enablePublish: boolean, enablePlayout: boolean): void;
1849
+ /**
1850
+ * 向 SDK 混入自定义音轨
1851
+ *
1852
+ * * 调用该接口之前,您需要先通过 [enableMixExternalAudioFrame]{@link TRTCCloud#enableMixExternalAudioFrame} 开启自定义音轨,之后就可以通过本接口将自己的音轨以 PCM 格式混入到 SDK 中。
1853
+ * 理想情况下,我们期望您的代码能够以非常均匀的速度向 SDK 提供音轨数据。但我们也非常清楚,完美的调用间隔是一个巨大的挑战。
1854
+ * 所以 SDK 内部会开启一个音轨数据的缓冲区,该缓冲区的作用类似一个“蓄水池”,它能够暂存您传入的音轨数据,平抑由于接口调用间隔的抖动问题。
1855
+ * 本接口的返回值代表这个音轨缓冲区的大小,单位是毫秒(ms),比如:如果该接口返回 50,则代表当前的音轨缓冲区有 50ms 的音轨数据。因此只要您在 50ms 内再次调用本接口,SDK 就能保证您混入的音轨数据是连续的。
1856
+ * 当您调用该接口后,如果发现返回值 > 100ms,则可以等待一帧音频帧的播放时间之后再次调用;如果返回值 < 100ms,则代表缓冲区比较小,您可以再次混入一些音轨数据以确保音轨缓冲区的大小维持在“安全水位”以上。
1857
+ * 参数 {@link TRTCAudioFrame} 推荐下列填写方式(其他字段不需要填写):
1858
+ * - data:音频帧 buffer。音频帧数据只支持 PCM 格式,支持[5ms ~ 100ms]帧长,推荐使用 20ms 帧长,长度计算方法:【48000采样率、单声道的帧长度:48000 × 0.02s × 1 × 16bit = 15360bit = 1920字节】。
1859
+ * - sampleRate:采样率,支持:16000、24000、32000、44100、48000。
1860
+ * - channel:声道数(如果是立体声,数据是交叉的),单声道:1; 双声道:2。
1861
+ * - timestamp:时间戳,单位为毫秒(ms),请使用音频帧在采集时被记录下来的时间戳(可以在获得一帧音频帧之后,通过调用 [generateCustomPTS]{@link TRTCCloud#generateCustomPTS} 获得时间戳)。
1862
+ *
1863
+ * 注意:
1864
+ * - 混入自定义音轨,需要有上行音频流驱动,支持的上行音频流包括:
1865
+ * - SDK 默认采集的麦克风音频流,调用 [startLocalAudio]{@link TRTCCloud#startLocalAudio} 接口开启。
1866
+ * - 开启了自定义音频流,并有自定义音频数据上行,分别调用 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 和 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 接口。
1867
+ * - 开启了背景音乐,调用接口 [startPlayMusic]{@link TRTCCloud#startPlayMusic}。
1868
+ * - 请您精准地按每帧时长的间隔调用本接口,数据投送间隔不均匀时极易触发声音卡顿。
1869
+ *
1870
+ * @param {TRTCAudioFrame} frame - 音频数据
1871
+ * @returns {Number} - 音频缓冲时长,单位:ms。< 0 错误(-1 未启用 mixExternalAudioFrame)
1872
+ */
1873
+ mixExternalAudioFrame(frame: TRTCAudioFrame): number;
1874
+ /**
1875
+ * 设置推流时混入外部音频的推流音量和播放音量
1876
+ *
1877
+ * @param {Number} publishVolume - 设置的推流音量大小,范围0 - 100,-1表示不改变。
1878
+ * @param {Number} playoutVolume - 设置的播放音量大小,范围0 - 100,-1表示不改变。
1879
+ */
1880
+ setMixExternalAudioVolume(publishVolume: number, playoutVolume: number): void;
1881
+ /**
1882
+ * 生成自定义采集时的时间戳
1883
+ *
1884
+ * 本接口仅适用于自定义采集模式,用于解决音视频帧的采集时间(capture time)和投送时间(send time)不一致所导致的音画不同步问题。
1885
+ * 当您通过 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 等接口进行自定义视频或音频采集时,请按照如下操作使用该接口:
1886
+ * 1. 首先,在采集到一帧视频或音频帧时,通过调用本接口获得当时的 PTS 时间戳。
1887
+ * 2. 之后可以将该视频或音频帧送入您使用的前处理模块(如第三方美颜组件,或第三方音效组件)。
1888
+ * 3. 在真正调用 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 进行投送时,请将该帧在采集时记录的 PTS 时间戳赋值给 {@link TRTCVideoFrame} 或 {@link TRTCAudioFrame} 中的 timestamp 字段。
1889
+ *
1890
+ *
1891
+ * @returns {Number} - 时间戳(单位:ms)
1892
+ */
1893
+ generateCustomPTS(): number;
1788
1894
  /**
1789
1895
  * @private
1790
1896
  * 设置本地视频自定义渲染(Electron 平台下不可用)
@@ -1959,7 +2065,7 @@ declare class TRTCCloud extends EventEmitter {
1959
2065
  * @example
1960
2066
  * // 音乐播放
1961
2067
  * import TRTCCloud, { AudioMusicParam } from 'trtc-electron-sdk';
1962
- * const rtcCloud = new TRTCCloud();
2068
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
1963
2069
  *
1964
2070
  * const params = new AudioMusicParam();
1965
2071
  * params.id = 1;
package/liteav/trtc.js CHANGED
@@ -144,7 +144,7 @@ let oriRtcCloud = null;
144
144
  * @example
145
145
  * // 创建/使用/销毁 TRTCCloud 对象的示例代码:
146
146
  * import TRTCCloud from 'trtc-electron-sdk';
147
- * this.rtcCloud = new TRTCCloud();
147
+ * this.rtcCloud = TRTCCloud.getTRTCShareInstance();
148
148
  * // 获取 SDK 版本号
149
149
  * let version = this.rtcCloud.getSDKVersion();
150
150
  *
@@ -225,7 +225,7 @@ class TRTCCloud extends events_1.EventEmitter {
225
225
  * @example
226
226
  * // Enable 'debug' mode
227
227
  * const TRTCCloud = require('trtc-electron-sdk');
228
- * const rtcCloud = new TRTCCloud();
228
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
229
229
  * rtcCloud.getConfigObject().setDebugMode(true);
230
230
  *
231
231
  * @returns {TRTCConfig}
@@ -267,7 +267,7 @@ class TRTCCloud extends events_1.EventEmitter {
267
267
  * @example
268
268
  * // 创建/使用/销毁 TRTCCloud 对象的示例代码:
269
269
  * import TRTCCloud from 'trtc-electron-sdk';
270
- * this.rtcCloud = new TRTCCloud();
270
+ * this.rtcCloud = TRTCCloud.getTRTCShareInstance();
271
271
  *
272
272
  * // 注册回调的方法,事件关键字详见下方"通用事件回调"
273
273
  * subscribeEvents = (rtcCloud) => {
@@ -2944,7 +2944,7 @@ class TRTCCloud extends events_1.EventEmitter {
2944
2944
  * TRTCScreenCaptureProperty
2945
2945
  * } from 'trtc-electron-sdk';
2946
2946
  *
2947
- * const rtcCloud = new TRTCCloud();
2947
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
2948
2948
  *
2949
2949
  * const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
2950
2950
  *
@@ -2971,7 +2971,7 @@ class TRTCCloud extends events_1.EventEmitter {
2971
2971
  * // 示例2: 选择要分享的窗口或屏幕,9.3 及之前版本只能使用此方式
2972
2972
  * import TRTCCloud, { Rect } from 'trtc-electron-sdk';
2973
2973
  *
2974
- * const rtcCloud = new TRTCCloud();
2974
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
2975
2975
  *
2976
2976
  * const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
2977
2977
  *
@@ -3027,7 +3027,7 @@ class TRTCCloud extends events_1.EventEmitter {
3027
3027
  * TRTCVideoResolutionMode
3028
3028
  * } from 'trtc-electron-sdk';
3029
3029
  *
3030
- * const rtcCloud = new TRTCCloud();
3030
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
3031
3031
  *
3032
3032
  * const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
3033
3033
  *
@@ -3189,16 +3189,143 @@ class TRTCCloud extends events_1.EventEmitter {
3189
3189
  removeAllExcludedShareWindow() {
3190
3190
  this.rtcCloud.removeAllExcludedShareWindow();
3191
3191
  }
3192
+ /**
3193
+ * 将指定窗口加入屏幕分享的包含列表中(该接口仅支持桌面系统)
3194
+ *
3195
+ * @param {String} win - 希望被分享出去的窗口(Windows 平台下为窗口句柄: HWND)
3196
+ * - 该方法只有在 TRTCScreenCaptureSourceInfo 中的 type 指定为 TRTCScreenCaptureSourceTypeWindow 时生效,即分享窗口内容时,额外包含指定窗口的功能才生效。
3197
+ * - 您在 startScreenCapture 之前和之后调用均可。
3198
+ * - 通过该方法添加到包含列表中的窗口,会在退出房间后被 SDK 自动清除。
3199
+ */
3200
+ addIncludedShareWindow(win) {
3201
+ if (isNaN(+win)) {
3202
+ console.error('trtc:addIncludedShareWindow, win: ' + win + 'is not invalid!');
3203
+ return;
3204
+ }
3205
+ this.rtcCloud.addIncludedShareWindow(win);
3206
+ }
3207
+ /**
3208
+ * 将指定窗口从屏幕分享的包含列表中移除(该接口仅支持桌面系统)
3209
+ *
3210
+ * @param {String} win - 希望被分享出去的窗口(Mac 平台: 窗口 ID;Windows 平台: HWND)
3211
+ * - 该方法只有在 TRTCScreenCaptureSourceInfo 中的 type 指定为 TRTCScreenCaptureSourceTypeWindow 时生效,即分享窗口内容时,额外包含指定窗口的功能才生效。
3212
+ */
3213
+ removeIncludedShareWindow(win) {
3214
+ if (isNaN(+win)) {
3215
+ console.error('trtc:removeIncludedShareWindow, win: ' + win + 'is not invalid!');
3216
+ return;
3217
+ }
3218
+ this.rtcCloud.removeIncludedShareWindow(win);
3219
+ }
3220
+ /**
3221
+ * 将全部窗口从屏幕分享的包含列表中移除(该接口仅支持桌面系统)
3222
+ *
3223
+ * @note 该方法只有在 TRTCScreenCaptureSourceInfo 中的 type 指定为 TRTCScreenCaptureSourceTypeWindow 时生效,即分享窗口内容时,额外包含指定窗口的功能才生效。
3224
+ */
3225
+ removeAllIncludedShareWindow() {
3226
+ this.rtcCloud.removeAllIncludedShareWindow();
3227
+ }
3192
3228
  /////////////////////////////////////////////////////////////////////////////////
3193
3229
  //
3194
3230
  // (九)自定义采集和渲染
3195
3231
  //
3196
3232
  /////////////////////////////////////////////////////////////////////////////////
3197
- //TODO:暂时未完成
3198
- // | [enableCustomVideoCapture] | 启用视频自定义采集模式 |
3199
- // | [sendCustomVideoData] | 向 SDK 投送自己采集的视频数据 |
3200
- // | [enableCustomAudioCapture] | 向 SDK 投送自己采集的音频数据 |
3201
- // | [setAudioFrameCallback] | 设置音频数据回调 |
3233
+ /**
3234
+ * 启用音频自定义采集模式
3235
+ *
3236
+ * 开启该模式后,SDK 不在运行原有的音频采集流程,即不再继续从麦克风采集音频数据,而是只保留音频编码和发送能力。
3237
+ * 您需要通过 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 不断地向 SDK 塞入自己采集的音频数据。
3238
+ *
3239
+ * 注意:
3240
+ * - 音频自定义采集与 SDK 默认的麦克疯音频采集互斥。因此,调用 `enableCustomAudioCapture(true)` 开启音频自定义采集前,需要先调用 [stopLocalAudio]{@link TRTCCloud#stopLocalAudio} 接口关闭默认的麦克风音频上行,否则不生效;调用 `enableCustomAudioCapture(false)` 关闭自定义采集后,要调用 [startLocalAudio]{@link TRTCCloud#startLocalAudio} 接口才能开启 SDK 默认的麦克风音频采集。
3241
+ * - 由于回声抵消(AEC)需要严格的控制声音采集和播放的时间,所以开启自定义音频采集后,AEC 能力可能会失效。
3242
+ *
3243
+ * @param {Boolean} enable - 是否启用,默认值:false。
3244
+ */
3245
+ enableCustomAudioCapture(enable) {
3246
+ this.rtcCloud.enableCustomAudioCapture(enable);
3247
+ }
3248
+ /**
3249
+ * 向 SDK 投送自己采集的音频数据
3250
+ *
3251
+ * 参数 {@link TRTCAudioFrame} 推荐下列填写方式(其他字段不需要填写):
3252
+ * - audioFormat:音频数据格式,仅支持 TRTCAudioFrameFormatPCM。
3253
+ * - data:音频帧 buffer。音频帧数据只支持 PCM 格式,支持[5ms ~ 100ms]帧长,推荐使用 20ms 帧长,长度计算方法:【48000采样率、单声道的帧长度:48000 × 0.02s × 1 × 16bit = 15360bit = 1920字节】。
3254
+ * - sampleRate:采样率,支持:16000、24000、32000、44100、48000。
3255
+ * - channel:声道数(如果是立体声,数据是交叉的),单声道:1; 双声道:2。
3256
+ * - timestamp:时间戳,单位为毫秒(ms),请使用音频帧在采集时被记录下来的时间戳(可以在采集到一帧音频帧之后,通过调用 [generateCustomPTS]{@link TRTCCloud#generateCustomPTS} 获取时间戳)。
3257
+ *
3258
+ * 注意:请您精准地按每帧时长的间隔调用本接口,数据投送间隔不均匀时极易触发声音卡顿。
3259
+ *
3260
+ * @param {TRTCAudioFrame} frame - 音频数据
3261
+ */
3262
+ sendCustomAudioData(frame) {
3263
+ this.rtcCloud.sendCustomAudioData(frame);
3264
+ }
3265
+ /**
3266
+ * 启用/关闭自定义音轨
3267
+ *
3268
+ * 开启后,您可以通过本接口向 SDK 混入一条自定义的音轨。通过两个布尔型参数,您可以控制该音轨是否要在远端和本地播放。
3269
+ *
3270
+ * 注意: 如果您指定参数 enablePublish 和 enablePlayout 均为 false,代表完全关闭您的自定义音轨。
3271
+ * @param {Boolean} enablePublish - 控制混入的音轨是否要在远端播放,默认值:false。
3272
+ * @param {Boolean} enablePlayout - 控制混入的音轨是否要在本地播放,默认值:false。
3273
+ *
3274
+ */
3275
+ enableMixExternalAudioFrame(enablePublish, enablePlayout) {
3276
+ this.rtcCloud.enableMixExternalAudioFrame(enablePublish, enablePlayout);
3277
+ }
3278
+ /**
3279
+ * 向 SDK 混入自定义音轨
3280
+ *
3281
+ * * 调用该接口之前,您需要先通过 [enableMixExternalAudioFrame]{@link TRTCCloud#enableMixExternalAudioFrame} 开启自定义音轨,之后就可以通过本接口将自己的音轨以 PCM 格式混入到 SDK 中。
3282
+ * 理想情况下,我们期望您的代码能够以非常均匀的速度向 SDK 提供音轨数据。但我们也非常清楚,完美的调用间隔是一个巨大的挑战。
3283
+ * 所以 SDK 内部会开启一个音轨数据的缓冲区,该缓冲区的作用类似一个“蓄水池”,它能够暂存您传入的音轨数据,平抑由于接口调用间隔的抖动问题。
3284
+ * 本接口的返回值代表这个音轨缓冲区的大小,单位是毫秒(ms),比如:如果该接口返回 50,则代表当前的音轨缓冲区有 50ms 的音轨数据。因此只要您在 50ms 内再次调用本接口,SDK 就能保证您混入的音轨数据是连续的。
3285
+ * 当您调用该接口后,如果发现返回值 > 100ms,则可以等待一帧音频帧的播放时间之后再次调用;如果返回值 < 100ms,则代表缓冲区比较小,您可以再次混入一些音轨数据以确保音轨缓冲区的大小维持在“安全水位”以上。
3286
+ * 参数 {@link TRTCAudioFrame} 推荐下列填写方式(其他字段不需要填写):
3287
+ * - data:音频帧 buffer。音频帧数据只支持 PCM 格式,支持[5ms ~ 100ms]帧长,推荐使用 20ms 帧长,长度计算方法:【48000采样率、单声道的帧长度:48000 × 0.02s × 1 × 16bit = 15360bit = 1920字节】。
3288
+ * - sampleRate:采样率,支持:16000、24000、32000、44100、48000。
3289
+ * - channel:声道数(如果是立体声,数据是交叉的),单声道:1; 双声道:2。
3290
+ * - timestamp:时间戳,单位为毫秒(ms),请使用音频帧在采集时被记录下来的时间戳(可以在获得一帧音频帧之后,通过调用 [generateCustomPTS]{@link TRTCCloud#generateCustomPTS} 获得时间戳)。
3291
+ *
3292
+ * 注意:
3293
+ * - 混入自定义音轨,需要有上行音频流驱动,支持的上行音频流包括:
3294
+ * - SDK 默认采集的麦克风音频流,调用 [startLocalAudio]{@link TRTCCloud#startLocalAudio} 接口开启。
3295
+ * - 开启了自定义音频流,并有自定义音频数据上行,分别调用 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 和 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 接口。
3296
+ * - 开启了背景音乐,调用接口 [startPlayMusic]{@link TRTCCloud#startPlayMusic}。
3297
+ * - 请您精准地按每帧时长的间隔调用本接口,数据投送间隔不均匀时极易触发声音卡顿。
3298
+ *
3299
+ * @param {TRTCAudioFrame} frame - 音频数据
3300
+ * @returns {Number} - 音频缓冲时长,单位:ms。< 0 错误(-1 未启用 mixExternalAudioFrame)
3301
+ */
3302
+ mixExternalAudioFrame(frame) {
3303
+ return this.rtcCloud.mixExternalAudioFrame(frame);
3304
+ }
3305
+ /**
3306
+ * 设置推流时混入外部音频的推流音量和播放音量
3307
+ *
3308
+ * @param {Number} publishVolume - 设置的推流音量大小,范围0 - 100,-1表示不改变。
3309
+ * @param {Number} playoutVolume - 设置的播放音量大小,范围0 - 100,-1表示不改变。
3310
+ */
3311
+ setMixExternalAudioVolume(publishVolume, playoutVolume) {
3312
+ this.rtcCloud.setMixExternalAudioVolume(publishVolume, playoutVolume);
3313
+ }
3314
+ /**
3315
+ * 生成自定义采集时的时间戳
3316
+ *
3317
+ * 本接口仅适用于自定义采集模式,用于解决音视频帧的采集时间(capture time)和投送时间(send time)不一致所导致的音画不同步问题。
3318
+ * 当您通过 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 等接口进行自定义视频或音频采集时,请按照如下操作使用该接口:
3319
+ * 1. 首先,在采集到一帧视频或音频帧时,通过调用本接口获得当时的 PTS 时间戳。
3320
+ * 2. 之后可以将该视频或音频帧送入您使用的前处理模块(如第三方美颜组件,或第三方音效组件)。
3321
+ * 3. 在真正调用 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 进行投送时,请将该帧在采集时记录的 PTS 时间戳赋值给 {@link TRTCVideoFrame} 或 {@link TRTCAudioFrame} 中的 timestamp 字段。
3322
+ *
3323
+ *
3324
+ * @returns {Number} - 时间戳(单位:ms)
3325
+ */
3326
+ generateCustomPTS() {
3327
+ return this.rtcCloud.generateCustomPTS();
3328
+ }
3202
3329
  /**
3203
3330
  * @private
3204
3331
  * 设置本地视频自定义渲染(Electron 平台下不可用)
@@ -3455,7 +3582,7 @@ class TRTCCloud extends events_1.EventEmitter {
3455
3582
  * @example
3456
3583
  * // 音乐播放
3457
3584
  * import TRTCCloud, { AudioMusicParam } from 'trtc-electron-sdk';
3458
- * const rtcCloud = new TRTCCloud();
3585
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
3459
3586
  *
3460
3587
  * const params = new AudioMusicParam();
3461
3588
  * params.id = 1;
@@ -232,6 +232,29 @@ export declare class TRTCVideoFrame {
232
232
  rotation: number;
233
233
  constructor(videoFormat?: TRTCVideoPixelFormat, bufferType?: TRTCVideoBufferType, data?: null | ArrayBuffer, textureId?: number, length?: number, width?: number, height?: number, timestamp?: number, rotation?: number);
234
234
  }
235
+ /**
236
+ * 音频帧数据
237
+ *
238
+ * @param {TRTCAudioFrameFormat} audioFormat - 音频帧的格式
239
+ * @param {ArrayBuffer} data - 音频数据
240
+ * @param {Number} length - 音频数据的长度
241
+ * @param {Number} sampleRate - 采样率
242
+ * @param {Number} channel - 声道数
243
+ * @param {Number} timestamp - 时间戳,单位ms
244
+ * @param {ArrayBuffer|null} extraData - 音频额外数据,远端用户通过 `onLocalProcessedAudioFrame` 写入的数据会通过该字段回调
245
+ * @param {Number} extraDataLength - 音频消息数据的长度
246
+ */
247
+ export declare class TRTCAudioFrame {
248
+ audioFormat: TRTCAudioFrameFormat;
249
+ data: ArrayBuffer | null;
250
+ length: number;
251
+ sampleRate: number;
252
+ channel: number;
253
+ timestamp: number;
254
+ extraData: ArrayBuffer | null;
255
+ extraDataLength: number;
256
+ constructor(audioFormat?: TRTCAudioFrameFormat, data?: any, length?: number, sampleRate?: number, channel?: number, timestamp?: number, extraData?: any, extraDataLength?: number);
257
+ }
235
258
  export declare enum TRTCLogLevel {
236
259
  TRTCLogLevelNone = 0,
237
260
  TRTCLogLevelVerbose = 1,
@@ -6,8 +6,8 @@
6
6
  *
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.TRTCSwitchRoomParam = exports.AudioMusicParam = exports.TRTCStatistics = exports.TRTCRemoteStatistics = exports.TRTCLocalStatistics = exports.TRTCAudioEffectParam = exports.TRTCAudioRecordingParams = exports.TRTCPublishCDNParam = exports.TRTCTranscodingConfig = exports.TRTCAudioRecordingContent = exports.TRTCMixInputType = exports.TRTCTranscodingConfigMode = exports.TRTCMixUser = exports.Rect = exports.TRTCSpeedTestResult = exports.TRTCSpeedTestParams = exports.TRTCVolumeInfo = exports.TRTCQualityInfo = exports.TRTCNetworkQosParam = exports.TRTCRenderParams = exports.TRTCVideoEncParam = exports.TRTCParams = exports.TRTCWaterMarkSrcType = exports.TRTCCameraCaptureMode = exports.TRTCDeviceType = exports.TRTCDeviceState = exports.TRTCLogLevel = exports.TRTCVideoFrame = exports.TRTCDeviceInfo = exports.TRTCScreenCaptureProperty = exports.TRTCScreenCaptureSourceInfo = exports.TRTCImageBuffer = exports.TRTCAudioQuality = exports.TRTCScreenCaptureSourceType = exports.TRTCAudioFrameFormat = exports.TRTCVideoQosPreference = exports.TRTCQosControlMode = exports.TRTCRoleType = exports.TRTCAppScene = exports.TRTCRecordType = exports.TRTCVideoMirrorType = exports.TRTCVideoBufferType = exports.TRTCVideoPixelFormat = exports.TRTCBeautyStyle = exports.TRTCVideoRotation = exports.TRTCVideoFillMode = exports.TRTCQuality = exports.TRTCVideoStreamType = exports.TRTCVideoResolutionMode = exports.TRTCVideoResolution = void 0;
10
- exports.VideoBufferInfo = void 0;
9
+ exports.AudioMusicParam = exports.TRTCStatistics = exports.TRTCRemoteStatistics = exports.TRTCLocalStatistics = exports.TRTCAudioEffectParam = exports.TRTCAudioRecordingParams = exports.TRTCPublishCDNParam = exports.TRTCTranscodingConfig = exports.TRTCAudioRecordingContent = exports.TRTCMixInputType = exports.TRTCTranscodingConfigMode = exports.TRTCMixUser = exports.Rect = exports.TRTCSpeedTestResult = exports.TRTCSpeedTestParams = exports.TRTCVolumeInfo = exports.TRTCQualityInfo = exports.TRTCNetworkQosParam = exports.TRTCRenderParams = exports.TRTCVideoEncParam = exports.TRTCParams = exports.TRTCWaterMarkSrcType = exports.TRTCCameraCaptureMode = exports.TRTCDeviceType = exports.TRTCDeviceState = exports.TRTCLogLevel = exports.TRTCAudioFrame = exports.TRTCVideoFrame = exports.TRTCDeviceInfo = exports.TRTCScreenCaptureProperty = exports.TRTCScreenCaptureSourceInfo = exports.TRTCImageBuffer = exports.TRTCAudioQuality = exports.TRTCScreenCaptureSourceType = exports.TRTCAudioFrameFormat = exports.TRTCVideoQosPreference = exports.TRTCQosControlMode = exports.TRTCRoleType = exports.TRTCAppScene = exports.TRTCRecordType = exports.TRTCVideoMirrorType = exports.TRTCVideoBufferType = exports.TRTCVideoPixelFormat = exports.TRTCBeautyStyle = exports.TRTCVideoRotation = exports.TRTCVideoFillMode = exports.TRTCQuality = exports.TRTCVideoStreamType = exports.TRTCVideoResolutionMode = exports.TRTCVideoResolution = void 0;
10
+ exports.VideoBufferInfo = exports.TRTCSwitchRoomParam = void 0;
11
11
  const util_1 = require("./Renderer/util");
12
12
  /////////////////////////////////////////////////////////////////////////////////
13
13
  //
@@ -657,6 +657,32 @@ class TRTCVideoFrame {
657
657
  }
658
658
  exports.TRTCVideoFrame = TRTCVideoFrame;
659
659
  ;
660
+ /**
661
+ * 音频帧数据
662
+ *
663
+ * @param {TRTCAudioFrameFormat} audioFormat - 音频帧的格式
664
+ * @param {ArrayBuffer} data - 音频数据
665
+ * @param {Number} length - 音频数据的长度
666
+ * @param {Number} sampleRate - 采样率
667
+ * @param {Number} channel - 声道数
668
+ * @param {Number} timestamp - 时间戳,单位ms
669
+ * @param {ArrayBuffer|null} extraData - 音频额外数据,远端用户通过 `onLocalProcessedAudioFrame` 写入的数据会通过该字段回调
670
+ * @param {Number} extraDataLength - 音频消息数据的长度
671
+ */
672
+ class TRTCAudioFrame {
673
+ constructor(audioFormat = TRTCAudioFrameFormat.TRTCAudioFrameFormatNone, data = null, length = 0, sampleRate = 48000, channel = 1, timestamp = 0, extraData = null, extraDataLength = 0) {
674
+ this.audioFormat = audioFormat;
675
+ this.data = data;
676
+ this.length = length;
677
+ this.sampleRate = sampleRate;
678
+ this.channel = channel;
679
+ this.timestamp = timestamp;
680
+ this.extraData = extraData;
681
+ this.extraDataLength = extraDataLength;
682
+ }
683
+ }
684
+ exports.TRTCAudioFrame = TRTCAudioFrame;
685
+ ;
660
686
  /////////////////////////////////////////////////////////////////////////////////
661
687
  //
662
688
  // 【(四)更多枚举值定义】
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trtc-electron-sdk",
3
- "version": "11.4.502-beta.0",
3
+ "version": "11.4.502-beta.2",
4
4
  "description": "trtc electron sdk",
5
5
  "main": "./liteav/trtc.js",
6
6
  "types": "./liteav/trtc.d.ts",