<@U084APK40NS> how can i get the phoneNumber to wh...
# ask-ai
w
@millions-hair-24956 how can i get the phoneNumber to which the call is made in VoicePipelineAgent?
g
To get the phone number to which a call is made in a
VoicePipelineAgent
, you can access the SIP participant's attributes. Specifically, the
sip.trunkPhoneNumber
attribute contains the phone number that was dialed. You can retrieve this information by waiting for the participant and then accessing their attributes. Here's a basic example:
Copy code
participant = await ctx.wait_for_participant()
dialed_number = participant.attributes.get('sip.trunkPhoneNumber')
This code waits for a participant to join and then retrieves the dialed phone number from the participant's attributes. Would you like more details on this process? Sources: - LiveKit Slack Discussion 👍 1 button 👎 0 button 💡 Hint: Mention @millions-hair-24956 in the thread for followups.
w
@millions-hair-24956 How to disconnect a call with a message
g
To disconnect a call with a message using LiveKit, you can utilize the
LiveKitAPI
to remove a participant from the room and play a message before disconnection. Here's a basic approach: 1. Define a function to play a message: Use the Text-to-Speech (TTS) capabilities to play a message to the participant. 2. Remove the participant: Use the
remove_participant
method to disconnect the participant after the message is played. Here's a Python example:
Copy code
async def disconnect_with_message(ctx, participant, message):
    # Play the message using TTS
    await ctx.tts.say(message)
    
    # Disconnect the participant
    lk_api = api.LiveKitAPI()
    await lk_api.room.remove_participant(
        api.RoomParticipantIdentity(
            room=ctx.room.name, identity=participant.identity
        )
    )
This function first plays a message to the participant and then disconnects them from the room. Would you like more details on implementing this? Sources: - LiveKit Slack Discussion 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
w
@millions-hair-24956 which package to use for api.LiveKitAPI()?
g
To use
api.LiveKitAPI()
, you should use the
livekit
Python package. This package provides the necessary classes and methods to interact with LiveKit's API, including room management and participant control. You can install the package using pip:
Copy code
pip install livekit
Would you like more details on how to set up and use this package? Sources: - https://docs.livekit.io/home/quickstarts/swift/ - https://livekit-users.slack.com/archives/C07FY8WHGPM/p1727992834.783299 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
w
@millions-hair-24956 From where api is imported?
g
The
api
module is part of the
livekit
Python package. You can import it using:
Copy code
from livekit import api
This import statement allows you to access the
LiveKitAPI
class and other related functionalities provided by the
livekit
package. Would you like more details on using this module? Sources: - https://livekit-users.slack.com/archives/C07FY8WHGPM/p1727992834.783299 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
w
@millions-hair-24956 AttributeError: 'JobContext' object has no attribute 'tts' got this error
g
It seems likely that the
JobContext
object does not directly have a
tts
attribute. To use Text-to-Speech (TTS) capabilities, you should ensure that you have initialized a TTS instance separately and are using it correctly within your code. Here's a basic example of how you might set up and use TTS in a LiveKit agent:
Copy code
from livekit import agents, rtc
from livekit.plugins import openai

async def entrypoint(ctx: agents.JobContext):
    # Initialize TTS
    tts = openai.TTS(api_key='your_openai_api_key')

    # Connect to the room
    await ctx.connect()

    # Wait for a participant
    participant = await ctx.wait_for_participant()

    # Use TTS to say a message
    await tts.synthesize("Hello, this is a test message.")

    # Disconnect the participant
    await ctx.room.disconnect()
Ensure that you have properly initialized the TTS instance and are calling its methods directly, rather than expecting it to be an attribute of
JobContext
. Would you like more details on setting up TTS? Sources: - https://docs.livekit.io/python/livekit/agents/pipeline/index.html#livekit.agents.pipeline.VoicePipelineAgent.MIN_TIME_PLAYED_FOR_COMMIT 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.