returnn.sprint.cache#

This module is about reading (maybe later also writing) the Sprint archive format.

class returnn.sprint.cache.FileInfo(name, pos, size, compressed, index)[source]#

File info.

Parameters:
  • name (str) –

  • pos (int) –

  • size (int) –

  • compressed (bool|int) –

  • index (int) –

class returnn.sprint.cache.FileArchive(filename, must_exists=True, encoding='ascii')[source]#

File archive.

read_u32()[source]#
Return type:

int

read_U32()[source]#
Return type:

int

read_U8()[source]#
Return type:

int

read_packed_U32()[source]#
Return type:

int

read_u64()[source]#
Return type:

int

read_char()[source]#
Return type:

int

read_bytes(length)[source]#
Parameters:

length (int) –

Return type:

bytes

read_str(length, encoding='ascii')[source]#
Parameters:
  • length (int) –

  • encoding (str) –

Return type:

str

read_S16()[source]#
Return type:

float

read_f32()[source]#
Return type:

float

read_f64()[source]#
Return type:

float

read_v(typ, size)[source]#
Parameters:
  • typ (str) – “f” for float (float32) or “d” for double (float64)

  • size (int) – number of elements to return

Returns:

numpy array of shape (size,) of dtype depending on typ

Return type:

numpy.ndarray

write_str(s, enc='ascii')[source]#
Parameters:
  • s (str) –

  • enc (str) –

Return type:

int

write_char(i)[source]#
Parameters:

i (int) –

Return type:

int

write_u32(i)[source]#
Parameters:

i (int) –

Return type:

int

write_U32(i)[source]#
Parameters:

i (int) –

Return type:

int

write_u64(i)[source]#
Parameters:

i (int) –

Return type:

int

write_f32(i)[source]#
Parameters:

i (float) –

Return type:

int

write_f64(i)[source]#
Parameters:

i (float) –

Return type:

int

SprintCacheHeader = 'SP_ARC1\x00'[source]#
start_recovery_tag = 2857740885[source]#
end_recovery_tag = 1437226410[source]#
file_list()[source]#
Return type:

list[str]

finalize()[source]#

Finalize.

read_file_info_table()[source]#

Read file info table.

write_file_info_table()[source]#

Write file info table.

scan_archive()[source]#

Scan archive.

has_entry(filename)[source]#
Parameters:

filename (str) – argument for self.read()

Returns:

True if we have this entry

read(filename, typ)[source]#
Parameters:
  • filename (str) – the entry-name in the archive

  • typ (str) – “str”, “feat” or “align”

Returns:

depending on typ, “str” -> string, “feat” -> (time, data), “align” -> align, where string is a str, time is list of time-stamp tuples (start-time,end-time) in millisecs,

data is a list of features, each a numpy vector,

align is a list of (time, allophone, state, weight), time is an int from 0 to len of align,

allophone is some int, state is e.g. in [0,1,2].

Return type:

str|(list[numpy.ndarray],list[numpy.ndarray])|list[(int,int,int,float)]

get_state(mix)[source]#
Parameters:

mix (int) –

Returns:

(mix, state)

Return type:

(int,int)

set_allophones(f)[source]#
Parameters:

f (str) – allophone filename. line-separated. will ignore lines starting with “#”

get_allophones_list() List[str][source]#
Returns:

list of allophones

add_feature_cache(filename, features, times)[source]#
Parameters:
  • filename (str) –

  • features

  • times

add_attributes(filename, dim, duration)[source]#
Parameters:
  • filename (str) –

  • dim (int) –

  • duration (float) –

class returnn.sprint.cache.FileArchiveBundle(filename=None, encoding='ascii')[source]#

File archive bundle.

Parameters:
  • filename (str|None) – .bundle file

  • encoding (str) – encoding used in the files

add_bundle(filename, encoding='ascii')[source]#
Parameters:
  • filename (str) – bundle

  • encoding (str) –

add_archive(filename, encoding='ascii')[source]#
Parameters:
  • filename (str) – single archive

  • encoding (str) –

add_bundle_or_archive(filename, encoding='ascii')[source]#
Parameters:
  • filename (str) –

  • encoding (str) –

file_list()[source]#
Return type:

list[str]

Returns:

list of content-filenames (which can be used for self.read())

has_entry(filename)[source]#
Parameters:

filename (str) – argument for self.read()

Returns:

True if we have this entry

read(filename, typ)[source]#
Parameters:
  • filename (str) – the entry-name in the archive

  • typ (str) – “str”, “feat” or “align”

Returns:

depending on typ, “str” -> string, “feat” -> (time, data), “align” -> align, where string is a str, time is list of time-stamp tuples (start-time,end-time) in millisecs,

data is a list of features, each a numpy vector,

align is a list of (time, allophone, state, weight), time is an int from 0 to len of align,

allophone is some int, state is e.g. in [0,1,2].

Return type:

str|(list[numpy.ndarray],list[numpy.ndarray])|list[(int,int,int,float)]

Uses FileArchive.read().

set_allophones(filename)[source]#
Parameters:

filename (str) – allophone filename

get_allophones_list() List[str][source]#
Returns:

list of allophones

returnn.sprint.cache.open_file_archive(archive_filename, must_exists=True, encoding='ascii')[source]#
Parameters:
  • archive_filename (str) –

  • must_exists (bool) –

  • encoding (str) –

Return type:

FileArchiveBundle|FileArchive

returnn.sprint.cache.is_sprint_cache_file(filename)[source]#
Parameters:

filename (str) – file to check. must exist

Returns:

True iff this is a sprint cache (which can be loaded with open_file_archive())

Return type:

bool

class returnn.sprint.cache.AllophoneLabeling(silence_phone, allophone_file, phoneme_file=None, state_tying_file=None, verbose_out=None)[source]#

Allophone labeling.

Parameters:
  • silence_phone (str) – e.g. “si”

  • allophone_file (str) – list of allophones

  • phoneme_file (str|None) – list of phonemes

  • state_tying_file (str|None) – allophone state tying (e.g. via CART). maps each allophone state to a class label

  • verbose_out (file) – stream to dump log messages

get_label_idx_by_allo_state_idx(allo_state_idx)[source]#
Parameters:

allo_state_idx (int) –

Return type:

int

get_label_idx(allo_idx, state_idx)[source]#
Parameters:
  • allo_idx (int) –

  • state_idx (int) –

Return type:

int

class returnn.sprint.cache.MixtureSet(filename)[source]#

Mixture set.

Parameters:

filename (str) –

read_u32()[source]#
Return type:

int

read_U32()[source]#
Return type:

int

read_u64()[source]#
Return type:

int

read_char()[source]#
Return type:

int

read_str(length, encoding='ascii')[source]#
Parameters:
  • length (int) –

  • encoding (str) –

Return type:

str

read_f32()[source]#
Return type:

float

read_f64()[source]#
Return type:

float

read_v(size, a)[source]#
Parameters:
  • size (int) –

  • a (array.array) –

Return type:

array.array

write(filename)[source]#
Parameters:

filename (str) –

get_mean_by_idx(idx)[source]#
Parameters:

idx (int) –

Return type:

numpy.ndarray

get_cov_by_idx(idx)[source]#
Parameters:

idx (int) –

Return type:

numpy.ndarray

get_number_mixtures()[source]#
Return type:

int

class returnn.sprint.cache.WordBoundaries(filename)[source]#

Word boundaries.

Parameters:

filename (str) –

read_u16()[source]#
Return type:

int

read_u32()[source]#
Return type:

int

read_str(length, encoding='ascii')[source]#
Parameters:
  • length (int) –

  • encoding (str) –

Return type:

str

returnn.sprint.cache.main()[source]#

Main entry for usage as a tool.