Opentok视频通话是扬声器用户ID

问题描述 投票:0回答:1

我已经在我的角度6中集成了OT视频通话会话。

这是发布商流代码

    const publisher = OT.initPublisher('publisher', {
     name: 'pubname',
  style: { 'buttonDisplayMode': 'off'},
  insertMode: 'append',
  width: '100%',
  fitMode: 'contain',
  height: '100%'
  });

这是订阅者流代码:

session.subscribe(event.stream, dup_div, {
  insertMode: 'append',
  name:'subname',
 style: { 'buttonDisplayMode': 'off'},
width: '100%',
fitMode: 'contain',
height: '100%'
});

这工作正常。我的流中有4个订阅者。如果是这样,我想得到谁说话。也就是说,如果订户1提出问题,那么其他人应该让Subscriber1发言。所以我希望获得正在发言的用户ID。我如何使用captureStream()getAudioTracks()获得此功能。

请帮我找到这个。我没有得到任何关于此的示例或示例代码。

angular6 opentok
1个回答
0
投票

我能想到有几种选择。

  1. 您可以使用Subscriber "audioLevelUpdated" Events,如果它们超过阈值,那么您说用户正在说话。就像是: const subscriber = session.subscribe(stream); subscriber.on('audioLevelUpdated', () => { if (movingAvg === null || movingAvg <= event.audioLevel) { movingAvg = event.audioLevel; } else { movingAvg = 0.7 * movingAvg + 0.3 * event.audioLevel; } // 1.5 scaling to map the -30 - 0 dBm range to [0,1] let logLevel = (Math.log(movingAvg) / Math.LN10) / 1.5 + 1; logLevel = Math.min(Math.max(logLevel, 0), 1); if (logLevel > 0.5) { // They are speaking, do whatever you need to do here } });
  2. 您可以使用已经有用的“讲话”事件的hark.js library,然后将这些事件发送给其他参与者。 const publisher = OT.initPublisher(); // Create a new MediaStream with the audio track from the Publisher const mediaStream = new MediaStream([publisher.getAudioSource()]); const speech = hark(mediaStream, options); speech.on('speaking', () => { // They are speaking session.signal({ type: 'speaking'}); }); const subscribersByConnectionId = {}; session.on('streamCreated', (event) => { const subscriber = session.subscribe(event.stream); subscribersByConnectionId[event.stream.connection.connectionId] = subscriber; subscriber.on('destroyed', (event) => { delete subscribersByConnectionId[event.stream.connection.connectionId]; }); }); session.on('signal:speaking', (event) => { const subscriberSpeaking = subscribersByConnectionId[event.from.connectionId]; // Do whatever you want with the subscriber that is speaking });
© www.soinside.com 2019 - 2024. All rights reserved.