import wave
import click


def validate_wave(ctx, param, value):
    """
        Validate the wave file by trying to open it
        and checking that its got a single channel.

        :param ctx:<class 'click.core.Context'>
        :param param:<class 'click.core.Option'>
        :param value:str
        :return:<class 'wave.Wave_read'>
    """

    try:
        wave_read = wave.open(value)

        if wave_read.getnchannels() != 1:
            raise click.BadParameter('Only mono wave files are supported')

        return wave_read

    except wave.Error as e:
        raise click.BadParameter('Not a valid wave file. {}'.format(e.__str__()))