提交 c6c5f416 编写于 作者: X Xinghai Sun 提交者: GitHub

Merge pull request #378 from xinghai-sun/seqbin

Fix a bug in running tools/compute_meanstd.py with seqbin data.
......@@ -65,8 +65,11 @@ class AudioSegment(object):
:return: Audio segment instance.
:rtype: AudioSegment
"""
samples, sample_rate = soundfile.read(file, dtype='float32')
return cls(samples, sample_rate)
if isinstance(file, basestring) and re.findall(r".seqbin_\d+$", file):
return cls.from_sequence_file(file)
else:
samples, sample_rate = soundfile.read(file, dtype='float32')
return cls(samples, sample_rate)
@classmethod
def slice_from_file(cls, file, start=None, end=None):
......
......@@ -7,7 +7,6 @@ from __future__ import print_function
import random
import tarfile
import re
import multiprocessing
import numpy as np
import paddle.v2 as paddle
......@@ -105,9 +104,6 @@ class DataGenerator(object):
if filename.startswith('tar:'):
speech_segment = SpeechSegment.from_file(
self._subfile_from_tar(filename), transcript)
elif re.findall(r".seqbin_\d+$", filename):
speech_segment = SpeechSegment.from_sequence_file(filename,
transcript)
else:
speech_segment = SpeechSegment.from_file(filename, transcript)
self._augmentation_pipeline.transform_audio(speech_segment)
......
......@@ -50,20 +50,6 @@ class SpeechSegment(AudioSegment):
audio = AudioSegment.from_file(filepath)
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
def from_bytes(cls, bytes, transcript):
"""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.
先完成此消息的编辑!
想要评论请 注册