From 2c8af5af648d110e21209e975241a51f4a9d9371 Mon Sep 17 00:00:00 2001 From: Jian Wang Date: Fri, 6 Aug 2021 10:43:10 +0800 Subject: [PATCH 1/2] somefix for higher version python --- use-python/dialogic_ADPCM.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/use-python/dialogic_ADPCM.py b/use-python/dialogic_ADPCM.py index e43828e..626783e 100644 --- a/use-python/dialogic_ADPCM.py +++ b/use-python/dialogic_ADPCM.py @@ -147,7 +147,7 @@ def ADPCM_Decode(code): list_16bit = [] for i in range(len(list_8bit_bytes)): - byte_i = list_8bit_bytes[i] # 1 bytes = 8bit + byte_i = ord(list_8bit_bytes[i]) # 1 bytes = 8bit high_4bit = (byte_i & 0xf0) >> 4 # split high 4bit from 8bit low_4bit = byte_i & 0x0f # split low 4bit from 8bit @@ -181,5 +181,5 @@ def ADPCM_Decode(code): wav_file.setsampwidth(2) wav_file.setframerate(16000) # converts data to binary data and writes it to a file - wav_file.writeframes(np.array(list_16bit).tostring()) + wav_file.writeframes(np.array(list_16bit, dtype=np.int16).tostring()) wav_file.close() From 4d75a1121690312538ef655bb37d1bf9a3e88c6d Mon Sep 17 00:00:00 2001 From: Jian Wang Date: Fri, 6 Aug 2021 10:47:12 +0800 Subject: [PATCH 2/2] friendly interface --- use-python/dialogic_ADPCM.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/use-python/dialogic_ADPCM.py b/use-python/dialogic_ADPCM.py index 626783e..b8f0c4d 100644 --- a/use-python/dialogic_ADPCM.py +++ b/use-python/dialogic_ADPCM.py @@ -140,10 +140,24 @@ def ADPCM_Decode(code): # decode test: vox(dialogic ADPCM) to wav(PCM) +# could use sox -t vox -r 6000 xxx.v3 xxx.wav +# but as said in README: "The center of the signal deviates from the zero axis as a whole" if __name__ == '__main__': - vox_file = open('xxxx.vox', mode='rb') - list_8bit_bytes = vox_file.read() - vox_file.close() + import sys + import argparse + + parser = argparse.ArgumentParser(description="Convert a vox(dialogic ADPCM) to wav(PCM)") + parser.add_argument("samplerate", type=int, + help="samplerate of source file"); + parser.add_argument("voxfile", type=str, + help="input vox file"); + parser.add_argument("wavfile", type=str, + help="output wav file"); + + args = parser.parse_args() + + with open(args.voxfile, mode='rb') as vox_file: + list_8bit_bytes = vox_file.read() list_16bit = [] for i in range(len(list_8bit_bytes)): @@ -174,12 +188,11 @@ def ADPCM_Decode(code): list_16bit.extend([tmpDeS16_0, tmpDeS16_1]) - wav_file = wave.open('xxxx.wav', 'wb') - + wav_file = wave.open(args.wavfile, 'wb') # configure channel number, quantization size, and sample rate wav_file.setnchannels(1) wav_file.setsampwidth(2) - wav_file.setframerate(16000) + wav_file.setframerate(args.samplerate) # converts data to binary data and writes it to a file wav_file.writeframes(np.array(list_16bit, dtype=np.int16).tostring()) wav_file.close()