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

    The vpioEnabled property is always true because the voice processing I/O is always enabled. The voice processing I/O is always enabled in the PlanetKitAudioMicSpk class. If you want to disable the voice processing I/O, you should use the PlanetKitAudioMic and PlanetKitAudioSpk class directly.

    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 or PlanetKitConference 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’s didCapture(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 or PlanetKitConference 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’s willPlay(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 of AVAudioSession will be changed to the configuration of PlanetKitAudio.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 of AVAudioSession will be changed to the configuration of PlanetKitAudio.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.

    Declaration

    Swift

    public var isSpeakerOut: Bool { get }
  • 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

    public func speakerOut(_ out: Bool)
  • Sets the category and options for the audio session.

    Declaration

    Swift

    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.

  • Sets the mode for the audio session.

    Declaration

    Swift

    public func setMode(_ mode: AVAudioSession.Mode)

    Parameters

    mode

    The mode of the audio session.

  • Sets the preferred audio route for the speaker playback.

    Declaration

    Swift

    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 to PlanetKitAudio.shared.micDevice.
  • Represents the currently used speaker device.

    Remark

    This property is reflected identically to PlanetKitAudio.shared.spkDevice.
  • Provides device type information to PlanetKit, indicating if it is a real device or a virtual device.

    Remark

    The value of the isVirtualDevice property is always false.

    See

    PlanetKitAudioMicControllable, PlanetKitAudioSpkControllable`

    Declaration

    Swift

    public var isVirtualDevice: Bool { get }

Setup Delegate

Play File

  • 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)

PlanetAudioPlayerDelegate

  • 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.

PlanetAudioUnitTargetDelegate

  • 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.

PlanetAudioUnitSourceDelegate

  • 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.