当我解析PDF以便从那里提取.WAV时,它没有标题。因此,我需要为BigEndian格式的数据生成标头,因为PDF WAV存储在BigEndian中,并且将BigEndian转换为LittleEndian占用大量资源。 在这里,我有代码生成带有littleendian数据的wav标头,并且效果很好:
bits := 16
pcmLen := len(samples) * 2
samplingRate := format.sampleRate
numChannels := format.channels
blockAlign := (numChannels * bits) >> 3
// jshint bitwise:true
RIFF := 0x46464952 // Resource Interchange File Format
WAVE := 0x45564157 // Wave
FMT := 0x20746D66 // Format
DATA := 0x61746164 // Audio Data
buf := new(bytes.Buffer)
_ = binary.Write(buf, binary.LittleEndian, uint32(RIFF))
_ = binary.Write(buf, binary.LittleEndian, uint32(32+pcmLen))
_ = binary.Write(buf, binary.LittleEndian, uint32(WAVE))
_ = binary.Write(buf, binary.LittleEndian, uint32(FMT))
_ = binary.Write(buf, binary.LittleEndian, uint32(16))
_ = binary.Write(buf, binary.LittleEndian, uint16(1))
_ = binary.Write(buf, binary.LittleEndian, uint16(numChannels))
_ = binary.Write(buf, binary.LittleEndian, uint32(samplingRate))
_ = binary.Write(buf, binary.LittleEndian, uint32(samplingRate*blockAlign))
_ = binary.Write(buf, binary.LittleEndian, uint16(blockAlign))
_ = binary.Write(buf, binary.LittleEndian, uint16(bits))
_ = binary.Write(buf, binary.LittleEndian, uint32(DATA))
_ = binary.Write(buf, binary.LittleEndian, uint32(pcmLen))
如何为bigEndian生成标头?可能吗? 我尝试使用RIFX格式,但标准媒体播放器不支持