<commit_before>import numpy as np

from _alsa import card_name, card_indexes, asoundlib_version
from _alsa import Device, AlsaException

def play(input, samplerate = 48000):
    if input.ndim == 1:
        n = input.size
        nc = 1
    elif input.ndim == 2:
        n, nc = input.shape
    else:
        raise ValueError("Only ndim 1 or 2 supported")

    try:
        dev = Device(samplerate = samplerate, channels = nc)

        assert nc == dev.channels
        assert input.dtype == np.float32 or input.dtype == np.float64

        dev.play_short((16384 * input).astype(np.int16))
    except AlsaException, e:
        raise IOError(str(e))

if __name__ == '__main__':
    print "Asoundlib version is", asoundlib_version()
    for i in card_indexes():
        print card_name(i)

    dev = Device()<commit_msg>Check input dtype before creating pcm device.<commit_after>import numpy as np

from _alsa import card_name, card_indexes, asoundlib_version
from _alsa import Device, AlsaException

def play(input, samplerate = 48000):
    if input.ndim == 1:
        n = input.size
        nc = 1
    elif input.ndim == 2:
        n, nc = input.shape
    else:
        raise ValueError("Only ndim 1 or 2 supported")

    if not input.dtype in (np.float32, np.float64):
        raise ValueError("input should be array of float32 or float64 !")

    try:
        dev = Device(samplerate = samplerate, channels = nc)
        dev.play_short((16384 * input).astype(np.int16))
    except AlsaException, e:
        raise IOError(str(e))

if __name__ == '__main__':
    print "Asoundlib version is", asoundlib_version()
    for i in card_indexes():
        print card_name(i)

    dev = Device()
{'fraction_non_alphanumeric': 0.0983995257854179, 'fraction_numerical': 0.027267338470657973, 'mean_word_length': 2.7427937915742793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2865039', 'n_tokens_mistral': 580, 'n_tokens_neox': 540, 'n_words': 167}