Skip to content

Commit 3f64b59

Browse files
authored
[doc] add tutorial for kaldi pybind IO. (#3986)
1 parent 61cda6b commit 3f64b59

20 files changed

+928
-13
lines changed

src/pybind/.clang-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Run manually to reformat a file:
2+
# clang-format -i --style=file <file>
3+
BasedOnStyle: Google
4+
DerivePointerAlignment: false

src/pybind/doc/conf.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,25 @@
1818
# otherwise `import` will throw.
1919
import sphinx_rtd_theme
2020

21-
22-
2321
# -- Project information -----------------------------------------------------
2422

2523
project = 'Kaldi Pybind'
26-
copyright = '2020, Kaldi Pybind Authors'
24+
copyright = '2019-2020, Kaldi Pybind Authors'
2725
author = 'Kaldi Pybind Authors'
2826

29-
3027
# -- General configuration ---------------------------------------------------
3128

3229
# Add any Sphinx extension module names here, as strings. They can be
3330
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3431
# ones.
3532
extensions = [
36-
'sphinx.ext.autodoc',
37-
'sphinx.ext.autosummary',
38-
'sphinx.ext.mathjax',
39-
'sphinx.ext.napoleon',
40-
'sphinx.ext.todo',
41-
'sphinx.ext.viewcode',
33+
'sphinx.ext.autodoc',
34+
'sphinx.ext.autosummary',
35+
'sphinx.ext.mathjax',
36+
'sphinx.ext.napoleon',
37+
'sphinx.ext.todo',
38+
'sphinx.ext.viewcode',
39+
'sphinx.ext.githubpages',
4240
]
4341

4442
# Add any paths that contain templates here, relative to this directory.
@@ -60,7 +58,6 @@
6058
# The name of the Pygments (syntax highlighting) style to use.
6159
pygments_style = 'sphinx'
6260

63-
6461
# -- Options for HTML output -------------------------------------------------
6562

6663
# The theme to use for HTML and HTML Help pages. See the documentation for

src/pybind/doc/getting_started.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from
1515

1616
Kaldi Pybind is still under active development and has not
1717
yet been merged into the master branch. You should checkout
18-
the `pybind11` branch before compilation.
18+
the ``pybind11`` branch before compilation.
1919

2020
.. Note::
2121

@@ -40,3 +40,15 @@ The following is a quick start:
4040
make
4141
make test
4242
43+
After a successful compilation, you have to modify the environment
44+
variable ``PYTHONPATH``:
45+
46+
.. code-block:: bash
47+
48+
export KALDI_ROOT=/path/to/your/kaldi
49+
export PYTHONPATH=$KALDI_ROOT/src/pybind:$PYTHONPATH
50+
51+
.. HINT::
52+
53+
There is no ``make install``. Once compiled, you are ready to
54+
use Kaldi Pybind.

src/pybind/doc/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ Welcome to Kaldi Pybind's documentation!
1818

1919
introduction
2020
getting_started
21+
22+
.. toctree::
23+
:maxdepth: 1
24+
:caption: Tutorial
25+
26+
tutorial/working_with_kaldi_matrices
27+
tutorial/working_with_kaldi_io

src/pybind/doc/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ About Kaldi Pybind
1010

1111
Kaldi Pybind is a Python wrapper for Kaldi
1212
using `Pybind11 <https://github.com/pybind/pybind11>`_.
13+
It is still under active development.
1314

14-
Kaldi Pybind is still under active development.
1515
Everything related to Kaldi Pybind is put in the
1616
`pybind11 branch <https://github.com/kaldi-asr/kaldi/tree/pybind11>`_.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python3
2+
3+
import kaldi
4+
5+
f = kaldi.FloatMatrix(2, 3)
6+
f[1, 2] = 100
7+
print(f)
8+
9+
g = f.numpy()
10+
g[0, 0] = 200
11+
print(f)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python3
2+
3+
import kaldi
4+
import numpy as np
5+
6+
m = np.array([[1, 2, 3], [10, 20, 30]], dtype=np.float32)
7+
f = kaldi.FloatSubMatrix(m)
8+
9+
f[1, 2] = 100
10+
print(m)
11+
print()
12+
13+
g = f.numpy()
14+
g[0, 0] = 200
15+
print(m)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
3+
import kaldi
4+
import numpy as np
5+
6+
v = np.array([10, 20, 30], dtype=np.float32)
7+
f = kaldi.FloatSubVector(v)
8+
9+
f[0] = 0
10+
print(v)
11+
12+
g = f.numpy()
13+
g[1] = 100
14+
print(v)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python3
2+
3+
import kaldi
4+
5+
f = kaldi.FloatVector(3)
6+
f[0] = 10
7+
print(f)
8+
9+
g = f.numpy()
10+
g[1] = 20
11+
print(f)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
3+
import kaldi
4+
5+
wspecifier = 'ark,scp:/tmp/ali.ark,/tmp/ali.scp'
6+
7+
writer = kaldi.IntVectorWriter(wspecifier)
8+
writer.Write(key='foo', value=[1, 2, 3])
9+
writer.Write('bar', [10, 20])
10+
writer.Close()
11+
12+
rspecifier = 'scp:/tmp/ali.scp'
13+
reader = kaldi.SequentialIntVectorReader(rspecifier)
14+
15+
for key, value in reader:
16+
print(key, value)
17+
18+
reader.Close()
19+
20+
reader = kaldi.RandomAccessIntVectorReader(rspecifier)
21+
value1 = reader['foo']
22+
print(value1)
23+
24+
value2 = reader['bar']
25+
print(value2)
26+
reader.Close()

0 commit comments

Comments
 (0)