[英]Python wav plot, the graph is not plotting
我正在制作簡單的 python 音頻播放器,但我在繪制 wav 文件時遇到問題。
我使用 matplotlib 和 wave
代碼片段:
spf = wave.open('music.wav','r')
signal = spf.readframes(-1)
signal = np.fromstring(signal, dtype=int, sep=' ')
fs = spf.getframerate()
Time=np.linspace(0, len(signal)/fs, num=len(signal))
plt.figure(1)
plt.title('Signal Wave...')
plt.plot(Time,signal)
plt.show()
程序有效但未繪制圖形,我認為問題可能出在 np.fromstring 中,但我不太確定。
嘗試這個:
import matplotlib.pyplot as plt
import numpy as np
import wave
spf = wave.open('music.wav','r')
signal = spf.readframes(-1)
signal = np.fromstring(signal, 'Int8')
plt.figure(1)
plt.title('Signal Wave...')
plt.plot(signal)
plt.show()
與時間軸:
import matplotlib.pyplot as plt
import numpy as np
import wave
spf = wave.open('music.wav','r')
signal = spf.readframes(-1)
signal = np.fromstring(signal, 'Int8')
fs = spf.getframerate()
Time=np.linspace(0, len(signal)/fs, num=len(signal))
plt.figure(1)
plt.title('Signal Wave...')
plt.plot(Time,signal)
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.