我正在尝试构建一个类似于使用 Audacity 创建的音频样本的绘图频谱。从 Audacity 的 wiki 页面,情节频谱(附加示例)执行:
Plot Spectrum take the audio in blocks of 'Size' samples, does the FFT, and averages all the blocks together.
我在想我会使用 Tensorflow 最近提供的 STFT 功能。
我正在使用大小为 512 的音频块,我的代码如下:
audio_binary = tf.read_file(audio_file)
waveform = tf.contrib.ffmpeg.decode_audio(
audio_binary,
file_format="wav",
samples_per_second=4000,
channel_count=1
)
stft = tf.contrib.signal.stft(
waveform,
512, # frame_length
512, # frame_step
fft_length=512,
window_fn=functools.partial(tf.contrib.signal.hann_window, periodic=True), # matches audacity
pad_end=True,
name="STFT"
)
但是当我期望每帧(512 个样本)的 FFT 结果时,stft 的结果只是一个空数组
我打这个电话的方式有什么问题?
我已经验证波形音频数据可以通过常规
tf.fft
正确读取。功能。
最佳答案
audio_file = tf.placeholder(tf.string)
audio_binary = tf.read_file(audio_file)
waveform = tf.contrib.ffmpeg.decode_audio(
audio_binary,
file_format="wav",
samples_per_second=sample_rate, # Get Info on .wav files (sample rate)
channel_count=1 # Get Info on .wav files (audio channels)
)
stft = tf.contrib.signal.stft(
tf.transpose(waveform),
frame_length, # frame_lenght, hmmm
frame_step, # frame_step, more hmms
fft_length=fft_length,
window_fn=functools.partial(tf.contrib.signal.hann_window,
periodic=False), # matches audacity
pad_end=False,
name="STFT"
)
关于audio - tensorflows STFT函数的正确使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45903477/