SinchAudioController

public final class SinchAudioController

The SinchAudioController provides methods for controlling audio related functionality, e.g. enabling the speaker, muting the microphone, and playing sound files.

Playing Sound Files

The audio controller provides a convenience method (startPlayingSoundFile:looping:) for playing sounds that are related to a call, such as ring tones and busy tones.

Example

let audio = client.audioController
let soundPath = Bundle.main.path(forResource: "ringtone", ofType: "wav")
do {
  try audio.startPlayingSoundFile(withPath:soundPath, looping:true)
} catch {
  ...
}

Applications that prefer to use their own code for playing sounds are free to do so, but they should follow a few guidelines related to audio session categories and audio session activation/deactivation (see Sinch SDK User Guide for details).

Sound File Format

The sound file must be a mono (1 channel), 16-bit, uncompressed (PCM) .wav file with a sample rate of 8kHz, 16kHz, or 32kHz.

  • The object that acts as the delegate of the audio controller.

    The delegate object handles audio related state changes.

    Declaration

    Swift

    public weak var delegate: SinchAudioControllerDelegate? { get set }
  • Use this method to override the default AVAudioSessionCategoryOptions that will be set for the duration of phone calls. The selected options will be set for each call starting after the method invocation.

    Declaration

    Swift

    public func setAudioSessionCategoryOptions(_ options: AVAudioSession.CategoryOptions)
  • Mute the microphone.

    Declaration

    Swift

    public func mute()
  • Unmute the microphone.

    Declaration

    Swift

    public func unmute()
  • Route the call audio through the speaker.

    Note that if this method is invoked at a moment when no established call exists, the current AVAudioSession configuration might be affected.

    This method will affect AVAudioSessionCategoryOptions during the calls even if custom options have been set via SINAudioController.setAudioSessionCategoryOptions(_:).

    Declaration

    Swift

    public func enableSpeaker()
  • Route the call audio through the handset earpiece.

    Note that if this method is invoked at a moment when no established call exists, the current AVAudioSession configuration might be affected.

    This method will affect AVAudioSessionCategoryOptions during the calls even if custom options have been set via SINAudioController.setAudioSessionCategoryOptions(_:).

    Declaration

    Swift

    public func disableSpeaker()
  • Play a sound file, for the purpose of playing ringtones, etc.

    This is a simple convenience method for playing sounds associated with a call, such as ringtones. It can only play one sound file at a time.

    Note that if your app integrates with CallKit, the preferred way to specify the ringtone for an incoming audio call is via ringtoneSound property of CXProviderConfiguration.

    For advanced audio, apps that use the SDK should implement their own methods for playing sounds.

    Regardless of whether a sound is looping or not, a corresponding call to the stopPlayingSoundFile method must be done at some point after each invocation of this method.

    Invoking this method could modify AVAudioSession current configuration to route audio to the speakers.

    The sound file must be a mono (1 channel), 16-bit, uncompressed (PCM) .wav file with a sample rate of 8kHz, 16kHz, or 32kHz.

    Throws

    if no file exists at the given path

    Declaration

    Swift

    public func startPlayingSoundFile(withPath path: String?, looping: Bool) throws

    Parameters

    path

    Full path for the sound file to play

    looping

    Specifies whether the sound should loop or not

  • Stop playing the sound file.

    Declaration

    Swift

    public func stopPlayingSoundFile()
  • Configure the audio session for an incoming CallKit call.

    Important

    This method should be invoked before the CXAnswerCallAction is fulfilled.

    Declaration

    Swift

    public func configureAudioSessionForCallKitCall()