diff --git a/Makefile b/Makefile index 20c531d..a80ec98 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/README b/README.md similarity index 85% rename from README rename to README.md index faa4e01..16c1976 100644 --- a/README +++ b/README.md @@ -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) @@ -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]]) - +``` diff --git a/kaldi-python/kaldi_argparse.py b/kaldi_argparse/__init__.py similarity index 96% rename from kaldi-python/kaldi_argparse.py rename to kaldi_argparse/__init__.py index a771734..b7f7ad4 100644 --- a/kaldi-python/kaldi_argparse.py +++ b/kaldi_argparse/__init__.py @@ -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): @@ -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): @@ -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:] diff --git a/kaldi-python/Makefile b/kaldi_io/Makefile similarity index 100% rename from kaldi-python/Makefile rename to kaldi_io/Makefile diff --git a/kaldi-python/kaldi_io.py b/kaldi_io/__init__.py similarity index 99% rename from kaldi-python/kaldi_io.py rename to kaldi_io/__init__.py index 4ce731b..744145c 100644 --- a/kaldi-python/kaldi_io.py +++ b/kaldi_io/__init__.py @@ -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 @@ -232,13 +232,11 @@ | | | | | +--------------------+---------------------+-----------------------+-----------------------+ -''' -''' Created on Jul 31, 2014 @author: chorows -''' +""" import numpy as np @@ -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: @@ -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): @@ -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): @@ -300,6 +301,7 @@ def value(self, key): def __getitem__(self, key): return self.value(key) + class TransSeq(_Transformed): def __init__(self, *args, **kwargs): diff --git a/kaldi-python/bp_converters.h b/kaldi_io/bp_converters.h similarity index 100% rename from kaldi-python/bp_converters.h rename to kaldi_io/bp_converters.h diff --git a/kaldi-python/kaldi_io_internal.cpp b/kaldi_io/kaldi_io_internal.cpp similarity index 100% rename from kaldi-python/kaldi_io_internal.cpp rename to kaldi_io/kaldi_io_internal.cpp diff --git a/kaldi-python/python_wrappers.h b/kaldi_io/python_wrappers.h similarity index 100% rename from kaldi-python/python_wrappers.h rename to kaldi_io/python_wrappers.h diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..870d979 --- /dev/null +++ b/setup.py @@ -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'])