Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does tf.audio.decode_wav get its contents?

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?

like image 704
RobGMSN Avatar asked Sep 25 '19 10:09

RobGMSN


1 Answers

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)
like image 70
Sharky Avatar answered Sep 29 '22 23:09

Sharky