Commit ae40b7cb authored by Vinit Veera's avatar Vinit Veera
Browse files

Checking for nan and inf

parent 023b26b7
Loading
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -134,8 +134,12 @@ def bs1770demo(
        result = run(cmd, logger=logger)

        # parse output
        measured_loudness = float(result.stdout.splitlines()[3].split(":")[1])
        scale_factor = float(result.stdout.splitlines()[-3].split(":")[1])
        measured_loudness = check_for_nan_and_inf(
            result.stdout.splitlines()[3].split(":")[1]
        )
        scale_factor = check_for_nan_and_inf(
            result.stdout.splitlines()[-3].split(":")[1]
        )

    return measured_loudness, scale_factor

@@ -289,3 +293,20 @@ def scale_files(

            # write into file
            write(file, scaled_audio, audio_obj.fs)


def check_for_nan_and_inf(input_string: str):
    """
    Checks the input string for nan and inf

    Parameters
    ----------
    input_string: str
        Input string
    """
    if "nan" in input_string.lower():
        raise ValueError("Too quiet.")
    elif "inf" in input_string.lower():
        raise ValueError("All zeros.")
    else:
        return float(input_string)