Converts a binary format language model, as generated by idngram2lm, into an an ARPA format language model.

def binlm2arpa(input_file, output_file, verbosity=2):
    """
        Converts a binary format language model, as generated by idngram2lm, into an an ARPA format language model.
    """
    cmd = ['binlm2arpa', '-binary', input_file,
                         '-arpa'. output_file]
    
    if verbosity:
        cmd.extend(['-verbosity', verbosity])
    
    # Ensure that every parameter is of type 'str'
    cmd = [str(x) for x in cmd]

    with tempfile.SpooledTemporaryFile() as output_f:
        with  output_to_debuglogger() as err_f:
            exitcode = subprocess.call(cmd, stdout=output_f, stderr=err_f)
        output = output_f.read()
    
    logger = logging.getLogger(__name__)
    logger.debug("Command '%s' returned with exit code '%d'." % (' '.join(cmd), exitcode))        

    if exitcode != 0:
        raise ConversionError("'%s' returned with non-zero exit status '%s'" % (cmd[0], exitcode))

    if sys.version_info >= (3,) and type(output) is bytes:
        output = output.decode('utf-8')

    return output.strip()