當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。