WeixuanYuan commited on
Commit
2969274
·
verified ·
1 Parent(s): bd6e54b

Upload tools.py

Browse files
Files changed (1) hide show
  1. tools.py +20 -0
tools.py CHANGED
@@ -2,6 +2,7 @@ import numpy as np
2
  import matplotlib.pyplot as plt
3
  import matplotlib
4
  import librosa
 
5
  from scipy.io.wavfile import write
6
  import torch
7
 
@@ -342,3 +343,22 @@ def decode_stft(encoded_D):
342
 
343
  D = magnitude * (np.cos(phase) + 1j * np.sin(phase))
344
  return D
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import matplotlib.pyplot as plt
3
  import matplotlib
4
  import librosa
5
+ from scipy.io import wavfile
6
  from scipy.io.wavfile import write
7
  import torch
8
 
 
343
 
344
  D = magnitude * (np.cos(phase) + 1j * np.sin(phase))
345
  return D
346
+
347
+
348
+ def read_wav_to_numpy(file_path):
349
+ """
350
+ 读取 WAV 文件并返回采样率和音频数据 (NumPy 数组)
351
+
352
+ 参数:
353
+ file_path (str): WAV 文件的路径
354
+
355
+ 返回:
356
+ tuple: 采样率 (int) 和音频数据 (NumPy array)
357
+ """
358
+ # 使用 scipy.io.wavfile 读取 wav 文件
359
+ sample_rate, data = wavfile.read(file_path)
360
+ data = data/np.max(np.abs(data))
361
+
362
+ return sample_rate, data
363
+
364
+