wait for answer machineΒΆ

class UASCallChannel
wait_for_answer_machine(milliseconds_min_beep_duration=180, milliseconds_post_beep_silence=1000, milliseconds_no_beep_silence=4000, seconds_timeout=10)

Wait until an answering machine is ready to record.

Optional argument:
  • milliseconds_min_beep_duration

    the minimum duration of a beep for it to be recognised. Default value is 180ms.

  • milliseconds_post_beep_silence

    the period of silence after a beep. Default value is 1000ms.

  • milliseconds_no_beep_silence

    the period of silence without a beep Default value is 4000ms.

  • seconds_timeout

    the amount of time allocated to wait for the answer machine to be ready. None means no timeout. Default is 10 seconds.

This function looks for a combination of beeps and silence to identify a suitable moment at which to begin playing a file to an answering machine. Further details on playing files are available here.

This function should only be used when the far end has been identified as an answering machine, for more information on this go here.

The default values for this function will cause it to return True if one of the following is true:

  • A beep at least 180 milliseconds long is followed by a 1000 millisecond silence.

  • An uninterrupted 4000 millisecond silence is heard.

If neither of the above is true within the seconds_timeout limit, this function will return False.

If the call state is IDLE, this function will raise a Hangup exception. If the call state is not IDLE but also not ANSWERED, this function will raise an Error exception.

This function will block until confirmation has been received that the answer machine is ready to record or a timeout has expired.

Usage example:

state = channel.call('sip:1234@127.0.0.1:5060;user=phone'
                      live_speaker_detect=channel.LiveSpeakerDetectionSettings.DEFAULT)
if state == channel.State.ANSWERED:
    # might be an answer machine
    if channel.Details.far_end_type == channel.CallFarEndType.ANSWER_MACHINE:
        # play a message to the answer machine
        if channel.wait_for_answer_machine() is True:
            cause = channel.FilePlayer.play('my_message')
            # NOTE: the file to play must not have any leading silence
            #       as the answer machine may hang up the call on silence
            #       detection, it is up to the user to trim leading silence.

Upon success, this function will return True, else False.