import bluespy
from time import sleep

bluespy.connect()
bluespy.capture("main_cap_1.pcapng", LE=True,CL=True, I2S=[bluespy.i2s_options(SCLK_line=12,WS_line=13,SD_line=11,n_channels=1,bits_per_ch=1),None], Audiopod=bluespy.audiopod_options(input=bluespy.audio_connect.I2S, LA_low_voltage = 0.5, LA_high_voltage = 1.5))
sleep(6)
I2S_ID = None
BIS_ID = None
for a in bluespy.audiostreams:
    #print(hex(a.value), a.channels, a.sample_rate, a.type, a.total_bytes, a.summary)
    if a.type == "BIS":
        BIS_ID = a
    if a.type == "I2S Stream":
        I2S_ID = a
if BIS_ID != None and I2S_ID != None:
    bluespy.measure_latency(bluespy._audio_channel_t(BIS_ID, 0), bluespy._audio_channel_t(I2S_ID, 0), True, bluespy.time_point())
elif BIS_ID != None:
    print("I2S not found")
else:
    print("BIS not found")
sleep(3)
bluespy.stop_capture()
bluespy.close_file()