Skip to content

Add install script #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SRCDIR = kaldi-python
SRCDIR = kaldi_io

ifndef KALDI_ROOT
$(error please set KALDI_ROOT to point ot the base of the kaldi installation)
Expand Down
13 changes: 11 additions & 2 deletions README → README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
This is a set of Python wrappers for Kaldi input-output classes.
# This is a set of Python wrappers for Kaldi input-output classes.

## Installation

Simply run
```
./setup.py install
```

## Usage
It allows you to do e.g.:

```
In [1]: import kaldi_io
In [2]: feat_reader = kaldi_io.SequentialBaseFloatMatrixReader('scp:./mfcc/raw_mfcc_test.1.scp')
In [3]: next(feat_reader)
Expand All @@ -20,4 +29,4 @@ It allows you to do e.g.:
2.52763462]
[ 38.64388275 -29.08744812 -9.59657097 ..., -1.66973591 -0.54327661
9.77887821]])
```
11 changes: 5 additions & 6 deletions kaldi-python/kaldi_argparse.py → kaldi_argparse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'''
"""
Created on Aug 14, 2014

@author: chorows
'''
"""

import os
import sys
import argparse

#import __main__

class AddConfig(argparse.Action):
def __init__(self, *args, **kwargs):
Expand All @@ -17,7 +16,8 @@ def __init__(self, *args, **kwargs):
def __call__(self, parser, namespace, values, option_string=None):
with open(values,'r') as f:
opts = [l.split('#')[0].strip() for l in f]
parser.parse_args(args=opts, namespace=namespace)
parser.parse_args(args=opts, namespace=namespace)


class KaldiArgumentParser(argparse.ArgumentParser):
def __init__(self, *args, **kwargs):
Expand All @@ -44,8 +44,7 @@ def add_standard_arguments(self):
grp.add_argument('--print-args', type=bool, default=True, help='Print the command line arguments (to stderr)')
#grp.add_argument('--config', action=AddConfig, help='Configuration file with options')
grp.add_argument('--config', default=argparse.SUPPRESS, help='Configuration file with options')



def parse_known_args(self, args=None, namespace=None):
if args is None:
args = sys.argv[1:]
Expand Down
File renamed without changes.
12 changes: 7 additions & 5 deletions kaldi-python/kaldi_io.py → kaldi_io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''Python Wrappers for Kaldi table IO (:kaldi:`io.html`)
"""Python Wrappers for Kaldi table IO (:kaldi:`io.html`)

In Kaldi the archive does not carry information about its contents and the user is required to
use the proper Reader or Writer. This module follows this approach and provides wrappers for
Expand Down Expand Up @@ -232,13 +232,11 @@
| | | | |
+--------------------+---------------------+-----------------------+-----------------------+

'''

'''
Created on Jul 31, 2014

@author: chorows
'''
"""


import numpy as np
Expand Down Expand Up @@ -266,6 +264,7 @@
SequentialBaseFloatVectorReader = SequentialFloat32VectorReader
BaseFloatVectorWriter = Float32VectorWriter


def get_io_for_dtype(access, dtype, element=''):
'''
Get a writer or reader for the given dtype. eg:
Expand All @@ -280,7 +279,8 @@ def get_io_for_dtype(access, dtype, element=''):
'float32':'Float32',
'float64':'Float64'}
dtype = dtypemap[dtype]
return globals()[access + dtype + element]
return globals()[access + dtype + element]


class _Transformed(object):
def __init__(self, reader, transform_function, **kwargs):
Expand All @@ -290,6 +290,7 @@ def __init__(self, reader, transform_function, **kwargs):

def __getattr__(self, attr):
return getattr(self.reader,attr)


class TransRA(_Transformed):
def __init__(self, *args, **kwargs):
Expand All @@ -300,6 +301,7 @@ def value(self, key):

def __getitem__(self, key):
return self.value(key)


class TransSeq(_Transformed):
def __init__(self, *args, **kwargs):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python

import os
from distutils.core import setup
from distutils.command.build_py import build_py

class Make(build_py):
def run(self):
os.system("make")
build_py.run(self)

setup(name='kaldi-python',
version='1.0',
description='Python interface for kaldi iterators',
author='Jan Chorowski',
url='https://github.com/janchorowski/kaldi-python',
cmdclass={'build_py': Make},
packages=['kaldi_io', 'kaldi_argparse'],
package_data={'kaldi_io': ['kaldi_io_internal.so']},
scripts=['scripts/apply-global-cmvn.py',
'scripts/compute-global-cmvn-stats.py',
'scripts/copy-feats-padded.py',
'scripts/show-wav-ali.py'],
requires=['numpy'])