Audio
You can control user audio in ongoing session using methods provided by the Video SDK.
Prior to using audio and video controls, you must request permissions to use the microphone. See the rest of this page for details and Requesting Authorization for Media Capture on macOS for more.
Audio controls
Using the SDK functions, you can provide users in a session with controls for managing their audio. Session hosts can manage their own audio as well the audio of other users in the session.
Some common features that you might want to include in your app could be an option to mute or unmute a user's audio. Prior to changing the audio control, you may also need to obtain data about the state of each users' audio and present it in the UI of your app.
The following sections show some examples of audio and video controls.
Check if the user is connected to audio
Before you can use audio controls, you must first check if the user is connected to audio by getting the user's ZMVideoSDKAudioType.
// Get the user\'s audioStatus
if let audioStatus = user.getAudioStatus() {
// Get the user\'s audioType.
let audioType = audioStatus.getAudioType()
}
// Get the user\'s audioStatus.
ZMVideoSDKAudioStatus *audioStatus = [user getAudioStatus];
// Get the user\'s audioType.
ZMVideoSDKAudioType audioType = [audioStatus getAudioType];
Connect to audio
If the user is not already connected, you can connect to the audio through the ZMVideoSDKAudioHelper.
if audioType == ZMVideoSDKAudioType_None {
// User\'s audio is not connected.
// Get the ZMVideoSDKAudioHelper to perform audio actions.
if let audioHelper = ZMVideoSDK.shared()?.getAudioHelper() {
// Connect User\'s audio.
audioHelper.startAudio()
}
} else {
// User is already connected to audio.
}
if (audioType == ZMVideoSDKAudioType_None) {
// User\'s audio is not connected.
// Get the ZMVideoSDKAudioHelper to perform audio actions.
ZMVideoSDKAudioHelper *audioHelper = [[ZMVideoSDK sharedZMVideoSDK] getAudioHelper];
if (audioHelper) {
// Connect User\'s audio.
[audioHelper startAudio];
}
} else {
// User is already connected to audio.
}
Mute audio
Once connected, you can mute a user's audio by calling muteAudio with the user's ID:
// Get the ZMVideoSDKAudioHelper to perform audio actions.
if let audioHelper = ZMVideoSDK.shared()?.getAudioHelper() {
// Mute user.
audioHelper.muteAudio(user)
}
// Get the ZMVideoSDKAudioHelper to perform audio actions.
ZMVideoSDKAudioHelper *audioHelper = [[ZMVideoSDK sharedZMVideoSDK] getAudioHelper];
if (audioHelper) {
// Mute user.
[audioHelper muteAudio:user];
}
Unmute audio
Unmute a user's audio in a similar manner using unMuteAudio:
// Get the ZMVideoSDKAudioHelper to perform audio actions.
if let audioHelper = ZMVideoSDK.shared()?.getAudioHelper() {
// Unmute user.
audioHelper.unMuteAudio(user)
}
// Get the ZMVideoSDKAudioHelper to perform audio actions.
ZMVideoSDKAudioHelper *audioHelper = [[ZMVideoSDK sharedZMVideoSDK] getAudioHelper];
if (audioHelper) {
// Mute user.
[audioHelper muteAudio:user];
}
Disconnect from audio
To disconnect completely from audio, use stopAudio:
// Get the ZMVideoSDKAudioHelper to perform audio actions.
if let audioHelper = ZMVideoSDK.shared()?.getAudioHelper() {
// Disconnect User\'s audio.
audioHelper.stopAudio()
}
// Get the ZMVideoSDKAudioHelper to perform audio actions.
ZMVideoSDKAudioHelper *audioHelper = [[ZMVideoSDK sharedZMVideoSDK] getAudioHelper];
if (audioHelper) {
// Disconnect User\'s audio.
[audioHelper stopAudio];
}
Sound options
By default, Zoom uses noise suppression and echo cancellation to improve the quality of the audio received by your microphone, but these audio filters can interfere with situations that require capturing the full range of audio. See Configuring professional audio settings for Zoom Meetings for details.
Video SDK uses the same technology to improve audio quality, but also supports the ability to turn off these filters to capture the original sound of the microphone, for example, to support the use of a high-quality microphone with built-in audio filters or to capture the full audio range without noise suppression. Capturing the microphone's original sound disables the background noise suppression feature.
Original sound
To enable original sound, set enableMicOriginalInput to true (YES) in the ZMVideoSDKAudioSettingHelper class. The default setting is false (NO).
ZMVideoSDKAudioSettingHelper *audioSettingHelper = [[ZMVideoSDK sharedVideoSDK] getAudioSettingHelper];
[audioSettingHelper enableMicOriginalInput:YES];
To disable, set enableMicOriginalInput to false (NO).
[audioSettingHelper enableMicOriginalInput:NO];
Background noise suppression
By default, Zoom Video SDK's standard optimized audio is used for processing your microphone audio. This includes some background noise suppression and is best for most situations, but the level of background noise suppression can be adjusted to suit your needs.
Set the noise suppression level using setSuppressBackgroundNoiseLevel in the ZMVideoSDKAudioSettingHelper class.
ZMVideoSDKAudioSettingHelper *audioSettingHelper = [[ZMVideoSDK sharedVideoSDK] getAudioSettingHelper];
[audioSettingHelper setSuppressBackgroundNoiseLevel: ZMVideoSDKSuppressBackgroundNoiseLevel_High];
You can choose from the following levels:
ZMVideoSDKSuppressBackgroundNoiseLevel_Auto(the default setting)ZMVideoSDKSuppressBackgroundNoiseLevel_LowZMVideoSDKSuppressBackgroundNoiseLevel_MediumZMVideoSDKSuppressBackgroundNoiseLevel_High
Callbacks
The following are examples of some audio callbacks.
Get notified when a user's audio status has changed
func onUserAudioStatusChanged(_ audioHelper: ZMVideoSDKAudioHelper!, userList userArray: [ZMVideoSDKUser]!) {
// UserArray contains the users that had an audio status change.
// Use helper to perform actions on a user.
if let userArray = userArray {
for user in userArray {
// Use to check if a user's audio is muted.
// If true, the user is muted. If false, the user is unmuted.
if ((user.getAudioStatus().isMuted) == true) {
// User's audio is not muted.
}
// Use to obtain a certain user's audio type.
if let audioType = getAudioStatus()?.audioType {
print("User has audio type: \(audioType)")
}
}
}
}
- (void)onUserAudioStatusChanged:(ZMVideoSDKAudioHelper*)audioHelper userList:(NSArray*)userArray {
// UserArray contains the users that had an audio status change.
// Use helper to perform actions on a user.
for (int i = 0; i < userArray.count; i++) {
if (userArray[i]) {
// Use to check if a user's audio is muted.
// If true, the user is muted. If false, the user is unmuted.
if ([user getAudioStatus].isMuted) {
// User's audio is not muted.
}
// Use to obtain a certain user's audio type.
NSLog(@"User has audio type: %lu", [userArray[i] getAudioStatus].audioType);
}
}
}
Get notified when a user's active audio changes
onUserActiveAudioChanged is different from onUserAudioStatusChanged. The SDK calls onUserActiveAudioChanged when a given user's audio changes, it calls onUserAudioStatusChanged when the user's audio status changes.
For example, if the user is unmuted and is using their device's microphone, onUserActiveAudioChanged will be triggered whenever their microphone detects a noise.
func onUserActiveAudioChanged(_ audioHelper: ZMVideoSDKAudioHelper!, userList userArray: [ZMVideoSDKUser]!) {
// UserArray contains the users that had an active audio change.
// Use helper to perform audio actions.
if let userArray = userArray {
for user in userArray {
// Use to see if the user is currently talking.
if let audioStatus = user.getAudioStatus(), audioStatus.isTalking, let userName = user.getUserName() {
print("\(userName) began talking.")
}
}
}
}
- (void)onUserActiveAudioChanged:(ZMVideoSDKAudioHelper*)audioHelper userList:(NSArray*)userArray {
// UserArray contains the users that had an active audio change.
// Use helper to perform audio actions.
for (int i = 0; i < userArray.count; i++) {
if (userArray[i]) {
// Use to see if the user is currently talking.
if ([userArray[i] getAudioStatus].isTalking) {
NSLog(@"%@ began talking.", userArray[i].getUserName);
}
}
}
}