简体   繁体   English

tf.audio.decode_wav 如何获取其内容?

[英]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 .我正在尝试使用 tf.audio.decode_wav 将一些音频文件拉入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. WAV 编码的音频,通常来自文件。
  • desired_channels: An optional int. desired_channels:一个可选的整数。 Defaults to -1.默认为 -1。 Number of sample channels wanted.需要的采样通道数。
  • desired_samples: An optional int. desired_samples:一个可选的整数。 Defaults to -1.默认为 -1。 Length of audio requested.请求的音频长度。
  • name: A name for the operation (optional). name:操作的名称(可选)。

I'm guessing the contents is a tensor which has already been pulled from a file rather than a path?我猜内容是已经从文件而不是路径中提取的张量?

You're right, tf.audio.decode_wav() requires a tensor.你是对的, tf.audio.decode_wav()需要一个张量。 You can provide one with tf.io.read_file() which reads wav file into tensor of type string.您可以提供一个tf.io.read_file() ,它将 wav 文件读入字符串类型的张量。

raw_audio = tf.io.read_file(filename)
waveform = tf.audio.decode_wav(raw_audio)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM