当前位置: 首页>>代码示例>>Python>>正文


Python kaldiio.WriteHelper方法代码示例

本文整理汇总了Python中kaldiio.WriteHelper方法的典型用法代码示例。如果您正苦于以下问题:Python kaldiio.WriteHelper方法的具体用法?Python kaldiio.WriteHelper怎么用?Python kaldiio.WriteHelper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kaldiio的用法示例。


在下文中一共展示了kaldiio.WriteHelper方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import kaldiio [as 别名]
# 或者: from kaldiio import WriteHelper [as 别名]
def __init__(
        self, wspecifier, write_num_frames=None, compress=False, compression_method=2
    ):
        if compress:
            self.writer = kaldiio.WriteHelper(
                wspecifier, compression_method=compression_method
            )
        else:
            self.writer = kaldiio.WriteHelper(wspecifier)
        self.writer_scp = None
        if write_num_frames is not None:
            self.writer_nframe = get_num_frames_writer(write_num_frames)
        else:
            self.writer_nframe = None 
开发者ID:espnet,项目名称:espnet,代码行数:16,代码来源:cli_writers.py

示例2: feats_scp

# 需要导入模块: import kaldiio [as 别名]
# 或者: from kaldiio import WriteHelper [as 别名]
def feats_scp(tmp_path):
    p = tmp_path / "feats.scp"
    p2 = tmp_path / "feats.ark"
    with kaldiio.WriteHelper(f"ark,scp:{p2},{p}") as w:
        w["a"] = np.random.randn(100, 80)
        w["b"] = np.random.randn(150, 80)
    return str(p) 
开发者ID:espnet,项目名称:espnet,代码行数:9,代码来源:test_iterable_dataset.py

示例3: test_load_inputs_and_targets_legacy_format

# 需要导入模块: import kaldiio [as 别名]
# 或者: from kaldiio import WriteHelper [as 别名]
def test_load_inputs_and_targets_legacy_format(tmpdir):
    # batch = [("F01_050C0101_PED_REAL",
    #          {"input": [{"feat": "some/path.ark:123"}],
    #           "output": [{"tokenid": "1 2 3 4"}],
    ark = str(tmpdir.join("test.ark"))
    scp = str(tmpdir.join("test.scp"))

    desire_xs = []
    desire_ys = []
    with kaldiio.WriteHelper("ark,scp:{},{}".format(ark, scp)) as f:
        for i in range(10):
            x = np.random.random((100, 100)).astype(np.float32)
            uttid = "uttid{}".format(i)
            f[uttid] = x
            desire_xs.append(x)
            desire_ys.append(np.array([1, 2, 3, 4]))

    batch = []
    with open(scp, "r") as f:
        for line in f:
            uttid, path = line.strip().split()
            batch.append(
                (
                    uttid,
                    {
                        "input": [{"feat": path, "name": "input1"}],
                        "output": [{"tokenid": "1 2 3 4", "name": "target1"}],
                    },
                )
            )

    load_inputs_and_targets = LoadInputsAndTargets()
    xs, ys = load_inputs_and_targets(batch)
    for x, xd in zip(xs, desire_xs):
        np.testing.assert_array_equal(x, xd)
    for y, yd in zip(ys, desire_ys):
        np.testing.assert_array_equal(y, yd) 
开发者ID:espnet,项目名称:espnet,代码行数:39,代码来源:test_utils.py

示例4: test_load_inputs_and_targets_legacy_format

# 需要导入模块: import kaldiio [as 别名]
# 或者: from kaldiio import WriteHelper [as 别名]
def test_load_inputs_and_targets_legacy_format(self):
    # batch = [("F01_050C0101_PED_REAL",
    #          {"input": [{"feat": "some/path.ark:123"}],
    #           "output": [{"tokenid": "1 2 3 4"}],

    tmpdir = Path(tempfile.mkdtemp())
    ark = str(tmpdir.joinpath('test.ark'))
    scp = str(tmpdir.joinpath('test.scp'))

    desire_xs = []
    desire_ys = []
    with kaldiio.WriteHelper('ark,scp:{},{}'.format(ark, scp)) as f:
      for i in range(10):
        x = np.random.random((100, 100)).astype(np.float32)
        uttid = 'uttid{}'.format(i)
        f[uttid] = x
        desire_xs.append(x)
        desire_ys.append(np.array([1, 2, 3, 4]))

    batch = []
    with open(scp, 'r') as f:
      for line in f:
        uttid, path = line.strip().split()
        batch.append((uttid, {
            'input': [{
                'feat': path,
                'name': 'input1'
            }],
            'output': [{
                'tokenid': '1 2 3 4',
                'name': 'target1'
            }]
        }))

    logging.info("kaldi meta: {}".format(batch[0]))
    load_inputs_and_targets = LoadInputsAndTargets()
    xs, ys = load_inputs_and_targets(batch)
    for x, xd in zip(xs, desire_xs):
      self.assertAllEqual(x, xd)
    for y, yd in zip(ys, desire_ys):
      self.assertAllEqual(y, yd) 
开发者ID:didi,项目名称:delta,代码行数:43,代码来源:espnet_utils_test.py

示例5: __init__

# 需要导入模块: import kaldiio [as 别名]
# 或者: from kaldiio import WriteHelper [as 别名]
def __init__(self, wspecifier, write_num_frames=None, compress=False,
                 compression_method=2):
        if compress:
            self.writer = kaldiio.WriteHelper(
                wspecifier, compression_method=compression_method)
        else:
            self.writer = kaldiio.WriteHelper(wspecifier)
        self.writer_scp = None
        if write_num_frames is not None:
            self.writer_nframe = get_num_frames_writer(write_num_frames)
        else:
            self.writer_nframe = None 
开发者ID:DigitalPhonetics,项目名称:adviser,代码行数:14,代码来源:cli_writers.py

示例6: generate_json_data

# 需要导入模块: import kaldiio [as 别名]
# 或者: from kaldiio import WriteHelper [as 别名]
def generate_json_data(config, mode, nexamples):
  """Generate Json data for test."""

  # pylint: disable=too-many-locals
  tmpdir = Path(tempfile.mkdtemp())
  ark = str(tmpdir.joinpath('test.ark'))
  scp = str(tmpdir.joinpath('test.scp'))
  ilens = 100
  nfeat = 40
  nexamples = nexamples
  desire_xs = []
  desire_ilens = []
  desire_ys = []
  desire_olens = []
  with kaldiio.WriteHelper('ark,scp:{},{}'.format(ark, scp)) as out_f:
    for i in range(nexamples):
      # pylint: disable=invalid-name
      x = np.random.random((ilens, nfeat)).astype(np.float32)
      uttid = 'uttid{}'.format(i)
      out_f[uttid] = x
      desire_xs.append(x)
      desire_ilens.append(ilens)
      desire_ys.append(np.array([1, 2, 3, 10]))
      desire_olens.append(4)

  dummy_json = {}
  dummy_json['utts'] = {}
  with open(scp, 'r') as out_f:
    for line in out_f:
      uttid, path = line.strip().split()
      dummy_json['utts'][uttid] = {
          'input': [{
              'feat': path,
              'name': 'input1',
              'shape': [ilens, nfeat]
          }],
          'output': [{
              'tokenid': '1 2 3 10',
              'name': 'output1',
              'shape': [4, 10]
          }]
      }

  path = tmpdir.joinpath('{}.json'.format(mode))
  path.touch(exist_ok=True)
  path = str(path.resolve())
  with open(path, 'w') as out_f:
    json.dump(dummy_json, out_f, cls=JsonNumpyEncoder)
    config['data'][mode]['paths'] = [path]

  return desire_xs, desire_ilens, desire_ys, desire_olens 
开发者ID:didi,项目名称:delta,代码行数:53,代码来源:test_utils.py


注:本文中的kaldiio.WriteHelper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。