PlanetKitAudio
public class PlanetKitAudio : NSObject
extension PlanetKitAudio: PlanetKitAudioVolumeDelegate
A class that represents the audio device for PlanetKit.
-
The shared instance of
PlanetKitAudio
.Declaration
Swift
@objc public static let shared: PlanetKitAudio
-
The default audio manager for PlanetKit.
Declaration
Swift
@objc public static var `default`: PlanetKitAudioManager { get }
-
Configures
AVAudioSession
open settings.Remark
openSettings
will be used by PlanetKit when it opensAVAudioSession
forPlanetKitAudioMicSpk
andPlanetKitAudioMic
. -
Configures
AVAudioSession
close settings.Remark
closeSettings
will be used by PlanetKit when it closesAVAudioSession
forPlanetKitAudioMicSpk
andPlanetKitAudioMic
. -
Default speaker interface.
Remark
The default speaker should be configured before creating a call or conference instance. And if you set thePlanetKitAudio.vpioEnabled
value, then the speaker interface will be reset by default.Declaration
Swift
@objc public var spk: PlanetKitAudioSpkControllable? { get set }
-
Default microphone interface.
Remark
The default microphone should be configured before creating a call or conference instance. And if you set thePlanetKitAudio.vpioEnabled
value, then the microphone interface will be reset by default.Declaration
Swift
@objc public var mic: PlanetKitAudioMicControllable? { get set }
-
Configures the default I/O buffer duration.
Remark
This will set theAVAudioSession.ioBufferDuration
value. The recommended value is 0.01, but if you set an unaffordable or incorrect value, it can affect the audio device, like causing a Bluetooth HFP device to become stuck or stop working. Please be careful when changing this value. -
Configures the default microphone sample rate.
Remark
The default microphone sample rate is 44100 (VPIO on) or 48000 (VPIO off) in macOS, and 32000 in iOS.Declaration
Swift
@objc public var defaultMicSampleRate: Float64 { get set }
-
Configures the default speaker sample rate.
Remark
The default speaker sample rate is 44100 (VPIO on) or 48000 (VPIO off) in macOS, and 32000 in iOS.Declaration
Swift
@objc public var defaultSpkSampleRate: Float64 { get set }
-
Indicates whether the VoiceProcessingIO is enabled.
Remark
This value will be modified during call setup by our service configuration. If you want to override our suggested configuration, you should callwithIgnoreVpioServiceConfigKey(ignore:)
. The default value istrue
for iOS andfalse
for macOS.Declaration
Swift
@objc public var vpioEnabled: Bool { get set }
-
Gets the available audio devices.
Declaration
Swift
@objc public var devices: [PlanetKitAudioDevice]? { get }
-
Gets or sets the microphone device.
Remark
The value can be changed at any time and will take effect at the next successfulPlanetKitAudio.start()
call. IfmicDevice
is set tonil
, the input device will be disabled. If you want to restore the default device, callPlanetKitAudio.setPreferredDefaultDevice(type:)
.Declaration
Swift
@objc public var micDevice: PlanetKitAudioDevice? { get set }
-
Gets or sets the speaker device.
Remark
The value can be changed at any time and will take effect at the next successfulPlanetKitAudio.start()
call. IfspkDevice
is set tonil
, the output device will be disabled. If you want to restore the default device, callPlanetKitAudio.setPreferredDefaultDevice(type:)
.Declaration
Swift
@objc public var spkDevice: PlanetKitAudioDevice? { get set }
-
Adds a delegate to receive device change events.
Declaration
Swift
@objc public func addDeviceChangeDelegate(_ delegate: PlanetKitAudioDeviceChangeDelegate)
Parameters
delegate
The delegate to add.
-
Removes a previously added device change delegate.
Declaration
Swift
@objc public func removeDeviceChangeDelegate(_ delegate: PlanetKitAudioDeviceChangeDelegate)
Parameters
delegate
The delegate to remove.
-
The current volume level of the microphone.
Remark
The volume level ranges between 0.0 and 1.0.Declaration
Swift
@objc public var micVolume: Float { get }
-
The current volume level of the speaker.
Remark
The volume level ranges between 0.0 and 1.0.Declaration
Swift
@objc public var spkVolume: Float { get }
-
Sets the volume level for the audio device.
Remark
Setting the speaker volume is not supported on iOS.Declaration
Swift
@objc public func setVolume(_ volume: Float, for type: PlanetKitAudioDeviceType)
-
Adds a delegate to receive volume change events.
Declaration
Swift
@objc public func addVolumeDelegate(_ delegate: PlanetKitAudioVolumeDelegate, for type: PlanetKitAudioDeviceType)
-
Removes a delegate from receiving volume change events.
Declaration
Swift
@objc public func removeVolumeDelegate(_ delegate: PlanetKitAudioVolumeDelegate, for type: PlanetKitAudioDeviceType)
Parameters
delegate
The delegate to remove from receiving volume change events.
type
The type of the audio device.
-
Adds a delegate to be notified of audio route changes.
-
Removes a delegate from being notified of audio route changes.
-
Indicates whether the audio input is from a Bluetooth device in the current audio session route.
Declaration
Swift
@objc public var isBluetoothInput: Bool { get }
-
Indicates whether the audio output is from a built-in receiver or built-in speaker in the current audio session route.
-
Called when the volume level of the audio device changes.
Declaration
Swift
public func didChangeVolume(_ type: PlanetKitAudioDeviceType, volume: Float)
Parameters
type
The type of the audio device.
volume
The volume level of the audio device.
-
The notification name for when the microphone is opened.
Declaration
Swift
@objc public static let didOpenMicNotification: NSNotification.Name
-
The notification name for when the speaker is opened.
Declaration
Swift
@objc public static let didOpenSpkNotification: NSNotification.Name
-
The notification name for when the microphone is closed.
Declaration
Swift
@objc public static let didCloseMicNotification: NSNotification.Name
-
The notification name for when the speaker is closed.
Declaration
Swift
@objc public static let didCloseSpkNotification: NSNotification.Name
-
The notification name for when the microphone is started.
Declaration
Swift
@objc public static let didStartMicNotification: NSNotification.Name
-
The notification name for when the speaker is started.
Declaration
Swift
@objc public static let didStartSpkNotification: NSNotification.Name
-
The notification name for when the microphone is stopped.
Declaration
Swift
@objc public static let didStopMicNotification: NSNotification.Name
-
The notification name for when the speaker is stopped.
Declaration
Swift
@objc public static let didStopSpkNotification: NSNotification.Name
-
Sets the preferred default audio device.
Remark
The recommended default audio device is set by the system.Declaration
Swift
@objc public func setPreferredDefaultDevice(type: PlanetKitAudioDeviceType)