|
发表于 2023-2-3 14:32
来自手机
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
chatgpt 给的代码 没测试
Sub Waveform()
Dim WaveFile As String
WaveFile = Application.GetOpenFilename("*.wav", , "打开音频文件")
If WaveFile = "False" Then Exit Sub
Dim Wave As Object
Set Wave = CreateObject("sapi.spwave")
Wave.Open WaveFile
Dim WaveData As Variant
WaveData = Wave.GetWaveData
Dim WaveLength As Integer
WaveLength = UBound(WaveData)
Dim WaveData2 As Variant
ReDim WaveData2(WaveLength)
Dim i As Integer
For i = 0 To WaveLength
WaveData2(i) = WaveData(i) / CLng(32767)
Next
With ActiveChart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = WaveFile
With .SeriesCollection(1).XValues
.Clear
For i = 0 To WaveLength
.Add i
Next
End With
With .SeriesCollection(1).Values
.Clear
For i = 0 To WaveLength
.Add WaveData2(i)
Next
End With
.SeriesCollection(1).MarkerStyle = xlMarkerStyleNone
.SeriesCollection(1).Border.Weight = 3
.SeriesCollection(1).Border.Color = RGB(255, 0, 0)
End With
Wave.Close
End Sub |
|