diff --git a/deep_speech_2/data_utils/audio.py b/deep_speech_2/data_utils/audio.py index 01c0648448d29345ad706120228d7f463fbe1699..3fb782951699bc1abd3d5613621e89685ee387de 100644 --- a/deep_speech_2/data_utils/audio.py +++ b/deep_speech_2/data_utils/audio.py @@ -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): diff --git a/deep_speech_2/data_utils/data.py b/deep_speech_2/data_utils/data.py index fca5381758f3a0a97d1d288019f0d909eca2469a..71ba2434f2875c007b011cef659a031c7d80a621 100644 --- a/deep_speech_2/data_utils/data.py +++ b/deep_speech_2/data_utils/data.py @@ -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) diff --git a/deep_speech_2/data_utils/speech.py b/deep_speech_2/data_utils/speech.py index 623b38c24132519de737dafb1a782293d5db24f7..0cea887309d7c443a5dcdb3577ad897e6b36e209 100644 --- a/deep_speech_2/data_utils/speech.py +++ b/deep_speech_2/data_utils/speech.py @@ -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