PlanetKitAudioManager
public class PlanetKitAudioManager : NSObject
A class that manages audio processing.
-
Indicates whether the VoiceProcessingIO is enabled.
Setting this property to
true
enables the VPIO feature, while setting it tofalse
disables it. The default value istrue
for iOS andfalse
for macOS.Remark
This property is reflected identically toPlanetKitAudio.shared.vpioEnabled
.Declaration
Swift
@objc public var vpioEnabled: Bool { get set }
-
The speaker instance that controls the audio playback.
Declaration
Swift
@objc public var spk: PlanetKitAudioSpkControllable? { get set }
-
The microphone instance that controls the audio capture.
Declaration
Swift
@objc public var mic: PlanetKitAudioMicControllable? { get set }
-
A Boolean value indicating whether the microphone is enabled or disabled.
Declaration
Swift
@objc public var micEnabled: Bool { get set }
-
A Boolean value indicating whether the speaker is enabled or disabled.
Declaration
Swift
@objc public var spkEnabled: Bool { get set }
-
Queries whether the audio device instance is opened.
Declaration
Swift
@objc public var isOpened: Bool { get }
-
Queries whether the audio device instance is started.
Declaration
Swift
@objc public var isStarted: Bool { get }
-
Creates an audio processing unit instance and configures AVAudioSession.
iOS Only
If you have configured
PlanetKitAudio.shared.openSettings
, the configuration ofAVAudioSession
will be changed to the configuration ofPlanetKitAudio.shared.openSettings
.Declaration
Swift
@objc public func open()
-
Starts audio processing.
iOS Only
It will call
AVAudioSession.sharedInstance().setActive(true)
internally.Declaration
Swift
@objc public func start()
-
Stops audio processing.
Declaration
Swift
@objc public func stop()
-
Releases the audio processing unit instance and resets AVAudioSession.
iOS Only
If you have configured
PlanetKitAudio.shared.closeSettings
, the configuration ofAVAudioSession
will be changed to the configuration ofPlanetKitAudio.shared.closeSettings
.Declaration
Swift
@objc public func close()
-
Sets the audio route to its default value.
Declaration
Swift
@objc public func setDefaultAudioRoute(_ hasVideo: Bool)
-
Attempts to change the audio route to the speaker temporarily. You can check whether the state has been changed internally with a periodic query on
isSpeakerOut
for value changes.Remark
If the current audio route changed by connecting with a Bluetooth audio device, it will be reset by the system. See more details on QA1754. You can also change the audio route using AVRoutePickerView.Declaration
Swift
@objc public func speakerOut(_ out: Bool)
-
Sets the category and options for the audio session.
Declaration
Swift
@objc public func setCategory(_ category: AVAudioSession.Category, options: AVAudioSession.CategoryOptions)
Parameters
category
The category of the audio session.
options
The options for the audio session category.
-
Indicates whether the speakerphone is enabled.
Declaration
Swift
@objc public var isSpeakerOut: Bool { get }
-
Sets the preferred audio route for the speaker playback.
Declaration
Swift
@objc public func setPreferredAudioRoute(_ route: PlanetKitAudioRoute)
Parameters
route
The preferred audio route for the speaker playback.
-
Represents the currently used microphone device.
Remark
This property is reflected identically toPlanetKitAudio.shared.micDevice
. -
Represents the currently used speaker device.
Remark
This property is reflected identically toPlanetKitAudio.shared.spkDevice
.
-
Adds a microphone receiver to receive a copy of captured audio data.
Declaration
Swift
@objc public func addMicReceiver(_ micReceiver: PlanetKitAudioMicCaptureDelegate)
-
Removes the targeted microphone receiver.
Declaration
Swift
@objc public func removeMicReceiver(_ micReceiver: PlanetKitAudioMicCaptureDelegate)
-
Adds a speaker receiver to receive a copy of rendered audio data.
Declaration
Swift
@objc public func addSpkReceiver(_ spkReceiver: PlanetKitAudioSpkPlayDelegate)
-
Removes the targeted speaker receiver.
Declaration
Swift
@objc public func removeSpkReceiver(_ spkReceiver: PlanetKitAudioSpkPlayDelegate)
-
Plays a local audio file.
Declaration
Swift
@objc public func playFile(fileResourceUrl: URL, type: String, loopCount: Int32 = -1)
Parameters
type
Identifies a unique playing instance. Generally used to stop playing the audio file.
-
Plays a local audio file.
Declaration
Swift
@objc public func playFile(fileResourceUrl: URL, type: String, loopCount: Int32, completion: @escaping (Bool) -> Void)
Parameters
type
Identifies a unique playing instance. Generally used to stop playing the audio file.
completion
It is called after the audio file has finished playing.
-
Stops playing the audio file.
Declaration
Swift
@objc public func playStop(type: String)