我有一个小问题:在VS2010年的“WinForm App”中, 我试图做Alvas.Audio似乎可行的工作。见(c#ex:http://alvas.net/alvas.audio.tips.aspx#tip94 。
Dim data() As Byte = wr.ReadData(second * i, second)
结果给了我 data. long ()=0
。 我没有任何例外, 我可以读取它的格式, 无论我使用什么读者, 我都有这个问题 。
EDIT : 经过一些测试后, 第一步我创建的未压缩文件( 以PCM格式, 有. wav 扩展) 似乎无法被 Alvas. audio 库确认为第二步 。 我必须忽略音频文件标记或类似的东西 。
以下是可能来源的代码(基本上这是第1步):
Dim functOut As String = String.Empty
Dim wr As Alvas.Audio.IAudioReader = Nothing
Dim fs As IO.FileStream = Nothing
Dim i As Integer = 0
Dim tmpData() As Byte = Nothing
Dim dataPCM() As Byte = Nothing
Dim newFormat As IntPtr = IntPtr.Zero
Try
Select Case IO.Path.GetExtension(filename).ToLower()
Case ".wav"
wr = New Alvas.Audio.WaveReader(IO.File.OpenRead(filename))
filename = IO.Path.GetTempPath & IO.Path.GetFileNameWithoutExtension(filename) & "2" & IO.Path.GetExtension(filename)
Case ".mp3"
wr = New Alvas.Audio.Mp3Reader(IO.File.OpenRead(filename))
Case Else : wr = New Alvas.Audio.DsReader(filename)
End Select
functOut = IO.Path.ChangeExtension(filename, ".wav")
Dim format As IntPtr = wr.ReadFormat()
Dim formatDetail As Alvas.Audio.WaveFormat = Alvas.Audio.AudioCompressionManager.GetWaveFormat(format)
If formatDetail.wFormatTag = Alvas.Audio.AudioCompressionManager.MpegLayer3FormatTag Then
Alvas.Audio.AudioCompressionManager.Mp3ToWav(filename, functOut)
Return True
Else
IO.File.Create(functOut).Close()
While True
tmpData = wr.ReadData(SECONDS * i, SECONDS)
If tmpData Is Nothing Or tmpData.Length = 0 Then Exit While
If formatDetail.wBitsPerSample < 16 Then
Alvas.Audio.AudioCompressionManager.ToPcm16Bit(format, tmpData, newFormat, dataPCM)
Else
newFormat = format
dataPCM = tmpData
End If
formatDetail = Alvas.Audio.AudioCompressionManager.GetWaveFormat(newFormat)
fs = IO.File.Open(filename, IO.FileMode.Append, IO.FileAccess.Write)
Using ww As New Alvas.Audio.WaveWriter(fs, Alvas.Audio.AudioCompressionManager.FormatBytes(newFormat))
ww.Write(dataPCM, 0, dataPCM.Length())
End Using
i += 1
tmpData = Nothing
End While
Return True
End If
wr.Close()
Catch ex As Exception
filename = String.Empty
Throw ex
Finally
fs.Close()
wr.Close()
filename = functOut
GC.Collect()
End Try
我如何写出结果流以确保我稍后能再读一遍?
任何想法都将受到高度赞赏。