timitphonemerec.py
def _audio_and_labels(prefix):
  """ Load and align a TIMIT wav file with its folded phonemes.

  Returns:
    A tuple, `(audio, labels)`. A 1-D float array and a 1-D int array, both
      with the same shape.
  """

  rate, audio = scipy.io.wavfile.read(prefix + '.wav')
  if rate != timit.SAMPLE_RATE:
    raise RuntimeError('Encountered an unexpected sampling rate of %d in %s' % (rate, prefix))
  audio = np.asarray(audio, dtype=np.float)
  phoneme_data = np.loadtxt(prefix + '.phn', dtype=np.object, comments=None, delimiter=' ',
                            converters={0: int, 1: int, 2: lambda x: str(x, encoding='ascii')})

  n = np.arange(audio.size)
  labels = -1 * np.ones([audio.size], dtype=np.int8)
  for start, end, phoneme in phoneme_data:
    phoneme = FOLDS[phoneme]
    labels[(n >= start) & (n < end)], = utils.tokens_to_ids([phoneme], TOKEN_VOCAB)
  audio_start = np.min(phoneme_data[:, 0])
  audio_end = np.max(phoneme_data[:, 1])
  audio = audio[audio_start:audio_end]
  labels = labels[audio_start:audio_end]
  if any(labels == -1):
    raise RuntimeError('Encountered incomplete labeling in %s' % prefix)

  return audio, labels
 Load and align a TIMIT wav file with its folded phonemes.

  Returns:
    A tuple, `(audio, labels)`. A 1-D float array and a 1-D int array, both
      with the same shape.
  
Load and align a TIMIT wav file with its folded phonemes.
Load and align a TIMIT wav file with its folded phonemes .
def _audio_and_labels(prefix):
  rate, audio = scipy.io.wavfile.read(prefix + '.wav')
  if rate != timit.SAMPLE_RATE:
    raise RuntimeError('Encountered an unexpected sampling rate of %d in %s' % (rate, prefix))
  audio = np.asarray(audio, dtype=np.float)
  phoneme_data = np.loadtxt(prefix + '.phn', dtype=np.object, comments=None, delimiter=' ',
                            converters={0: int, 1: int, 2: lambda x: str(x, encoding='ascii')})
  n = np.arange(audio.size)
  labels = -1 * np.ones([audio.size], dtype=np.int8)
  for start, end, phoneme in phoneme_data:
    phoneme = FOLDS[phoneme]
    labels[(n >= start) & (n < end)], = utils.tokens_to_ids([phoneme], TOKEN_VOCAB)
  audio_start = np.min(phoneme_data[:, 0])
  audio_end = np.max(phoneme_data[:, 1])
  audio = audio[audio_start:audio_end]
  labels = labels[audio_start:audio_end]
  if any(labels == -1):
    raise RuntimeError('Encountered incomplete labeling in %s' % prefix)
  return audio, labels
def _audio_and_labels ( prefix ) : rate , audio = scipy . io . wavfile . read ( prefix + '.wav' ) if rate != timit . SAMPLE_RATE : raise RuntimeError ( 'Encountered an unexpected sampling rate of %d in %s' % ( rate , prefix ) ) audio = np . asarray ( audio , dtype = np . float ) phoneme_data = np . loadtxt ( prefix + '.phn' , dtype = np . object , comments = None , delimiter = ' ' , converters = { 0 : int , 1 : int , 2 : lambda x : str ( x , encoding = 'ascii' ) } ) n = np . arange ( audio . size ) labels = - 1 * np . ones ( [ audio . size ] , dtype = np . int8 ) for start , end , phoneme in phoneme_data : phoneme = FOLDS [ phoneme ] labels [ ( n >= start ) & ( n < end ) ] , = utils . tokens_to_ids ( [ phoneme ] , TOKEN_VOCAB ) audio_start = np . min ( phoneme_data [ : , 0 ] ) audio_end = np . max ( phoneme_data [ : , 1 ] ) audio = audio [ audio_start : audio_end ] labels = labels [ audio_start : audio_end ] if any ( labels == - 1 ) : raise RuntimeError ( 'Encountered incomplete labeling in %s' % prefix ) return audio , labels
Load and align a TIMIT wav file with its folded phonemes.
Load and align a TIMIT wav file with its folded phonemes .
""" Load and align a TIMIT wav file with its folded phonemes.

  Returns:
    A tuple, `(audio, labels)`. A 1-D float array and a 1-D int array, both
      with the same shape.
  """
A tuple, `(audio, labels)`. A 1-D float array and a 1-D int array, both
with the same shape.
A tuple ` ( audio labels ) ` . A 1 - D float array and a 1 - D int array both with the same shape .
prefix