提交 81207201 编写于 作者: X Xinghai Sun

Fix a bug in running tools/compute_meanstd.py with seqbin data.

上级 9ac15f8b
...@@ -65,8 +65,11 @@ class AudioSegment(object): ...@@ -65,8 +65,11 @@ class AudioSegment(object):
:return: Audio segment instance. :return: Audio segment instance.
:rtype: AudioSegment :rtype: AudioSegment
""" """
samples, sample_rate = soundfile.read(file, dtype='float32') if isinstance(file, basestring) and re.findall(r".seqbin_\d+$", file):
return cls(samples, sample_rate) return cls.from_sequence_file(file)
else:
samples, sample_rate = soundfile.read(file, dtype='float32')
return cls(samples, sample_rate)
@classmethod @classmethod
def slice_from_file(cls, file, start=None, end=None): def slice_from_file(cls, file, start=None, end=None):
......
...@@ -7,7 +7,6 @@ from __future__ import print_function ...@@ -7,7 +7,6 @@ from __future__ import print_function
import random import random
import tarfile import tarfile
import re
import multiprocessing import multiprocessing
import numpy as np import numpy as np
import paddle.v2 as paddle import paddle.v2 as paddle
...@@ -105,9 +104,6 @@ class DataGenerator(object): ...@@ -105,9 +104,6 @@ class DataGenerator(object):
if filename.startswith('tar:'): if filename.startswith('tar:'):
speech_segment = SpeechSegment.from_file( speech_segment = SpeechSegment.from_file(
self._subfile_from_tar(filename), transcript) self._subfile_from_tar(filename), transcript)
elif re.findall(r".seqbin_\d+$", filename):
speech_segment = SpeechSegment.from_sequence_file(filename,
transcript)
else: else:
speech_segment = SpeechSegment.from_file(filename, transcript) speech_segment = SpeechSegment.from_file(filename, transcript)
self._augmentation_pipeline.transform_audio(speech_segment) self._augmentation_pipeline.transform_audio(speech_segment)
......
...@@ -50,20 +50,6 @@ class SpeechSegment(AudioSegment): ...@@ -50,20 +50,6 @@ class SpeechSegment(AudioSegment):
audio = AudioSegment.from_file(filepath) audio = AudioSegment.from_file(filepath)
return cls(audio.samples, audio.sample_rate, transcript) return cls(audio.samples, audio.sample_rate, transcript)
@classmethod
def from_sequence_file(cls, filepath, transcript):
"""Create speech segment from sequence file and transcript.
:param filepath: Filepath of sequence file.
:type filepath: basestring
:param transcript: Transcript text for the speech.
:type transript: basestring
:return: Speech segment instance.
:rtype: SpeechSegment
"""
audio = AudioSegment.from_sequence_file(filepath)
return cls(audio.samples, audio.sample_rate, transcript)
@classmethod @classmethod
def from_bytes(cls, bytes, transcript): def from_bytes(cls, bytes, transcript):
"""Create speech segment from a byte string and corresponding """Create speech segment from a byte string and corresponding
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册