将stft张量流代码转换为pytorch /纯python代码

时间:2020-08-06 04:07:13

标签: audio pytorch signal-processing tensorflow2.0

我正在尝试将以下代码(来自https://github.com/saiteja-talluri/Speech2Face/blob/master/preprocess/speaker.py)转换为PyTorch或纯python。

def find_spec(self, filename):
        print("-------------finding spectrogram for {0}----------------".format(filename))
        with tf.Session(graph=tf.Graph()) as sess:

            holder = tf.placeholder(tf.string, [])
            file = tf.io.read_file(holder)
            decoder = tf.contrib.ffmpeg.decode_audio(file, file_format = "wav", samples_per_second = self.sample_rate, channel_count = 1)
            stft = tf.signal.stft(tf.transpose(a=decoder), frame_length = self.window, frame_step = self.stride, fft_length = self.fft_length, window_fn = tf.signal.hann_window)
            amp = tf.squeeze(tf.abs(stft)) ** self.amp_norm
            phase = tf.squeeze(tf.math.angle(stft))
            stacked = tf.stack([amp, phase], 2)
            stft = sess.run(stacked, feed_dict = {holder : self.audios_path + filename + ".wav"})
            pickle.dump(stft, open(self.spect_path + filename  + ".pkl", "wb"))
            print("============STFT SHAPE IS {0}=============".format(stft.shape))

我试图使用此处(https://tbnsilveira.info/2019/02/23/finding-cyclic-patterns-a-tutorial-on-how-to-implement-stft-in-python/)的代码进行转换,但是我无法找到可运行的代码。 我非常感谢您的帮助。谢谢。

0 个答案:

没有答案
相关问题