Hi, I want to download a file from M26 to my computer, I use AT+QFDWL, the command runs successfully and gets a response as binary data, then I use python code to convert this bytes to an audio file but it doesn’t play as expected. What step did I go wrong?
This is my pỵthon code convert binary file:
if filename in ''.join(response):
response = modem.write(f'AT+QFDWL="RAM:{filename}"', timeout=200) # Download file
file_bytes = b''
binary_data_parts = []
for res in response:
if res not in ('CONNECT', 'OK') and '+QFDWL:' not in res:
binary_data_parts.append(res.encode())
else:
print(res)
file_bytes = b''.join(binary_data_parts)
# print(file_bytes)
data_size_kb = len(file_bytes) / 1024
print(f"Size of data: {data_size_kb:.2f} KB")
output_file = rf'D:\rec.wav'
with wave.open(output_file, "wb") as file:
file.setnchannels(1) # 1 for mono, 2 for stereo
file.setsampwidth(2) # 2 bytes for 16-bit audio
file.setframerate(8000) # 8000 is standard rate for WAV 2G record incoming call
file.writeframes(file_bytes)
print(f'Saved file to {output_file}')