I get a blob out of a ms access database which contains mono wav data from an instrument. It's just 1 second. It begins with different values, so I mean it is pure wav Data
b'\\f_?\xb2\xca^??;]?\xa9(Z?\xf8\x87V?\x8e\x11S?PCP?\xcc\x06O?\xf1RN?a\x07M?\x83DK?\xa9hH?\x94\nE?\x9d.B?mb??\xf9\x05=?\xf5X;?\xeb|:?M\xc7:?Qg;?\xbd\x0c<?\x8c\x05=?\x85I>?v\xd2??/`B?\xfe\xafF?\xafFL?b3S?,\x8dZ?\xc1}`?\x16Le?\xef\xb2h?@#j?a\x02k?\xb3\xcck?D\xd2l?\xec\xaen?\x19\xccp?\x9e\xdfr?\x82Uu?\x81\x03x?tCz?\xa5E{?\xec\xecz?5\xcey?\x08\x82x?\x83\xd2v?\xec\xb3t?\x8f\x04r?\xce\x08n?\x8d3h?\x11@a?\x1e\xfbX?\x9b\x11P?\xfc}G?\x08\'
...
I used the packages wave
and soundfile
to create a wav file, but it never meets the original format. I could export a file from the original software, so it should work.
import wave
wav = wave.open(wavfile, 'rb')
print("filename :", wavfile)
print("channels :", wav.getnchannels())
print("sampwidth:", wav.getsampwidth())
print("framerate:", wav.getframerate())
print("nframes :", wav.getnframes())
The output is:
filename : c:\DATEN\TS_org.wav
channels : 1
sampwidth: 2
framerate: 32768
nframes : 16384
I did set these parameters to th new file and added the BLOB:
def create_audiofile(blobin, saveto):
nchannels = 1
#ok to read in another analyser, but wrong sound sampwidth = 1
sampwidth = 2
framerate = 32768
nframes = 16384
audio = wave.open (saveto, 'wb')
audio.setnchannels (nchannels)
audio.setsampwidth (sampwidth)
audio.setframerate (framerate)
audio.setnframes (nframes)
audio.writeframes(blobin)
#also no success
#audio.writeframesraw(blobin)
I checked serveral websites and answers here in SO. There is a good description here, but I never got a working wav file.
The first 36 bytes of the original file look like this:
Bytenr :0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
integer:82 73 70 70 36 128 0 0 87 65 86 69 102 109 116 32 16 0 0 0 1 0 1 0 0 128 0 0 0 0 1 0 2 0 16 0
hexcode:0x52 0x49 0x46 0x46 0x24 0x80 0x0 0x0 0x57 0x41 0x56 0x45 0x66 0x6d 0x74 0x20 0x10 0x0 0x0 0x0 0x1 0x0 0x1 0x0 0x0 0x80 0x0 0x0 0x0 0x0 0x1 0x0 0x2 0x0 0x10 0x0
ASCII :R I F F $ W A V E f m t # # # # # #
How can I use these information to build a new wav File?
Edit
This is the funny script from @mivk as python script to test conversion:
import subprocess
infile =("e:\\data\\wav\\raw.pcm")
ffmpeg = "e:\\data\\wav\\ffmpeg.exe"
samples = [8000, 11025, 22050, 16000, 32000, 22050, 44100]
formats = ['alaw', 'f32be', 'f32le', 'f64be', 'f64le', 'mulaw', 's16be', 's16le', 's24be', 's24le', 's32be',
's32le', 's8', 'u16be', 'u16le', 'u24be', 'u24le', 'u32be', 'u32le', 'u8']
for ar in samples:
for f in formats:
outfile = infile[:-4] + "_%s_%s.wav"%(f, ar)
order = '%s -f %s -ar %d -ac 1 -i %s %s'%(ffmpeg, f, ar, infile, outfile)
subprocess.call(order)