def _detect_leading_silence(sound, threshold=-40.0, chunk_size=10):
    """Detect silence at beginning of audio data.

    :param sound: pydub.AudioSegment.
    :param threshold: Silence threshold in dB. (Default: -40.0)
    :param chunk_size: Size of audio chunk in ms. (Default: 10)
    :return: Silence duration in ms.
    """

    # iterate over chunks until first one with sound
    trim_ms = 0
    while sound[trim_ms:trim_ms + chunk_size].dBFS < threshold:
        trim_ms += chunk_size

    return trim_ms