'How to record real time data array to wav file python raspi?

I am newbie when it comes to realtime data array recording.

Currently I have connected device ADS1263 High-Precision AD HAT and recieve raw data from 2 output to raspi.I have problem

How I record real time array data to wav file? And I have some example code but it error when write wav file . Thanks very much

import pyaudio
import time
import ADS1263
import RPi.GPIO as GPIO
import wave, struct, math, random

sampleRate = 44100.0 # hertz
duration = 3.0 # seconds
#frequency = 440.0 # hertz
obj = wave.open('sound.wav','w')
obj.setnchannels(1) # mono
obj.setsampwidth(2)
obj.setframerate(sampleRate)
REF = 5.08          # Modify according to actual voltage
                # external AVDD and AVSS(Default), or internal 2.5V

TEST_ADC1       = True

try:
ADC = ADS1263.ADS1263()
if (ADC.ADS1263_init_ADC1('ADS1263_7200SPS') == -1):
    exit()
ADC.ADS1263_SetMode(0)


if(TEST_ADC1):       # ADC1 Test
    while(1):
        ADC_Value = ADC.ADS1263_GetAll()    # get ADC1 value
        for i in range(0, 2):
            if(ADC_Value[i]>>31 ==1):
                print("ADC1 IN%d = -%lf" %(i, (REF*2 - ADC_Value[i] * REF / 0x80000000)))  
                obj.writeframesraw( ADC_Value[1] )
                time.sleep(0.1) 
            else:
                print("ADCX IN%d = %lf" %(i, (ADC_Value[i] * REF / 0x7fffffff)))   # 32bit
                obj.writeframesraw( ADC_Value[1] )
                time.sleep(0.1) 
        print("\33[11A")
    
obj.close()        
ADC.ADS1263_Exit()

except IOError as e:
print(e)

except KeyboardInterrupt:
print("ctrl + c:")
print("Program end")
ADC.ADS1263_Exit()
exit()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source