def test_read_write_wav(tmpdir, func, dtype):
    path = tmpdir.mkdir('test')
    ark = path.join('a.ark').strpath
    scp = path.join('a.scp').strpath

    # Write as pcm16
    array = np.random.randint(0, 10, 10, dtype=dtype)
    array2 = np.random.randint(0, 10, 10, dtype=dtype)
    d = {'utt': (8000, array), 'utt2': (8000, array2)}
    save_ark(ark, d, scp=scp)

    d = dict(func(scp))
    rate, test = d['utt']
    assert rate == 8000
    np.testing.assert_array_equal(array, test)

    rate, test = d['utt2']
    assert rate == 8000
    np.testing.assert_array_equal(array2, test)

    d = dict(load_ark(ark))
    rate, test = d['utt']
    assert rate == 8000
    np.testing.assert_array_equal(array, test)

    rate, test = d['utt2']
    assert rate == 8000
    np.testing.assert_array_equal(array2, test)
Exemple #2
0
def test_wavark_stream(tmpdir, dtype, write_function):
    path = tmpdir.mkdir("test")
    ark = path.join("a.ark").strpath

    # Write as pcm16
    array = np.random.randint(-1000, 1000, 100).astype(np.double) / abs(
        np.iinfo(np.int16).min)
    array2 = np.random.randint(-1000, 1000, 100).astype(np.double) / abs(
        np.iinfo(np.int16).min)
    if write_function == "numpy":
        d = {"utt": array, "utt2": array2}
    else:
        d = {"utt": (8000, array), "utt2": (8000, array2)}
    save_ark(ark, d, write_function=write_function)

    with open_like_kaldi("cat {}|".format(ark), "rb") as f:
        d = dict(load_ark(f))
        if write_function == "numpy":
            test = d["utt"]
        else:
            rate, test = d["utt"]
            assert rate == 8000
        np.testing.assert_allclose(array, test)

        if write_function == "numpy":
            test = d["utt2"]
        else:
            rate, test = d["utt2"]
            assert rate == 8000
        np.testing.assert_allclose(array2, test)
Exemple #3
0
def test_read_write_wav(tmpdir, func, dtype):
    path = tmpdir.mkdir("test")
    ark = path.join("a.ark").strpath
    scp = path.join("a.scp").strpath

    # Write as pcm16
    array = np.random.randint(0, 10, 10, dtype=dtype)
    array2 = np.random.randint(0, 10, 10, dtype=dtype)
    d = {"utt": (8000, array), "utt2": (8000, array2)}
    save_ark(ark, d, scp=scp)

    d = dict(func(scp))
    rate, test = d["utt"]
    assert rate == 8000
    np.testing.assert_array_equal(array, test)

    rate, test = d["utt2"]
    assert rate == 8000
    np.testing.assert_array_equal(array2, test)

    d = dict(load_ark(ark))
    rate, test = d["utt"]
    assert rate == 8000
    np.testing.assert_array_equal(array, test)

    rate, test = d["utt2"]
    assert rate == 8000
    np.testing.assert_array_equal(array2, test)
Exemple #4
0
def test_read_helper(tmpdir):
    path = tmpdir.strpath
    array_in = numpy.random.randn(10, 10)
    save_ark("{}/feats.ark".format(path), {"foo": array_in},
             scp="{}/feats.scp".format(path))
    helper = ReadHelper("ark:cat {}/feats.ark |".format(path))
    for uttid, array_out in helper:
        assert uttid == "foo"
        numpy.testing.assert_array_equal(array_in, array_out)

    helper = ReadHelper("scp:{}/feats.scp".format(path))
    for uttid, array_out in helper:
        assert uttid == "foo"
        numpy.testing.assert_array_equal(array_in, array_out)
def test_read_helper(tmpdir):
    path = tmpdir.strpath
    array_in = numpy.random.randn(10, 10)
    save_ark('{}/feats.ark'.format(path), {'foo': array_in},
             scp='{}/feats.scp'.format(path))
    helper = ReadHelper('ark:cat {}/feats.ark |'.format(path))
    for uttid, array_out in helper:
        assert uttid == 'foo'
        numpy.testing.assert_array_equal(array_in, array_out)

    helper = ReadHelper('scp:{}/feats.scp'.format(path))
    for uttid, array_out in helper:
        assert uttid == 'foo'
        numpy.testing.assert_array_equal(array_in, array_out)
Exemple #6
0
    def __call__(self, key, array):
        if self.closed:
            raise RuntimeError("WriteHelper has been already closed")
        save_ark(
            self.fark,
            {key: array},
            scp=self.fscp,
            text=self.text,
            compression_method=self.compression_method,
            write_function=self.write_function,
        )

        if self.flush:
            if self.fark is not None:
                self.fark.flush()
            if self.fscp is not None:
                self.fscp.flush()
Exemple #7
0
def test_read_write(tmpdir, func, dtype, write_function):
    path = tmpdir.mkdir("test")
    ark = path.join("a.ark").strpath
    scp = path.join("a.scp").strpath

    # Write as pcm16
    array = np.random.randint(-1000, 1000, 100).astype(np.double) / float(
        abs(np.iinfo(np.int16).min))
    array2 = np.random.randint(-1000, 1000, 100).astype(np.double) / abs(
        np.iinfo(np.int16).min)

    if write_function == "numpy":
        d = {"utt": array, "utt2": array2}
    else:
        d = {"utt": (8000, array), "utt2": (8000, array2)}
    save_ark(ark, d, scp=scp, write_function=write_function)

    d = dict(func(scp))
    if write_function == "numpy":
        test = d["utt"]
    else:
        rate, test = d["utt"]
        assert rate == 8000
    np.testing.assert_allclose(array, test)

    if write_function == "numpy":
        test = d["utt2"]
    else:
        rate, test = d["utt2"]
        assert rate == 8000
    np.testing.assert_allclose(array2, test)

    d = dict(load_ark(ark))
    if write_function == "numpy":
        test = d["utt"]
    else:
        rate, test = d["utt"]
        assert rate == 8000
    np.testing.assert_allclose(array, test)

    if write_function == "numpy":
        test = d["utt2"]
    else:
        rate, test = d["utt2"]
        assert rate == 8000
    np.testing.assert_allclose(array2, test)
def test_wavark_stream(tmpdir, dtype):
    path = tmpdir.mkdir('test')
    ark = path.join('a.ark').strpath

    # Write as pcm16
    array = np.random.randint(0, 10, 10, dtype=dtype)
    array2 = np.random.randint(0, 10, 10, dtype=dtype)
    d = {'utt': (8000, array), 'utt2': (8000, array2)}
    save_ark(ark, d)

    with open_like_kaldi('cat {}|'.format(ark), 'rb') as f:
        d = dict(load_ark(f))
        rate, test = d['utt']
        assert rate == 8000
        np.testing.assert_array_equal(array, test)

        rate, test = d['utt2']
        assert rate == 8000
        np.testing.assert_array_equal(array2, test)
Exemple #9
0
def test_wavark_stream(tmpdir, dtype):
    path = tmpdir.mkdir("test")
    ark = path.join("a.ark").strpath

    # Write as pcm16
    array = np.random.randint(0, 10, 10, dtype=dtype)
    array2 = np.random.randint(0, 10, 10, dtype=dtype)
    d = {"utt": (8000, array), "utt2": (8000, array2)}
    save_ark(ark, d)

    with open_like_kaldi("cat {}|".format(ark), "rb") as f:
        d = dict(load_ark(f))
        rate, test = d["utt"]
        assert rate == 8000
        np.testing.assert_array_equal(array, test)

        rate, test = d["utt2"]
        assert rate == 8000
        np.testing.assert_array_equal(array2, test)