python - tf.signal.stft 返回 -inf
问题描述
我正在关注有关音频识别的本教程 [https://www.tensorflow.org/tutorials/audio/simple_audio][1]
当我使用函数 tf.signal.stft 时,结果是一个包含多个元素且具有 -inf 值的数组。我认为这是因为波形包含一些 0,此问题仅在将某些音频文件转换为 wav(mp3、mp4、m4a)时出现,但在 ogg 中不会出现。我真的不知道该怎么办:(。
def get_stft(audio, frame_length=2048, frame_step=512, fft_length=256):
return tf.signal.stft(
tf.cast(audio, tf.float32),
frame_length=frame_length,
frame_step=frame_step,
fft_length=fft_length
)
def get_spectrogram(audio):
audio_stft = get_stft(audio)
audio_spec = tf.abs(audio_stft)
return tf.math.log(tf.transpose(audio_spec))
def get_waveform(filename):
raw_audio = tf.io.read_file(filename)
waveform, _ = tf.audio.decode_wav(raw_audio,desired_channels=1)
waveform=tf.squeeze(waveform, axis=-1)
return waveform
解决方案
推荐阅读
- ssis - 将 SSIS 连接到 Heroku PostgreSQL 数据库
- python-camelot - 如何使用 tabula_py 或 camelot 读取分布在多个页面上的表格
- django - 无法在迁移中创建对象
- apache-spark - 停止特定的火花动作
- coq - 在 Coq 中指定导出文件的路径?
- python - 无法上传使用 curl 在 selenium 中超过一定大小下载的文件
- terraform-provider-azure - 在 Terraform 中如何从自定义 VHD 创建 Azure 虚拟机
- cumulocity - 通过 Cumulocity 中的 REST API 将全局角色和应用程序分配给用户
- python - Adding a new node using jsonpath_ng
- java - Java Spring Boot 安全登录配置和页面控制器