Bạn có thể gọi wave lib để đọc tệp âm thanh.
Để vẽ dạng sóng, sử dụng "âm mưu" chức năng từ matplotlib
import matplotlib.pyplot as plt
import numpy as np
import wave
import sys
spf = wave.open('wavfile.wav','r')
#Extract Raw Audio from Wav File
signal = spf.readframes(-1)
signal = np.fromstring(signal, 'Int16')
#If Stereo
if spf.getnchannels() == 2:
print 'Just mono files'
sys.exit(0)
plt.figure(1)
plt.title('Signal Wave...')
plt.plot(signal)
plt.show()
bạn sẽ có một cái gì đó như: 
Để Vẽ trục x trong vài giây bạn cần có được tỷ lệ khung hình và chia cho kích thước của tín hiệu của bạn, bạn có thể sử dụng hàm linspace từ numpy để tạo ra một khoảng thời gian Vector cách đều với kích thước của tệp âm thanh và cuối cùng bạn có thể sử dụng lại âm mưu như plt.plot(Time,signal)
import matplotlib.pyplot as plt
import numpy as np
import wave
import sys
spf = wave.open('Animal_cut.wav','r')
#Extract Raw Audio from Wav File
signal = spf.readframes(-1)
signal = np.fromstring(signal, 'Int16')
fs = spf.getframerate()
#If Stereo
if spf.getnchannels() == 2:
print 'Just mono files'
sys.exit(0)
Time=np.linspace(0, len(signal)/fs, num=len(signal))
plt.figure(1)
plt.title('Signal Wave...')
plt.plot(Time,signal)
plt.show()
mới âm mưu trục x trong vài giây:

in 'đầu ra 'là gì? –
Đây có phải là tệp wavfile đơn hoặc đa kênh không? –
Bản in a, chỉ hiển thị một bộ dữ liệu với dữ liệu thô của tệp âm thanh. Và nó là một wavfile đơn. –