Hello Gang,
I’m working with Live API (Audio 2 Audio) using gemini-2.5-flash-native-audio-preview-09-2025 model, and I want to adding chat history for staying in context.
For that I tried to store the transcription of the user prompt and also the model response but I don’t know how to inject it in the API session.
Here’s my code if you can help me out
async with client.aio.live.connect(model=MODEL, config=config) as session:
timings = {}
turns = history.get_data(user_id=user_id)
print(turns)
start = time.perf_counter()
await session.send_realtime_input(
audio=types.Blob(data=audio_bytes, mime_type="audio/pcm;rate=16000"),
contents=turns #Not working
)
timings["transcription_time"] = round(time.perf_counter() - start, 4)
print(f"Sending : {timings['transcription_time']}")
start = time.perf_counter()
output_text_response = ""
input_text = ""
async for response in session.receive():
if response.server_content.input_transcription:
input_text += response.server_content.input_transcription.text
if response.server_content.output_transcription:
output_text_response += response.server_content.output_transcription.text
if response.data is not None:
wav_chunk = create_wav_chunk(response.data)
yield wav_chunk
timings["response_time"] = round(time.perf_counter() - start, 4)
print(f"Rendering : {timings['response_time']}")
if user_id not in history.data_store:
history.data_store[user_id] = []
history.data_store[user_id].append({"role": "user", "parts": [{"text": input_text}]})
history.data_store[user_id].append({"role": "model", "parts": [{"text": output_text_response}]})