@Operator(group="audio") public final class AudioSpectrogram extends PrimitiveOp implements Operand<Float>
Spectrograms are a standard way of representing audio information as a series of slices of frequency information, one slice for each window of time. By joining these together into a sequence, they form a distinctive fingerprint of the sound over time.
This op expects to receive audio data as an input, stored as floats in the range -1 to 1, together with a window width in samples, and a stride specifying how far to move the window between slices. From this it generates a three dimensional output. The first dimension is for the channels in the input, so a stereo audio input would have two here for example. The second dimension is time, with successive frequency slices. The third dimension has an amplitude value for each frequency during that time slice.
This means the layout when converted and saved as an image is rotated 90 degrees clockwise from a typical spectrogram. Time is descending down the Y axis, and the frequency decreases from left to right.
Each value in the result represents the square root of the sum of the real and imaginary parts of an FFT on the current window of samples. In this way, the lowest dimension represents the power of each frequency in the current window, and adjacent windows are concatenated in the next dimension.
To get a more intuitive and visual look at what this operation does, you can run tensorflow/examples/wav_to_spectrogram to read in an audio file and save out the resulting spectrogram as a PNG image.
Modifier and Type | Class and Description |
---|---|
static class |
AudioSpectrogram.Options
Optional attributes for
AudioSpectrogram |
operation
Modifier and Type | Method and Description |
---|---|
Output<Float> |
asOutput()
Returns the symbolic handle of a tensor.
|
static AudioSpectrogram |
create(Scope scope,
Operand<Float> input,
Long windowSize,
Long stride,
AudioSpectrogram.Options... options)
Factory method to create a class wrapping a new AudioSpectrogram operation.
|
static AudioSpectrogram.Options |
magnitudeSquared(Boolean magnitudeSquared) |
Output<Float> |
spectrogram()
3D representation of the audio frequencies as an image.
|
equals, hashCode, op, toString
public static AudioSpectrogram create(Scope scope, Operand<Float> input, Long windowSize, Long stride, AudioSpectrogram.Options... options)
scope
- current scopeinput
- Float representation of audio data.windowSize
- How wide the input window is in samples. For the highest efficiency
this should be a power of two, but other values are accepted.stride
- How widely apart the center of adjacent sample windows should be.options
- carries optional attributes valuespublic static AudioSpectrogram.Options magnitudeSquared(Boolean magnitudeSquared)
magnitudeSquared
- Whether to return the squared magnitude or just the
magnitude. Using squared magnitude can avoid extra calculations.public Output<Float> spectrogram()
public Output<Float> asOutput()
Operand
Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is used to obtain a symbolic handle that represents the computation of the input.
asOutput
in interface Operand<Float>
OperationBuilder.addInput(Output)
Copyright © 2022. All rights reserved.