5

I'm trying to pull some audio files into Tensorflow by using tf.audio.decode_wav.

I can see someone is looking into providing more info in the docs, but does anyone have any examples of how this should work?

tf.audio.decode_wav(
 contents,
 desired_channels=-1,
 desired_samples=-1,
 name=None
)

Args:

  • contents: A Tensor of type string. The WAV-encoded audio, usually from a file.
  • desired_channels: An optional int. Defaults to -1. Number of sample channels wanted.
  • desired_samples: An optional int. Defaults to -1. Length of audio requested.
  • name: A name for the operation (optional).

I'm guessing the contents is a tensor which has already been pulled from a file rather than a path?

tripleee
  • 175,061
  • 34
  • 275
  • 318
RobGMSN
  • 53
  • 1
  • 3

1 Answers1

10

You're right, tf.audio.decode_wav() requires a tensor. You can provide one with tf.io.read_file() which reads wav file into tensor of type string.

raw_audio = tf.io.read_file(filename)
waveform = tf.audio.decode_wav(raw_audio)
Sharky
  • 4,473
  • 2
  • 19
  • 27