最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

wxpython繪制音頻效果

 更新時間:2019年11月18日 11:16:32   作者:douzujun  
這篇文章主要為大家詳細介紹了wxpython繪制音頻效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了wxpython繪制音頻的具體代碼,供大家參考,具體內容如下

#-*- coding: utf-8 -*-
 
################################################################################
## 使用wxPython的繪圖模塊wxPyPlot,需要數(shù)據(jù)可視化的時候,無需再借用其他的庫或模塊了
################################################################################
import numpy as np
import wx
import wx.lib.plot as wxPyPlot # 導入繪圖模塊,并命名為wxPyPlot
import wave
import pylab as pl
# 需要把數(shù)據(jù)封裝進入MyDataObject中
def MyDataObject():
 # 50 個點的sin函數(shù),用藍色圓點表示
 data1 = 2.*np.pi*np.arange(100)/100.
 data1.shape = (50, 2)
 data1[:, 1] = np.sin(data1[:, 0])
 print ("debug:", data1.shape)
 markers = wxPyPlot.PolyMarker(data1, legend='Green Markers', colour='blue', marker='circle', size=1)
 # 50個點的cos函數(shù),用紅色表示
 data2 = 2.*np.pi*np.arange(100)/100.
 data2.shape = (50, 2)
 print ("debug: data2", len(data2))
 data2[:, 1] = np.cos(data2[:, 0])
 lines = wxPyPlot.PolySpline(data2, legend='Red Line', colour='red')
 GraphTitle = "Plot Data(Sin and Cos)"
 
 return wxPyPlot.PlotGraphics([markers, lines], GraphTitle, "X Axis", "Y Axis")
# 解析wav數(shù)據(jù)
def MyWavData(wav_filename=""):
 print('working')
 # 打開wav文檔
 file = wave.open("mic4.wav", "r")
 # 讀取格式信息
 # (nchannels, sampwidth,framerate, nframes, comptype, compname)
 params = file.getparams()
 nchannels, sampwidth, framerate, nframes = params[:4]
 print (nchannels, sampwidth, framerate, nframes)
 # 讀取波形數(shù)據(jù)
 str_data = file.readframes(nframes)
 # 文件使用完畢,關閉文件
 file.close()
 # 將波形數(shù)據(jù)裝換成數(shù)組
 wave_data = np.fromstring(str_data, dtype=np.short)
 wave_data.shape = (-1, 2)
 wave_data = wave_data.T # 矩陣轉置
 time = np.arange(0, nframes) * (1.0 / framerate)
 # print ("debug: time:", len(time))
 # print ("debug: wave_data:", len(wave_data[0][0:len(time)]))
 # print ("debug: time:", time)
 # print ("debug: wave:", wave_data)
 time_and_wav = np.asarray([time, wave_data[0][0:len(time)]]).T
 print ("debug: len of time and wav: ", len(time_and_wav))
 print ("debug: time and wav: ", time_and_wav.shape)
 lines = wxPyPlot.PolySpline(time_and_wav, legend='Blue Line', colour='blue')
 GraphTitle = "the freq of wav file"
 return wxPyPlot.PlotGraphics([lines, ], GraphTitle, "time/s", "fre/Hz")
class TestFrame1(wx.Frame):
 def __init__(self, parent=None, id=wx.ID_ANY, title="Using wxPyPlot"):
  wx.Frame.__init__(self, parent, id, title, size=(800, 600))
  # 創(chuàng)建菜單欄
  self.mainmenu = wx.MenuBar()
  # 創(chuàng)建菜單
  menu = wx.Menu()
  menu.Append(100, 'Draw1', 'Draw plots1')
  self.Bind(wx.EVT_MENU, self.OnPlotDraw1, id=100)
  menu.Append(200, 'Draw_wav', 'Draw wav')
  self.Bind(wx.EVT_MENU, self.OnPlotDraw_wav, id=200)
  # 添加菜單到菜單欄
  self.mainmenu.Append(menu, '&Plot')
  # 設置菜單Bar
  self.SetMenuBar(self.mainmenu)
  # 創(chuàng)建狀態(tài)欄,顯示信息
  self.CreateStatusBar(2)
  self.pc = wxPyPlot.PlotCanvas(self) # 此處導入繪圖面板
 
 def OnPlotDraw1(self, event):    # 繪圖函數(shù)
  self.pc.Draw(MyDataObject())
 def OnPlotDraw_wav(self, event):
  self.pc.Draw(MyWavData())
def main():
 app = wx.App()
 # MyWavData()
 tf = TestFrame1()
 tf.Show()
 app.MainLoop()
# 測試wxPyPlot的代碼
if __name__ == '__main__':
 main()

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

威海市| 钟祥市| 永寿县| 大冶市| 镇平县| 宁化县| 武强县| 鲜城| 大名县| 饶阳县| 襄汾县| 南充市| 寿宁县| 马公市| 密云县| 诸暨市| 霍林郭勒市| 内丘县| 湘阴县| 武乡县| 和平县| 天水市| 望谟县| 辽阳市| 布拖县| 扎囊县| 英山县| 北京市| 崇仁县| 宜丰县| 包头市| 凤台县| 大洼县| 汕头市| 莎车县| 二连浩特市| 许昌市| 神农架林区| 醴陵市| 化州市| 绥德县|