tf.contrib.ffmpeg.decode_audio replacement?

Viewed 1139

In the tensorflow docs, it stated that tf.contrib.ffmpeg.decode_audio is depreciated, however it does not state what it's replacement is...

THIS FUNCTION IS DEPRECATED. It will be removed after 2018-09-04. Instructions for updating: This will be deleted and should not be used.

Here is the link: https://www.tensorflow.org/api_docs/python/tf/contrib/ffmpeg/decode_audio

3 Answers

You don't have to use TensorFlow to decode audio files. You can use another Python library (although you might be slowed down by the GIL).

The tensorflow-io library now has AudioIOTensor as an interface for decoding audio files while also keeping track of their audio sample rates. You can use it as follows:

import tensorflow as tf
import tensorflow_io as tfio

audio_tensor = tfio.audio.AudioIOTensor("filename.flac")
print("Sample rate is", int(audio_tensor.rate))
# tensor = Decoded audio as a tf.Tensor of shape (frames, channels).
tensor = audio_tensor.to_tensor()
print(tensor.shape[0], "frames containing", tensor.shape[1], "channels")

Try tensorflow.contrib.framework.python.ops.audio_ops.decode_wav.

This might be gone in tensorflow 2

Related