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

pull/2/head
Xinghai Sun 7 years ago
parent 9ac15f8bd8
commit 81207201da

@ -65,6 +65,9 @@ class AudioSegment(object):
:return: Audio segment instance. :return: Audio segment instance.
:rtype: AudioSegment :rtype: AudioSegment
""" """
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') samples, sample_rate = soundfile.read(file, dtype='float32')
return cls(samples, sample_rate) return cls(samples, sample_rate)

@ -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):
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):
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

Loading…
Cancel
Save