PlanetKitAudioMicSpk
public class PlanetKitAudioMicSpk : NSObject
extension PlanetKitAudioMicSpk: PlanetKitAudioMicControllable, PlanetKitAudioSpkControllable
extension PlanetKitAudioMicSpk: PlanetAudioPlayerDelegate
extension PlanetKitAudioMicSpk: PlanetAudioUnitTargetDelegate
extension PlanetKitAudioMicSpk: PlanetAudioUnitSourceDelegate
The PlanetKitAudioMicSpk
class is a class that manages the microphone and speaker audio processing unit.
-
Indicates whether the VoiceProcessingIO is enabled.
Remark
ThevpioEnabled
property is alwaystrue
because the voice processing I/O is always enabled. The voice processing I/O is always enabled in thePlanetKitAudioMicSpk
class. If you want to disable the voice processing I/O, you should use thePlanetKitAudioMic
andPlanetKitAudioSpk
class directly.See
PlanetKitAudioMic
,PlanetKitAudioMicSpk
,PlanetKitAudioMicControllable
,PlanetKitAudioSpkControllable
Declaration
Swift
public var vpioEnabled: Bool { get set }
-
A Boolean value indicating whether the microphone is enabled or disabled.
Declaration
Swift
public var micEnabled: Bool
-
A Boolean value indicating whether the speaker is enabled or disabled.
Declaration
Swift
public var spkEnabled: Bool
-
Sets a private delegate for a
PlanetKitCall
orPlanetKitConference
instance.Remark
You should not set this delegate directly. It will be called when the call is connected or the conference is joined. If you implement it, you should call the delegate’sdidCapture(frameCnt:channels:sampleRate:sampleType:timestamp:outData:outDataLen:)
when the speaker needs to play sound.Declaration
Swift
public weak var micPrivateDelegate: PlanetKitAudioMicCaptureDelegate? { get set }
-
Sets a modifier to receive audio data before sending audio to the server.
The modifier can modify audio data.
Declaration
Swift
public weak var micModifier: PlanetKitAudioMicCaptureDelegate? { get set }
Parameters
micModifier
The modifier to receive audio data before audio transmission.
-
Sets a receiver to receive volume level events at intervals for the microphone.
Declaration
Swift
public weak var micVolumeReceiver: PlanetKitAudioDeviceVolumeDelegate? { get set }
-
Sets the volume level event interval for the microphone.
Declaration
Swift
public var micVolumeInterval: TimeInterval { get set }
-
Sets a private delegate for a
PlanetKitCall
orPlanetKitConference
instance.Remark
You should not set this delegate directly. It will be called when the call is connected or the conference is joined. If you implement it, you should call the delegate’swillPlay(frameCnt:channels:sampleRate:sampleType:timestamp:playBuf:playBufSize:)
when the speaker needs to play sound.Declaration
Swift
public weak var spkPrivateDelegate: PlanetKitAudioSpkPlayDelegate? { get set }
-
Sets a modifier to receive audio data before speaker out.
The modifier can modify audio data.
Declaration
Swift
public weak var spkModifier: PlanetKitAudioSpkPlayDelegate? { get set }
-
Sets a receiver to receive volume level events at intervals for the speaker.
Declaration
Swift
public weak var spkVolumeReceiver: PlanetKitAudioDeviceVolumeDelegate? { get set }
-
Sets the interval to receive volume level events for the speaker.
Declaration
Swift
public var spkVolumeInterval: TimeInterval { get set }
-
A textual representation of
PlanetKitAudioMicSpk
instance.Declaration
Swift
public override var description: String { get }
-
Queries whether the audio device instance is opened.
Declaration
Swift
public var isOpened: Bool { get }
-
Queries whether the audio device instance is started.
Declaration
Swift
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
public func open()
-
Starts audio processing for the microphone.
iOS Only
It will call
AVAudioSession.sharedInstance().setActive(true)
internally.Declaration
Swift
public func start()
-
Stops audio processing for the microphone.
Declaration
Swift
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
public func close()
-
Executes the
completion
handler after all current audio work items are completed.Remark
If you use this function for frequent or heavy jobs, it will affect the performance of setting up the microphone and the speaker device. Be sure not to enqueue an overload job.Declaration
Swift
public func async(completion: @escaping () -> Void)
-
Indicates whether the speakerphone is enabled.
-
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. -
Sets the category and options for the audio session.
-
Sets the mode for the audio session.
-
Sets the preferred audio route for the speaker playback.
-
Represents the currently used microphone device.
Remark
This property is reflected identically toPlanetKitAudio.shared.micDevice
.Declaration
Swift
public var micDevice: PlanetKitAudioDevice? { get set }
-
Represents the currently used speaker device.
Remark
This property is reflected identically toPlanetKitAudio.shared.spkDevice
.Declaration
Swift
public var spkDevice: PlanetKitAudioDevice? { get set }
-
Provides device type information to PlanetKit, indicating if it is a real device or a virtual device.
Remark
The value of theisVirtualDevice
property is alwaysfalse
.See
PlanetKitAudioMicControllable
, PlanetKitAudioSpkControllable`Declaration
Swift
public var isVirtualDevice: Bool { get }
-
Adds a microphone receiver to receive a copy of captured audio data.
Declaration
Swift
public func addMicReceiver(_ micReceiver: PlanetKitAudioMicCaptureDelegate)
-
Removes the targeted microphone receiver.
Declaration
Swift
public func removeMicReceiver(_ micReceiver: PlanetKitAudioMicCaptureDelegate)
-
Adds a speaker receiver to receive a copy of rendered audio data.
Declaration
Swift
public func addSpkReceiver(_ spkDelegate: PlanetKitAudioSpkPlayDelegate)
-
Removes the targeted speaker receiver.
Declaration
Swift
public func removeSpkReceiver(_ spkDelegate: PlanetKitAudioSpkPlayDelegate)
-
Plays a local audio file.
Declaration
Swift
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
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
public func playStop(type: String)
-
Called when the audio file has finished playing.
Declaration
Swift
public func playDidFinish(_ type: String!, userData: Int32)
Parameters
type
Identifies a unique playing instance. Generally used to stop playing the audio file.
userData
Enum value of
PlanetKitAudioPlayFileSetting
.
-
Processes the captured audio frames.
Declaration
Swift
public func onFrames(_ unitId: UInt32, frameNum frameNums: UInt32, format: UnsafeMutablePointer<AudioStreamBasicDescription>!, timestamp: UnsafePointer<AudioTimeStamp>!, buffer aBuffer: UnsafeMutableRawPointer!, size aBufferSize: UInt32) -> Int32
Parameters
unitId
The ID of the audio unit.
frameNums
The number of frames in the captured audio.
format
A pointer to the audio stream basic description.
timestamp
A pointer to the audio timestamp.
aBuffer
A pointer to the audio buffer.
aBufferSize
The size of the audio buffer.
Return Value
An integer indicating the result of the processing. If successful, the return value is 0. If fails, the return value is any other value.
-
Retrieves audio frames from the specified audio unit.
Declaration
Swift
public func getFrame(_ unitId: UInt32, frameNum frameNums: UInt32, format: UnsafeMutablePointer<AudioStreamBasicDescription>!, timestamp: UnsafePointer<AudioTimeStamp>!, buffer aBuffer: UnsafeMutableRawPointer!, size aBufferSize: UInt32) -> Int32
Parameters
unitId
The ID of the audio unit.
frameNums
The number of frames to retrieve.
format
A pointer to the audio stream basic description.
timestamp
A pointer to the audio timestamp.
aBuffer
A pointer to the buffer to store the retrieved frames.
aBufferSize
The size of the buffer in bytes.
Return Value
The size of the retrieved frames.