Rezuwan commited on
Commit
7566cd6
·
verified ·
1 Parent(s): c1e525b

Upload core.py

Browse files
Files changed (1) hide show
  1. librosa/core.py +27 -0
librosa/core.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import tensorflow as tf
3
+
4
+ def stft(y, n_fft=2048, hop_length=512, win_length=2048, **kwargs):
5
+ y = tf.convert_to_tensor(y, dtype=tf.float32)
6
+ Z = tf.signal.stft(
7
+ y,
8
+ frame_length=win_length,
9
+ frame_step=hop_length,
10
+ fft_length=n_fft,
11
+ window_fn=tf.signal.hann_window
12
+ )
13
+ return Z
14
+
15
+ def istft(Z, hop_length=512, win_length=2048, **kwargs):
16
+ if not tf.executing_eagerly():
17
+ tf.config.run_functions_eagerly(True)
18
+
19
+ Z = tf.convert_to_tensor(Z, dtype=tf.complex64)
20
+
21
+ audio = tf.signal.inverse_stft(
22
+ Z,
23
+ frame_length=win_length,
24
+ frame_step=hop_length,
25
+ window_fn=tf.signal.hann_window
26
+ )
27
+ return audio.numpy()