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


Python soundfile.info方法代码示例

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


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

示例1: _does_utt_match_target_format

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def _does_utt_match_target_format(self, utterance):
        """
        Return ``True`` if the utterance already matches the target format,
        ``False`` otherwise.
        """
        if utterance.track.path.endswith('mp3'):
            return False

        try:
            info = sf.info(utterance.track.path)

            for key, value in self.expected_properties.items():
                if info.__getattribute__(key) != value:
                    return False

        except RuntimeError:
            return False

        return True 
开发者ID:ynop,项目名称:audiomate,代码行数:21,代码来源:wav.py

示例2: main

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def main(args):
    assert args.valid_percent >= 0 and args.valid_percent <= 1.

    dir_path = os.path.realpath(args.root)
    search_path = os.path.join(dir_path, '**/*.' + args.ext)
    rand = random.Random(args.seed)

    with open(os.path.join(args.dest, 'train.tsv'), 'w') as train_f, open(
            os.path.join(args.dest, 'valid.tsv'), 'w') as valid_f:
        print(dir_path, file=train_f)
        print(dir_path, file=valid_f)

        for fname in glob.iglob(search_path, recursive=True):
            file_path = os.path.realpath(fname)

            if args.path_must_contain and args.path_must_contain not in file_path:
                continue

            frames = soundfile.info(fname).frames
            dest = train_f if rand.random() > args.valid_percent else valid_f
            print('{}\t{}'.format(os.path.relpath(file_path, dir_path), frames), file=dest) 
开发者ID:pytorch,项目名称:fairseq,代码行数:23,代码来源:wav2vec_manifest.py

示例3: soundfile_loader

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def soundfile_loader(path, start=0, dur=None):
    import soundfile
    # get metadata
    info = soundfile_info(path)
    start = int(start * info['samplerate'])
    # check if dur is none
    if dur:
        # stop in soundfile is calc in samples, not seconds
        stop = start + int(dur * info['samplerate'])
    else:
        # set to None for reading complete file
        stop = dur

    audio, _ = soundfile.read(
        path,
        always_2d=True,
        start=start,
        stop=stop
    )
    return torch.FloatTensor(audio.T) 
开发者ID:sigsep,项目名称:open-unmix-pytorch,代码行数:22,代码来源:utils.py

示例4: change_format_and_subtype

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def change_format_and_subtype(audio_path):
    audio, sr = sf.read(audio_path)
    audio_info = sf.info(audio_path)

    formats = ['WAV', 'FLAC']
    if audio_info.format in formats:
        formats.remove(audio_info.format)
    _format = random.choice(formats)

    subtypes = sf.available_subtypes(_format)
    accepted_subtypes = ['PCM_16', 'PCM_32', 'PCM_24', 'FLOAT', 'DOUBLE']
    subtypes = [s for s in subtypes.keys() if s in accepted_subtypes]
    if audio_info.subtype in subtypes:
        subtypes.remove(audio_info.subtype)
    _subtype = random.choice(subtypes)
    
    sf.write(audio_path, audio, sr, subtype=_subtype, format=_format) 
开发者ID:justinsalamon,项目名称:scaper,代码行数:19,代码来源:test_audio.py

示例5: info

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def info(filepath: str) -> Tuple[SignalInfo, EncodingInfo]:
    r"""See torchaudio.info"""

    sfi = soundfile.info(filepath)

    precision = _subtype_to_precision[sfi.subtype]
    si = SignalInfo(sfi.channels, sfi.samplerate, precision, sfi.frames)
    ei = EncodingInfo(bits_per_sample=precision)
    return si, ei 
开发者ID:pytorch,项目名称:audio,代码行数:11,代码来源:soundfile_backend.py

示例6: _process_audio

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def _process_audio(self, root, id):
        path = os.path.join(root, id + '.flac')
        self.paths.append(path)
        duration = soundfile.info(path).duration
        self.durations.append(duration) 
开发者ID:mlperf,项目名称:inference,代码行数:7,代码来源:librispeech.py

示例7: read_nsamples

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def read_nsamples(audio_path):

    if audio_path.suffix == '.wv1':
        f = open(audio_path, 'rb')
        header = f.read(1024).decode("utf-8")  # nist header is a multiple of
        # 1024 bytes
        nsamples = int(re.search("sample_count -i (.+?)\n", header).group(1))
    else:
        info = sf.info(str(audio_path), verbose=True)
        nsamples = info.frames
    return nsamples 
开发者ID:fgnt,项目名称:sms_wsj,代码行数:13,代码来源:create_json.py

示例8: _check_duration

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def _check_duration(fname, expected_duration, tolerance):
    dur = sf.info(fname).duration
    success = np.abs(dur - expected_duration) < tolerance
    if not success:
        raise warnings.warn('{} does not have the expected duration: {} !~ {}'
                            .format(fname, dur, expected_duration))
    return success 
开发者ID:cosmir,项目名称:openmic-2018,代码行数:9,代码来源:verify_dataset.py

示例9: soundfile_info

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def soundfile_info(path):
    import soundfile
    info = {}
    sfi = soundfile.info(path)
    info['samplerate'] = sfi.samplerate
    info['samples'] = int(sfi.duration * sfi.samplerate)
    info['duration'] = sfi.duration
    return info 
开发者ID:sigsep,项目名称:open-unmix-pytorch,代码行数:10,代码来源:utils.py

示例10: torchaudio_info

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def torchaudio_info(path):
    import torchaudio
    # get length of file in samples
    info = {}
    si, _ = torchaudio.info(str(path))
    info['samplerate'] = si.rate
    info['samples'] = si.length // si.channels
    info['duration'] = info['samples'] / si.rate
    return info 
开发者ID:sigsep,项目名称:open-unmix-pytorch,代码行数:11,代码来源:utils.py

示例11: torchaudio_loader

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def torchaudio_loader(path, start=0, dur=None):
    import torchaudio
    info = torchaudio_info(path)
    # loads the full track duration
    if dur is None:
        sig, rate = torchaudio.load(path)
        return sig
        # otherwise loads a random excerpt
    else:
        num_frames = int(dur * info['samplerate'])
        offset = int(start * info['samplerate'])
        sig, rate = torchaudio.load(
            path, num_frames=num_frames, offset=offset
        )
        return sig 
开发者ID:sigsep,项目名称:open-unmix-pytorch,代码行数:17,代码来源:utils.py

示例12: stats

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def stats(self):
        if not self._stats:
            self._stats = sf.info(self.filename)
        return self._stats 
开发者ID:mozilla,项目名称:voice-corpus-tool,代码行数:6,代码来源:voice.py

示例13: __init__

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def __init__(
        self,
        path="None",
        is_wav=False,
        stem_id=None,
        subset=None,
        chunk_start=0,
        chunk_duration=None
    ):
        self.path = path
        self.subset = subset
        self.stem_id = stem_id
        self.is_wav = is_wav

        self.chunk_start = chunk_start
        self.chunk_duration = chunk_duration

        # load and store metadata
        if os.path.exists(self.path):
            if not self.is_wav:
                self.info = stempeg.Info(self.path)
                self.samples = int(self.info.samples(self.stem_id))
                self.duration = self.info.duration(self.stem_id)
                self.rate = self.info.rate(self.stem_id)
            else:
                self.info = sf.info(self.path)
                self.samples = self.info.frames
                self.duration = self.info.duration
                self.rate = self.info.samplerate
        else:
            # set to `None` if no path was set (fake file)
            self.info = None
            self.samples = None
            self.duration = None
            self.rate = None

        self._audio = None 
开发者ID:sigsep,项目名称:sigsep-mus-db,代码行数:39,代码来源:audio_classes.py

示例14: load_audio

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def load_audio(self, path, stem_id, chunk_start=0, chunk_duration=None):
        """array_like: [shape=(num_samples, num_channels)]
        """
        if os.path.exists(self.path):
            if not self.is_wav:
                # read using stempeg
                audio, rate = stempeg.read_stems(
                    filename=path,
                    stem_id=stem_id,
                    start=chunk_start,
                    duration=chunk_duration,
                    info=self.info
                )
            else:
                chunk_start = int(chunk_start * self.rate)

                # check if dur is none
                if chunk_duration:
                    # stop in soundfile is calc in samples, not seconds
                    stop = chunk_start + int(chunk_duration * self.rate)
                else:
                    stop = chunk_duration

                audio, rate = sf.read(
                    path,
                    always_2d=True,
                    start=chunk_start,
                    stop=stop
                )
            self._rate = rate
            return audio
        else:
            self._rate = None
            self._audio = None
            raise ValueError("Oops! %s cannot be loaded" % path) 
开发者ID:sigsep,项目名称:sigsep-mus-db,代码行数:37,代码来源:audio_classes.py

示例15: stems

# 需要导入模块: import soundfile [as 别名]
# 或者: from soundfile import info [as 别名]
def stems(self):
        """array_like: [shape=(stems, num_samples, num_channels)]
        """

        # return cached audio it explicitly set bet setter
        if self._stems is not None:
            return self._stems
        # read from disk to save RAM otherwise
        else:
            if not self.is_wav and os.path.exists(self.path):
                S, rate = stempeg.read_stems(
                    filename=self.path,
                    start=self.chunk_start,
                    duration=self.chunk_duration,
                    info=self.info
                )
            else:
                rate = self.rate
                S = []
                S.append(self.audio)
                # append sources in order of stem_ids
                for k, v in sorted(self.sources.items(), key=lambda x: x[1].stem_id):
                    S.append(v.audio)
                S = np.array(S)
            self._rate = rate
            return S 
开发者ID:sigsep,项目名称:sigsep-mus-db,代码行数:28,代码来源:audio_classes.py


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