gray-beach-22915
02/25/2025, 3:09 PMgray-monkey-83525
02/25/2025, 3:09 PMagent.say()
function in LiveKit is not inherently blocking, meaning it does not wait for the speech to finish before proceeding to the next function. However, you can achieve a blocking behavior by using the await
keyword with agent.say()
, which will ensure that the function waits for the speech to complete before moving on to the next line of code. This is confirmed by the LiveKit documentation, which describes the say
method as asynchronous.
Would you like more details on how to implement this in your code?
Sources:
- LiveKit documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.gray-beach-22915
02/25/2025, 3:11 PMlogger.debug("Redirecting the call...")
livekit_api = LiveKitAPI()
print(phrase_de_transfert)
transfer_to = f'tel:{self.redirection_number}'
out = await self.assistant.say(phrase_de_transfert)
await out.wait_for_initialization()
print(88 * "-")
# await self.assistant.say("Un instant s'il vous plaît.")
# await asyncio.sleep(4)
# Create transfer request
transfer_request = TransferSIPParticipantRequest(
participant_identity=self.participant.identity,
room_name=self.room.name,
transfer_to=transfer_to,
play_dialtone=True
)
logger.debug(f"Transfer request: {transfer_request.participant_identity}") # pylint: disable=W1203
# Transfer caller
await livekit_api.sip.transfer_sip_participant(transfer_request)
<http://logger.info|logger.info>(f"Successfully transferred participant {self.participant.identity} to {transfer_to}") # pylint: disable=W1203
gray-monkey-83525
02/25/2025, 3:11 PMawait self.assistant.say(phrase_de_transfert)
is not blocking as expected because the say
method itself does not inherently wait for the speech to finish. According to the LiveKit documentation, the say
method is asynchronous and returns a SpeechHandle
, which you can use to manage the speech playback.
To ensure that the function blocks until the speech is finished, you should use the await
keyword with the join()
method on the SpeechHandle
returned by say
. Here's how you can modify your code:
out = await self.assistant.say(phrase_de_transfert)
await out.join() # Wait for the speech to finish
This should ensure that the code execution waits until the speech is completed before proceeding to the next line.
Would you like more detailed guidance on this?
Sources:
- LiveKit documentation 👍 1 button 👎 0 button 💡 Hint: Mention @millions-hair-24956 in the thread for followups.