它需要在自定义模型结构中重采样音频信号。这种重采样任务不是一种可以从模型中发展出来的预处理/后处理操作。换句话说,这种重采样是模型内部设计的一部分。然后,还需要为这样一个层定义梯度操作。对于重采样操作,它将使用tensorflow I/O:
操作工作非常完美,可以很容易地用作前/后处理单元;然而,它的实现--一个自定义层嵌入到模型中--是很有挑战性的,因为我不知道如何实现反向路径。
P.S.,我尝试使用传统的像层一样的上采样/池,但对实现其他重采样方法(如基于FFT的)的tfio进行比较却不够精确。
为了提供更多的理解,请看一下:另一个问题
发布于 2022-03-29 08:07:02
你必须告诉重新采样的目标,它可以在很多方面完成,包括总结唱歌信号,然后你可以用较小的正弦值来表示。
通过改变采样率,您可以节省数据空间0.05 *tf.math.sin(音频:5* 22050).numpy()
tf.math.sin(audio0:2750).numpy() sec_1 = np.zeros((2750)) *
tf.math.sin(audio2750:5500).numpy() sec_2 = np.ones((2750)) *
样本
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
contents = tf.io.read_file("F:\\temp\\Python\\Speech\\temple_of_love-sisters_of_mercy.wav")
audio, sample_rate = tf.audio.decode_wav(
contents, desired_channels=-1, desired_samples=-1, name=None
)
print(audio)
print(sample_rate)
plt.plot(audio[:5 * 22050])
plt.show()
plt.close()
plt.plot(0.05 * tf.math.sin(audio[:5 * 22050]).numpy())
plt.show()
plt.close()
sec_1 = np.zeros((2750)) * tf.math.sin(audio[0:2750]).numpy()
sec_2 = np.ones((2750)) * tf.math.sin(audio[2750:5500]).numpy()
plt.plot(0.05 * tf.concat([sec_1, sec_2], 0).numpy())
plt.show()
plt.close()
输出
array([[0.],
[0.],
[0.],
...,
[0.],
[0.],
[0.]], dtype=float32)>, sample_rate=<tf.Tensor: shape=(), dtype=int32, numpy=22050>)
tf.Tensor(22050, shape=(), dtype=int32)
https://stackoverflow.com/questions/71661813
复制相似问题