from scipy.io import wavfile
import numpy as np
import matplotlib.pyplot as plt
sample_rate, data = wavfile.read("Alarm01.wav") # 加载声音,返回采样频率,声音数据
print("Data type", data.dtype, "Shape", data.shape)
Data type int16 Shape (122868, 2)
repeated = np.array(list(data)*2) # 重复音频片段
wavfile.write("a.wav", sample_rate, repeated) # 绘制声音
plt.figure(figsize=(10,5))
plt.subplot(1,2,1)
plt.title("Original")
plt.plot(data)
plt.subplot(1,2,2)
plt.title("Repeated")
plt.plot(repeated)
plt.show()
声音数据下载:https://files.cnblogs.com/files/LiJinrun/Alarm01.zip