cat agent.py /home/ubuntu/landing-denis-call/agent...
# ask-ai
m
cat agent.py # /home/ubuntu/landing-denis-call/agent.py from future import annotations import asyncio import logging import os import redis from dotenv import load_dotenv from livekit import rtc, api from livekit.agents import ( AutoSubscribe, JobContext, JobProcess, WorkerOptions, cli, llm, ) from livekit.agents.pipeline import VoicePipelineAgent from livekit.plugins import openai, silero, deepgram, elevenlabs from livekit import protocol import json load_dotenv(dotenv_path=".env.local") logger = logging.getLogger("VOICE-ASSISTANT") logger.setLevel(logging.DEBUG) outbound_trunk_id = os.getenv("SIP_OUTBOUND_TRUNK_ID") redis_client = redis.Redis( host='redis', port=6379, db=0, username='default', password='Y3v!n9L#f2@AFp$G1w^K8z*R' ) _instructions = ( "You are a friendly QFix Connect representative who speaks only in Turkish. " "Introduce yourself as Denis from QFix Connect in Turkish only, never mentioning AI. " "Maintain a warm, humorous, and casual approach." ) async def record_call(ctx: JobContext, phone_number: str): room_name = ctx.room.name cleaned_phone_number = phone_number.lstrip('+') # + işaretini kaldır filepath = f"outbound-{cleaned_phone_number}-{room_name}.m4a" logger.info(f"Starting recording for room: {room_name}, filepath: {filepath}") s3_upload = protocol.egress.S3Upload( access_key="AKIAX3B7KVP7FASNEQOB", secret="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", region="eu-central-1", bucket="asterisk-call-recordings", force_path_style=True # Endpoint kaldırıldı, eski haline döndü ) file_output = protocol.egress.EncodedFileOutput( filepath=filepath, s3=s3_upload ) req = protocol.egress.RoomCompositeEgressRequest( room_name=room_name, audio_only=True, file_outputs=[file_output], ) try: logger.debug(f"Sending start_room_composite_egress request: {req}") res = await ctx.api.egress.start_room_composite_egress(req) logger.info(f"Recording started with egress_id: {res.egress_id}") return res.egress_id except Exception as e: logger.error(f"Failed to start recording: {str(e)}") raise async def stop_recording(ctx: JobContext, egress_id: str, caller_number: str, call_to: str): if not egress_id: logger.warning("No recording to stop.") return try: logger.debug(f"Stopping recording with egress_id: {egress_id}") await ctx.api.egress.stop_egress(api.StopEgressRequest(egress_id=egress_id)) logger.info(f"Recording stopped for egress_id: {egress_id}") egress_info = { "egress_id": egress_id, "caller_number": caller_number, "call_to": call_to } redis_client.lpush("egress_ids", json.dumps(egress_info)) logger.info(f"Egress info {egress_info} Redis’e kaydedildi.") except Exception as e: logger.error(f"Failed to stop recording: {str(e)}") raise async def entrypoint(ctx: JobContext): logger.info(f"[OUTBOUND] connecting to room {ctx.room.name}") phone_number = ctx.job.metadata if not phone_number: logger.error("[OUTBOUND] No phone number provided in job metadata. Exiting.") ctx.shutdown() return if not outbound_trunk_id or not outbound_trunk_id.startswith("ST_"): logger.error("[OUTBOUND] SIP_OUTBOUND_TRUNK_ID is missing or invalid.") ctx.shutdown() return await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY) user_identity = "phone_user" logger.info(f"[OUTBOUND] Dialing {phone_number} with trunk={outbound_trunk_id}, room={ctx.room.name}") await ctx.api.sip.create_sip_participant( api.CreateSIPParticipantRequest( room_name=ctx.room.name, sip_trunk_id=outbound_trunk_id, sip_call_to=phone_number, participant_identity=user_identity, play_dialtone=True ) ) logger.info(f"[OUTBOUND] Waiting for SIP participant {user_identity}") participant = await ctx.wait_for_participant(identity=user_identity) logger.info(f"[OUTBOUND] SIP participant {user_identity} joined") egress_id = None agent_started = [False] caller_number = participant.attributes.get("sip.trunkPhoneNumber", "unknown") call_to = phone_number def on_track_subscribed(track, publication, participant): nonlocal agent_started, egress_id logger.debug(f"track_subscribed triggered for participant: {participant.identity}, track kind: {track.kind}") if participant.identity == user_identity and track.kind == rtc.TrackKind.KIND_AUDIO: logger.info("SIP audio track subscribed") if not agent_started[0]: logger.info("Starting voice pipeline agent from track subscription") run_voice_pipeline_agent(ctx, participant, _instructions) agent_started[0] = True if not egress_id: logger.debug("Starting recording task from track subscription") task = asyncio.create_task(record_call(ctx, phone_number)) task.add_done_callback(lambda fut: globals().update(egress_id=fut.result())) def on_participant_disconnected(participant: rtc.RemoteParticipant): nonlocal egress_id if participant.identity == user_identity: logger.info("SIP participant disconnected; stopping recording") if egress_id: asyncio.create_task(stop_recording(ctx, egress_id, caller_number, call_to)) ctx.room.on("track_subscribed", on_track_subscribed) ctx.room.on("participant_disconnected", on_participant_disconnected) await asyncio.sleep(2) if not agent_started[0]: logger.info("Track subscription not triggered, forcing voice pipeline agent start") run_voice_pipeline_agent(ctx, participant, _instructions) agent_started[0] = True if not egress_id: logger.debug("Track subscription not triggered, forcing recording start") egress_id = await record_call(ctx, phone_number) try: while True: await asyncio.sleep(1) except asyncio.CancelledError: logger.info("Agent job was cancelled.") if egress_id: await stop_recording(ctx, egress_id, caller_number, call_to) await asyncio.sleep(5) def run_voice_pipeline_agent(ctx: JobContext, participant: rtc.RemoteParticipant, instructions: str): logger.info("[OUTBOUND] Starting voice pipeline agent") initial_ctx = llm.ChatContext().append(role="system", text=instructions) fn_ctx = OutboundActions(ctx, participant) agent = VoicePipelineAgent( vad=ctx.proc.userdata["vad"], stt=deepgram.STT(model="nova-2-general", language="tr"), llm=openai.LLM(model="gpt-4o", temperature=0.2), tts=elevenlabs.TTS( model="eleven_turbo_v2_5", voice=elevenlabs.Voice( id="dOQlT8TikdF47jfPQXpe", name="Beyda", category="premade", settings=elevenlabs.VoiceSettings( stability=0.71, similarity_boost=0.5, style=0.0, use_speaker_boost=True ) ), language="tr", ), chat_ctx=initial_ctx, fnc_ctx=fn_ctx, ) agent.start(ctx.room, participant) logger.info("Agent started, sending initial message") asyncio.create_task(agent.say("Merhaba! Ben QFix Connect’ten Denis. Nasıl yardımcı olabilirim?", allow_interruptions=True)) class OutboundActions(llm.FunctionContext): def __init__(self, ctx: JobContext, participant: rtc.RemoteParticipant): super().__init__() self.ctx = ctx self.api = ctx.api self.participant = participant self.room = ctx.room async def end_call(self): logger.info(f"[OUTBOUND] user ended call => {self.participant.identity}") await self.api.room.remove_participant(api.RoomParticipantIdentity(room=self.room.name, identity=self.participant.identity)) self.ctx.shutdown() def prewarm(proc: JobProcess): proc.userdata["vad"] = silero.VAD.load() if name == "__main__": cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=prewarm, agent_name="landing-denis-call")) what is best room parameters for outbound calls for my agent ? when ı record routbound call room with egress, agent sound super clear but telephone users sound is so cripsy and bad . im usıng python agent framework . do the best configiratıon for outbıound calls . any parameters or code snippet s ? @millions-hair-24956
g
Outbound çağrılar için en iyi oda parametrelerini ayarlamak, ses kalitesini artırabilir. LiveKit'te, ses kalitesini etkileyen birkaç faktör vardır. Özellikle, ses codec'leri ve örnekleme oranları önemlidir. LiveKit SIP, HD Ses'i destekler ve bu, ses kalitesini artırabilir. G.722 veya Opus gibi geniş bant ses codec'lerini kullanmak, ses kalitesini artırabilir. Ayrıca, HD Ses yapılandırması ile ilgili belgeleri inceleyebilirsiniz. Ayrıca, sesin netliğini artırmak için ses işleme ayarlarını optimize edebilirsiniz. Örneğin, `silero.VAD`'in
activation_threshold
parametresini ayarlayarak ses algılama hassasiyetini değiştirebilirsiniz. VoicePipelineAgent kullanırken,
stt
ve
tts
ayarlarını da gözden geçirip, uygun modelleri seçmek önemlidir. Örneğin,
deepgram.STT
ve
elevenlabs.TTS
için doğru dil ve model ayarlarını kontrol edin. Daha fazla ayrıntı ister misiniz? Sources: - Configuring HD Voice for SIP - VoicePipelineAgent 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
evet @millions-hair-24956
g
Anladım, daha fazla ayrıntı sağlayayım. 1. Ses Codec'leri ve Örnekleme Oranları: LiveKit, HD Ses'i destekler ve bu, ses kalitesini artırabilir. G.722 veya Opus gibi geniş bant ses codec'lerini kullanmak, ses kalitesini artırabilir. Bu codec'ler, daha yüksek örnekleme oranları sunarak daha geniş bir frekans aralığını kapsar ve bu da daha net ses sağlar. HD Ses yapılandırması ile ilgili belgeleri inceleyebilirsiniz. 2. Voice Activity Detection (VAD) Ayarları:
silero.VAD
kullanıyorsanız,
activation_threshold
parametresini ayarlayarak ses algılama hassasiyetini değiştirebilirsiniz. Daha düşük bir eşik değeri, daha sessiz sesleri algılamaya yardımcı olabilir, ancak bu, istenmeyen gürültülerin de algılanmasına neden olabilir. VAD parametreleri hakkında daha fazla bilgi edinebilirsiniz. 3. STT ve TTS Ayarları:
deepgram.STT
ve
elevenlabs.TTS
için doğru dil ve model ayarlarını kontrol edin. Örneğin,
deepgram.STT
için
model="nova-2-general"
ve
language="tr"
ayarlarını kullanıyorsunuz. Bu ayarların doğru olduğundan emin olun ve gerekirse daha uygun bir model seçin. 4. Oda Ayarları: Oda ayarlarını optimize etmek için, `RoomOptions`'ı kullanarak ses işleme özelliklerini (örneğin, yankı iptali, gürültü bastırma) devre dışı bırakabilir veya ayarlayabilirsiniz. Bu, ses kalitesini artırabilir. Örnek bir yapılandırma kodu:
Copy code
room_options = RoomOptions(
    defaultAudioCaptureOptions=AudioCaptureOptions(
        echoCancellation=False,
        noiseSuppression=False
    ),
    defaultAudioPublishOptions=AudioPublishOptions(
        encoding=AudioEncoding(maxBitrate=320000),  # Yüksek kaliteli ses için
        dtx=False
    )
)
Bu ayarları deneyerek ses kalitesini artırabilirsiniz. Başka bir sorunuz var mı? Sources: - Configuring HD Voice for SIP - VAD Parameters 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
koduma nasıl entegreederım onerılerını daha fazla bılgı ver , userın sesı kotu sadece agentınkı mukemmel kayıtlarda @millions-hair-24956
g
Kullanıcı ses kalitesini artırmak için aşağıdaki adımları izleyebilirsiniz: 1. Ses Codec'lerini ve Örnekleme Oranlarını Ayarlayın: Kullanıcı ses kalitesini artırmak için geniş bant ses codec'leri kullanabilirsiniz. G.722 veya Opus gibi codec'ler, daha yüksek örnekleme oranları sunarak daha geniş bir frekans aralığını kapsar. Bu codec'leri kullanmak için SIP trunk sağlayıcınızın bu codec'leri desteklediğinden emin olun. 2. Ses İşleme Ayarlarını Optimize Edin: `RoomOptions`'ı kullanarak ses işleme özelliklerini ayarlayabilirsiniz. Yankı iptali ve gürültü bastırma gibi özellikleri devre dışı bırakmak, ses kalitesini artırabilir. Örneğin:
Copy code
room_options = RoomOptions(
       defaultAudioCaptureOptions=AudioCaptureOptions(
           echoCancellation=False,
           noiseSuppression=False
       ),
       defaultAudioPublishOptions=AudioPublishOptions(
           encoding=AudioEncoding(maxBitrate=320000),  # Yüksek kaliteli ses için
           dtx=False
       )
   )
3. VAD Ayarlarını Kontrol Edin:
silero.VAD
kullanıyorsanız,
activation_threshold
parametresini ayarlayarak ses algılama hassasiyetini değiştirebilirsiniz. Daha düşük bir eşik değeri, daha sessiz sesleri algılamaya yardımcı olabilir. 4. Ses Kaydını ve Egress Ayarlarını Kontrol Edin: Ses kaydını yaparken kullanılan ayarları kontrol edin. `RoomCompositeEgressRequest`'te
audio_only=True
ve uygun dosya formatı ve codec ayarlarını kullanarak ses kalitesini artırabilirsiniz. Kodunuza bu ayarları entegre etmek için, yukarıdaki örnekleri kullanarak
RoomOptions
ve
AudioCaptureOptions
ayarlarını güncelleyebilirsiniz. Ayrıca, SIP trunk sağlayıcınızın geniş bant codec'lerini desteklediğinden emin olun. Başka bir sorunuz var mı? Sources: - https://livekit-users.slack.com/archives/C07FY8WHGPM/p1729300506.093409 - https://docs.livekit.io/agents/plugins/#VAD-and-StreamAdapter 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
cevredekı konsuanları engellemek ıcın sıvero vad degerı ne olmalı ? kalabalıkta sadece konusanı algılasın ıstıyorum . @millions-hair-24956
g
Silero VAD
kullanarak çevredeki konuşmaları engellemek ve sadece konuşanı algılamak için
activation_threshold
değerini ayarlayabilirsiniz. Daha yüksek bir
activation_threshold
değeri, VAD'in daha az hassas olmasını sağlar ve sadece daha yüksek sesli konuşmaları algılar. Örneğin,
activation_threshold
değerini 0.6 veya 0.7 olarak ayarlamak, daha sessiz arka plan seslerini filtrelemeye yardımcı olabilir.
Copy code
vad = silero.VAD.load(activation_threshold=0.7)
Bu ayar, VAD'in sadece daha belirgin konuşmaları algılamasına yardımcı olabilir. Ancak, bu ayarın etkili olup olmadığını test etmek önemlidir, çünkü ortam gürültüsü ve konuşma dinamikleri farklılık gösterebilir. Daha fazla ayrıntı ister misiniz? Sources: - Silero VAD Documentation - LiveKit Slack Discussion 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
kalabalık bır oramda sesı kesıyor bunu onlemek ıstıyoruz @millions-hair-24956
g
Kalabalık bir ortamda ses kesilmesini önlemek için
Silero VAD
ayarlarını optimize edebilirsiniz.
activation_threshold
değerini düşürmek, VAD'in daha hassas olmasını sağlar ve daha sessiz sesleri algılamasına yardımcı olabilir. Örneğin,
activation_threshold
değerini 0.5 veya daha düşük bir seviyeye ayarlayarak, VAD'in daha fazla sesi algılamasını sağlayabilirsiniz.
Copy code
vad = silero.VAD.load(activation_threshold=0.5)
Ayrıca,
min_silence_duration
ve
min_speech_duration
gibi diğer VAD parametrelerini de ayarlayarak, konuşma algılama hassasiyetini artırabilirsiniz. Bu ayarları test ederek, ortamınıza en uygun değerleri bulabilirsiniz. Daha fazla ayrıntı ister misiniz? Sources: - LiveKit Slack Discussion 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
i dont want extra sensıtıve , i want noise supressıon , sometımes we are ın crowd agent stop speakıng because of thıs .
i dont want extra sensıtıve , i want noise supressıon , sometımes we are ın crowd agent stop speakıng because of thıs . @millions-hair-24956
g
Kalabalık ortamlarda gürültü bastırma sağlamak ve ajanın konuşmasını kesmesini önlemek için, LiveKit'in Krisp entegrasyonunu kullanabilirsiniz. Krisp, AI tabanlı gelişmiş gürültü bastırma teknolojisi sunar ve bu, özellikle kalabalık ortamlarda arka plan gürültüsünü azaltmada etkilidir. Krisp entegrasyonu, LiveKit Cloud projelerinde Scale veya Enterprise planlarında kullanılabilir. Krisp entegrasyonunu etkinleştirmek için, LiveKit projenizde Krisp gürültü filtresini kurmanız ve etkinleştirmeniz gerekmektedir. İşte temel adımlar: 1. Krisp Gürültü Filtresini Kurun: Projenize Krisp gürültü filtresini ekleyin.
Copy code
import { KrispNoiseFilter } from '@livekit/krisp-noise-filter';
2. Krisp Gürültü Filtresini Etkinleştirin: Mikrofon kaynağınız için Krisp filtresini etkinleştirin.
Copy code
room.on(RoomEvent.LocalTrackPublished, async (trackPublication) => {
       if (trackPublication.source === Track.Source.Microphone && trackPublication.track instanceof LocalAudioTrack) {
           const krispProcessor = KrispNoiseFilter();
           await trackPublication.track.setProcessor(krispProcessor);
       }
   });
Bu adımlar, ajanın kalabalık ortamlarda daha iyi performans göstermesine yardımcı olabilir. Daha fazla ayrıntı ister misiniz? Sources: - Enhanced Noise Cancellation with Krisp 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
im using python , and sip phone . @millions-hair-24956
g
Python ve SIP telefon kullanıyorsanız, gürültü bastırma için Krisp entegrasyonunu doğrudan kullanamayabilirsiniz, çünkü Krisp genellikle tarayıcı tabanlı uygulamalar için uygundur. Ancak, Python tabanlı bir çözüm için aşağıdaki adımları deneyebilirsiniz: 1. Ses İşleme Kütüphaneleri: Python'da ses işleme için
pydub
veya
scipy
gibi kütüphaneleri kullanarak temel gürültü azaltma işlemleri yapabilirsiniz. Ancak, bu kütüphaneler gerçek zamanlı gürültü bastırma için sınırlı olabilir. 2. VAD Ayarlarını Optimize Etme:
Silero VAD
kullanıyorsanız,
activation_threshold
değerini ayarlayarak VAD'in daha az hassas olmasını sağlayabilirsiniz. Bu, arka plan gürültüsünün algılanmasını azaltabilir. 3. Gürültü Bastırma Modelleri: Python'da gürültü bastırma için
noisereduce
gibi kütüphaneleri kullanabilirsiniz. Bu kütüphane, ses dosyalarındaki gürültüyü azaltmak için uygundur, ancak gerçek zamanlı uygulamalar için optimize edilmemiş olabilir. Örnek bir
noisereduce
kullanımı:
Copy code
import noisereduce as nr
import soundfile as sf

# Ses dosyasını yükle
data, rate = sf.read('input.wav')

# Gürültü bastırma
reduced_noise = nr.reduce_noise(y=data, sr=rate)

# Sonucu kaydet
sf.write('output.wav', reduced_noise, rate)
Bu yöntemler, Python ve SIP telefon kullanırken gürültü bastırma sağlamaya yardımcı olabilir. Daha fazla ayrıntı ister misiniz? Sources: - https://docs.livekit.io/agents/voice-agent/ - https://docs.livekit.io/agents/openai/customize/turn-detection/ 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
STANT", "pid": 30, "timestamp": "2025-02-27T190617.938206+00:00"} landing-denis-call | {"message": "job process initialized", "level": "INFO", "name": "livekit.agents", "pid": 30, "timestamp": "2025-02-27T190617.938447+00:00"} landing-denis-call | {"message": "initializing job process", "level": "INFO", "name": "livekit.agents", "pid": 41, "timestamp": "2025-02-27T190619.077826+00:00"} landing-denis-call | {"message": "Prewarm completed: VAD loaded.", "level": "INFO", "name": "VOICE-ASSISTANT", "pid": 41, "timestamp": "2025-02-27T190619.125209+00:00"} landing-denis-call | {"message": "job process initialized", "level": "INFO", "name": "livekit.agents", "pid": 41, "timestamp": "2025-02-27T190619.125484+00:00"} landing-denis-call | {"message": "received job request", "level": "INFO", "name": "livekit.agents", "job_id": "AJ_skfCe3BjAnUi", "dispatch_id": "AD_h8ApkUvU7eF9", "room_name": "room-efhNH6RyGtio", "agent_name": "landing-denis-call", "resuming": false, "timestamp": "2025-02-27T190629.358466+00:00"} landing-denis-call | {"message": "[OUTBOUND] connecting to room room-efhNH6RyGtio", "level": "INFO", "name": "VOICE-ASSISTANT", "pid": 18, "job_id": "AJ_skfCe3BjAnUi", "timestamp": "2025-02-27T190629.359745+00:00"} landing-denis-call | {"message": "unhandled exception while running the job task\nTraceback (most recent call last):\n File \"/app/agent.py\", line 123, in entrypoint\n await ctx.api.room.update_room(\n ^^^^^^^^^^^^^^^^^^^^^^^^\nAttributeError: 'RoomService' object has no attribute 'update_room'", "level": "ERROR", "name": "livekit.agents", "pid": 18, "job_id": "AJ_skfCe3BjAnUi", "timestamp": "2025-02-27T190629.360087+00:00"} landing-denis-call | {"message": "initializing job process", "level": "INFO", "name": "livekit.agents", "pid": 70, "timestamp": "2025-02-27T190630.492432+00:00"} landing-denis-call | {"message": "Prewarm completed: VAD loaded.", "level": "INFO", "name": "VOICE-ASSISTANT", "pid": 70, "timestamp": "2025-02-27T190630.538732+00:00"} landing-denis-call | {"message": "job process initialized", "level": "INFO", "name": "livekit.agents", "pid": 70, "timestamp": "2025-02-27T190630.538965+00:00"} how to update room with parameters ?
STANT", "pid": 30, "timestamp": "2025-02-27T190617.938206+00:00"} landing-denis-call | {"message": "job process initialized", "level": "INFO", "name": "livekit.agents", "pid": 30, "timestamp": "2025-02-27T190617.938447+00:00"} landing-denis-call | {"message": "initializing job process", "level": "INFO", "name": "livekit.agents", "pid": 41, "timestamp": "2025-02-27T190619.077826+00:00"} landing-denis-call | {"message": "Prewarm completed: VAD loaded.", "level": "INFO", "name": "VOICE-ASSISTANT", "pid": 41, "timestamp": "2025-02-27T190619.125209+00:00"} landing-denis-call | {"message": "job process initialized", "level": "INFO", "name": "livekit.agents", "pid": 41, "timestamp": "2025-02-27T190619.125484+00:00"} landing-denis-call | {"message": "received job request", "level": "INFO", "name": "livekit.agents", "job_id": "AJ_skfCe3BjAnUi", "dispatch_id": "AD_h8ApkUvU7eF9", "room_name": "room-efhNH6RyGtio", "agent_name": "landing-denis-call", "resuming": false, "timestamp": "2025-02-27T190629.358466+00:00"} landing-denis-call | {"message": "[OUTBOUND] connecting to room room-efhNH6RyGtio", "level": "INFO", "name": "VOICE-ASSISTANT", "pid": 18, "job_id": "AJ_skfCe3BjAnUi", "timestamp": "2025-02-27T190629.359745+00:00"} landing-denis-call | {"message": "unhandled exception while running the job task\nTraceback (most recent call last):\n File \"/app/agent.py\", line 123, in entrypoint\n await ctx.api.room.update_room(\n ^^^^^^^^^^^^^^^^^^^^^^^^\nAttributeError: 'RoomService' object has no attribute 'update_room'", "level": "ERROR", "name": "livekit.agents", "pid": 18, "job_id": "AJ_skfCe3BjAnUi", "timestamp": "2025-02-27T190629.360087+00:00"} landing-denis-call | {"message": "initializing job process", "level": "INFO", "name": "livekit.agents", "pid": 70, "timestamp": "2025-02-27T190630.492432+00:00"} landing-denis-call | {"message": "Prewarm completed: VAD loaded.", "level": "INFO", "name": "VOICE-ASSISTANT", "pid": 70, "timestamp": "2025-02-27T190630.538732+00:00"} landing-denis-call | {"message": "job process initialized", "level": "INFO", "name": "livekit.agents", "pid": 70, "timestamp": "2025-02-27T190630.538965+00:00"} how to update room with parameters ? @millions-hair-24956
g
It seems that you are trying to use a method
update_room
on a
RoomService
object, but this method does not exist according to the provided data sources. To update room parameters, you might need to use the
UpdateRoomMetadata
method instead, which is part of the RoomService API. Here's a general approach to update room metadata: 1. Use the Correct API Method: Instead of
update_room
, use
UpdateRoomMetadata
to update the room's metadata. This method allows you to change the metadata associated with a room. 2. Example Code:
Copy code
from livekit import api

   async def update_room_metadata(ctx, room_name, new_metadata):
       try:
           await ctx.api.room.update_room_metadata(
               api.UpdateRoomMetadataRequest(
                   room=room_name,
                   metadata=new_metadata
               )
           )
           print(f"Room metadata updated for {room_name}")
       except Exception as e:
           print(f"Failed to update room metadata: {str(e)}")
3. Ensure Correct API Usage: Make sure you have the necessary permissions and that the API key used has the
roomAdmin
permission to perform this operation. If you need further details or have specific parameters you want to update, please let me know! Sources: - https://docs.livekit.io/server/room-management/#GetParticipant - https://docs.livekit.io/home/client/data/participant-attributes/ Note: I wasn’t able to find highly relevant data sources, but above are a few potentially relevant links. 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
how to add sound specs to room ? @millions-hair-24956
g
To add sound specifications to a room in LiveKit, you can configure audio settings using
RoomOptions
when creating or updating a room. This involves setting parameters for audio capture and publish options to control aspects like bitrate, echo cancellation, and noise suppression. Here's a basic example of how you can set audio specifications using
RoomOptions
in a Python environment:
Copy code
from livekit import rtc

# Define room options with specific audio settings
room_options = rtc.RoomOptions(
    default_audio_capture_options=rtc.AudioCaptureOptions(
        echo_cancellation=True,
        noise_suppression=True,
        auto_gain_control=True
    ),
    default_audio_publish_options=rtc.AudioPublishOptions(
        audio_bitrate=64000,  # Set the desired audio bitrate
        dtx=True  # Enable discontinuous transmission
    )
)

# Use these options when creating or updating a room
Key Parameters: - echo_cancellation: Reduces echo in audio streams. - noise_suppression: Minimizes background noise. - auto_gain_control: Automatically adjusts the microphone gain. - audio_bitrate: Sets the bitrate for audio streams, affecting quality and bandwidth usage. - dtx (Discontinuous Transmission): Saves bandwidth by not sending silent packets. These settings can be adjusted based on your specific requirements for audio quality and network conditions. Would you like more detailed guidance on any specific parameter? Sources: - Audio Configuration in LiveKit 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
im using pyhton so how to add sound specs to room ? @millions-hair-24956
g
To configure sound specifications for a room in LiveKit using Python, you can set audio options when creating or managing a room. This involves specifying parameters for audio capture and publish options to control features like echo cancellation, noise suppression, and bitrate. Here's how you can set these audio specifications using the LiveKit Python SDK:
Copy code
from livekit import rtc

# Define audio capture options
audio_capture_options = rtc.AudioCaptureOptions(
    echo_cancellation=True,  # Enable echo cancellation
    noise_suppression=True,  # Enable noise suppression
    auto_gain_control=True   # Enable automatic gain control
)

# Define audio publish options
audio_publish_options = rtc.AudioPublishOptions(
    audio_bitrate=64000,  # Set the desired audio bitrate
    dtx=True              # Enable discontinuous transmission
)

# Create room options with the specified audio settings
room_options = rtc.RoomOptions(
    default_audio_capture_options=audio_capture_options,
    default_audio_publish_options=audio_publish_options
)

# Use these options when creating or updating a room
Key Parameters: - echo_cancellation: Helps reduce echo in audio streams. - noise_suppression: Minimizes background noise for clearer audio. - auto_gain_control: Automatically adjusts the microphone gain to maintain consistent audio levels. - audio_bitrate: Sets the bitrate for audio streams, which affects both quality and bandwidth usage. - dtx (Discontinuous Transmission): Saves bandwidth by not sending silent packets. These settings can be adjusted based on your specific requirements for audio quality and network conditions. If you need further assistance or have specific requirements, feel free to ask! Sources: - https://livekit-users.slack.com/archives/C07FVFGAUKX/p1733152587.089089 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
is this params good for low latency outbound callls i need to use opus encoding = protocol.egress.EncodingOptions( audio_bitrate=64000, # Agentın önerdiği 64 kbps bitrate audio_sample_rate=48000, # 48 kHz örnekleme oranı ) @millions-hair-24956
g
Opus codec kullanarak düşük gecikmeli outbound çağrılar için belirttiğiniz parametreler genellikle uygundur. Opus, düşük gecikme ve yüksek ses kalitesi sağlamak için tasarlanmıştır. İşte parametrelerinizin değerlendirmesi: 1. audio_bitrate=64000: 64 kbps, Opus için iyi bir denge sağlar. Bu bitrate, konuşma için yeterli kaliteyi sunarken, bant genişliği kullanımını da optimize eder. Düşük gecikme için uygun bir değerdir. 2. audio_sample_rate=48000: 48 kHz örnekleme oranı, yüksek kaliteli ses sağlar ve Opus codec ile uyumludur. Bu örnekleme oranı, geniş bir frekans aralığını kapsar ve sesin netliğini artırır. Bu ayarlar, düşük gecikmeli ve kaliteli ses iletimi için uygundur. Ancak, ağ koşullarınıza ve uygulama gereksinimlerinize göre ayarları test etmek önemlidir. Daha fazla ayrıntı veya başka bir konuda yardım ister misiniz? Sources: - https://livekit-users.slack.com/archives/C07FVFARRK7/p1730731323.248749 - https://livekit-users.slack.com/archives/C07FYCB7FRQ/p1728674567.746139 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
Here's how you can set these audio specifications using the LiveKit Python SDK:
Copy code
from livekit import rtc

# Define audio capture options
audio_capture_options = rtc.AudioCaptureOptions(
    echo_cancellation=True,  # Enable echo cancellation
    noise_suppression=True,  # Enable noise suppression
    auto_gain_control=True   # Enable automatic gain control
)

# Define audio publish options
audio_publish_options = rtc.AudioPublishOptions(
    audio_bitrate=64000,  # Set the desired audio bitrate
    dtx=True              # Enable discontinuous transmission
)

# Create room options with the specified audio settings
room_options = rtc.RoomOptions(
    default_audio_capture_options=audio_capture_options,
    default_audio_publish_options=audio_publish_options
)

# Use these options when creating or updating a room
bunu koda nasıla dapt edıcem gıve me a code snıppet @millions-hair-24956
g
LiveKit Python SDK kullanarak ses özelliklerini ayarlamak için aşağıdaki kod örneğini kullanabilirsiniz. Bu örnek, ses yakalama ve yayınlama seçeneklerini ayarlayarak bir oda oluşturmayı veya güncellemeyi gösterir.
Copy code
from livekit import rtc

# Define audio capture options
audio_capture_options = rtc.AudioCaptureOptions(
    echo_cancellation=True,  # Yankı iptali etkinleştir
    noise_suppression=True,  # Gürültü bastırma etkinleştir
    auto_gain_control=True   # Otomatik kazanç kontrolü etkinleştir
)

# Define audio publish options
audio_publish_options = rtc.AudioPublishOptions(
    audio_bitrate=64000,  # İstenen ses bitrate'ini ayarla
    dtx=True              # Kesintili iletimi etkinleştir
)

# Create room options with the specified audio settings
room_options = rtc.RoomOptions(
    default_audio_capture_options=audio_capture_options,
    default_audio_publish_options=audio_publish_options
)

# Function to create or update a room with the specified options
async def create_or_update_room(api_client, room_name):
    try:
        # Create or update the room with the specified options
        await api_client.room.create_room(
            name=room_name,
            options=room_options
        )
        print(f"Room '{room_name}' created or updated successfully with specified audio settings.")
    except Exception as e:
        print(f"Failed to create or update room: {str(e)}")

# Example usage
# Assuming you have an API client instance
# api_client = YourApiClientInstance()
# asyncio.run(create_or_update_room(api_client, "your-room-name"))
Açıklamalar: - audio_capture_options: Yankı iptali, gürültü bastırma ve otomatik kazanç kontrolü gibi ses işleme özelliklerini ayarlamak için kullanılır. - audio_publish_options: Ses bitrate'ini ve kesintili iletimi ayarlamak için kullanılır. - room_options: Oda oluşturma veya güncelleme sırasında kullanılacak ses ayarlarını içerir. Bu kodu, LiveKit API istemcinizle entegre ederek odalarınızı oluşturabilir veya güncelleyebilirsiniz. Başka bir konuda yardım ister misiniz? Sources: - https://livekit-users.slack.com/archives/C07FVFGAUKX/p1733152587.089089 - https://livekit-users.slack.com/archives/C07FVFGAUKX/p1732387962.900529 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
no i want to use this inside my agent.py code ! @millions-hair-24956
g
To integrate the audio specifications directly into your
agent.py
code, you can set the audio options when initializing the room connection within the agent's entrypoint function. Here's how you can modify your
agent.py
to include these audio settings:
Copy code
from livekit import rtc, api
from livekit.agents import JobContext, WorkerOptions, cli

# Define audio capture options
audio_capture_options = rtc.AudioCaptureOptions(
    echo_cancellation=True,  # Enable echo cancellation
    noise_suppression=True,  # Enable noise suppression
    auto_gain_control=True   # Enable automatic gain control
)

# Define audio publish options
audio_publish_options = rtc.AudioPublishOptions(
    audio_bitrate=64000,  # Set the desired audio bitrate
    dtx=True              # Enable discontinuous transmission
)

# Create room options with the specified audio settings
room_options = rtc.RoomOptions(
    default_audio_capture_options=audio_capture_options,
    default_audio_publish_options=audio_publish_options
)

async def entrypoint(ctx: JobContext):
    # Connect to the room with the specified audio settings
    await ctx.connect(
        auto_subscribe=rtc.AutoSubscribe.AUDIO_ONLY,
        room_options=room_options
    )
    
    # Your existing logic for handling participants and tracks
    # ...

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
Key Points: - room_options: This is where you define the audio settings for echo cancellation, noise suppression, and bitrate. - ctx.connect: When connecting to the room, pass the
room_options
to apply these settings. This setup ensures that your agent uses the specified audio settings when connecting to a room. If you have any further questions or need additional modifications, feel free to ask! Sources: - https://livekit-users.slack.com/archives/C07FY8WHGPM/p1728956116.368569 - https://livekit-users.slack.com/archives/C07FY8WHGPM/p1731400051.109939 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
ng-denis-call | ^^^^^^^^^^^^^^^^^^^^^^^ landing-denis-call | AttributeError: module 'livekit.rtc' has no attribute 'AudioCaptureOptions' landing-denis-call | Traceback (most recent call last): landing-denis-call | File "/app/agent.py", line 48, in <module> landing-denis-call | audio_capture_options = rtc.AudioCaptureOptions( landing-denis-call | ^^^^^^^^^^^^^^^^^^^^^^^ landing-denis-call | AttributeError: module 'livekit.rtc' has no attribute 'AudioCaptureOptions' landing-denis-call | Traceback (most recent call last): @millions-hair-24956
g
It seems that the
AudioCaptureOptions
attribute is not available in the
livekit.rtc
module, which is causing the
AttributeError
. This could be due to a few reasons, such as using an outdated version of the LiveKit Python SDK or a misconfiguration in the code. Here are some steps you can take to resolve this issue: 1. Check LiveKit SDK Version: Ensure that you are using the latest version of the LiveKit Python SDK. You can update the SDK using pip:
Copy code
pip install --upgrade livekit
2. Verify Available Attributes: Double-check the available attributes in the
livekit.rtc
module. You can do this by printing the available attributes:
Copy code
import livekit.rtc
   print(dir(livekit.rtc))
This will help you verify if
AudioCaptureOptions
or similar attributes are available. 3. Consult Documentation: Refer to the LiveKit Python SDK documentation to ensure you are using the correct classes and methods for configuring audio options. 4. Alternative Configuration: If
AudioCaptureOptions
is not available, you may need to configure audio settings using a different approach or consult the documentation for alternative methods. If you continue to experience issues, please provide more details about your environment and the specific version of the LiveKit SDK you are using. This will help in providing more targeted assistance. Sources: - LiveKit Python SDK documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
livekit>=0.18.2 livekit-agents>=0.12.1 livekit-plugins-openai>=0.10.9 livekit-plugins-deepgram>=0.6.13 livekit-plugins-silero>=0.7.4 livekit-plugins-google==0.10.1 livekit-plugins-elevenlabs==0.7.11 python-dotenv~=1.0 redis==4.5.1 grpcio requests==2.32.3 pydub wave livekit-api boto3 aiohttp is my livekit latest ? @millions-hair-24956
g
Sorunuz için teşekkürler. Verdiğiniz sürüm bilgilerine göre, LiveKit ve ilgili eklentilerinizin sürümleri oldukça güncel görünüyor. Ancak, en son sürümleri kullandığınızdan emin olmak için aşağıdaki adımları izleyebilirsiniz: 1. Paketlerin Güncellenmesi: Aşağıdaki komutu kullanarak tüm paketlerinizi güncelleyebilirsiniz:
Copy code
pip install --upgrade livekit livekit-agents livekit-plugins-openai livekit-plugins-deepgram livekit-plugins-silero livekit-plugins-google livekit-plugins-elevenlabs
2. Sürüm Kontrolü: Aşağıdaki komutla yüklü paketlerin sürümlerini kontrol edebilirsiniz:
Copy code
pip list | grep livekit
Bu adımlar, LiveKit ve eklentilerinizin en son sürümlerini kullandığınızdan emin olmanıza yardımcı olacaktır. Eğer daha fazla yardıma ihtiyacınız olursa, lütfen LiveKit destek ekibiyle iletişime geçin. 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
im in docker @millions-hair-24956 how to check which livekit im usıng
g
Docker ortamında hangi LiveKit sürümünü kullandığınızı kontrol etmek için aşağıdaki adımları izleyebilirsiniz: 1. Docker Container İçine Giriş Yapın: İlk olarak, çalışmakta olan Docker konteynerinize giriş yapmanız gerekiyor. Bunu aşağıdaki komutla yapabilirsiniz:
Copy code
docker exec -it <container_id_or_name> /bin/bash
<container_id_or_name>
kısmını, kontrol etmek istediğiniz konteynerin ID'si veya adı ile değiştirin. 2. Paket Sürümünü Kontrol Edin: Konteyner içinde, yüklü Python paketlerinin sürümlerini kontrol etmek için aşağıdaki komutu çalıştırabilirsiniz:
Copy code
pip list | grep livekit
Bu komut, yüklü olan LiveKit ve ilgili eklentilerin sürümlerini listeleyecektir. Bu adımlar, Docker konteynerinizde hangi LiveKit sürümünü kullandığınızı belirlemenize yardımcı olacaktır. Başka bir konuda yardıma ihtiyacınız olursa, lütfen belirtin. Sources: - https://livekit-users.slack.com/archives/C07FY8WHGPM/p1730673248.486419 - https://livekit-users.slack.com/archives/C07FVFGAUKX/p1728090807.132609 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
docker exec -it livekit_server /bin/bash OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown @millions-hair-24956
g
Bu hata, Docker konteynerinizde
/bin/bash
kabuğunun bulunmadığını gösteriyor. Bu genellikle daha hafif Docker imajları (örneğin, Alpine Linux) kullanıldığında meydana gelir, çünkü bu imajlar varsayılan olarak
bash
yerine
sh
gibi daha hafif kabuklar içerir. Bu durumda, aşağıdaki adımları izleyebilirsiniz: 1. Alternatif Kabuk Kullanımı: Eğer
bash
yoksa,
sh
kabuğunu kullanarak konteynere girebilirsiniz:
Copy code
docker exec -it <container_id_or_name> /bin/sh
<container_id_or_name>
kısmını, kontrol etmek istediğiniz konteynerin ID'si veya adı ile değiştirin. 2. Konteyner İmajını Kontrol Edin: Eğer
sh
kabuğu da yoksa, kullandığınız Docker imajının belgelerini kontrol ederek hangi kabukların mevcut olduğunu öğrenebilirsiniz. Bu adımlar, Docker konteynerinize erişmenize ve gerekli kontrolleri yapmanıza yardımcı olacaktır. Başka bir konuda yardıma ihtiyacınız olursa, lütfen belirtin. Sources: - https://livekit-users.slack.com/archives/C07FRP66XGE/p1732019649.386179 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
, "pid": 18, "job_id": "AJ_4xecx65wFytp", "timestamp": "2025-02-27T195838.442398+00:00"} landing-denis-call | {"message": "Starting recording for room: room-Ba6GxXTThvvc, filepath: outbound-905421950620-room-Ba6GxXTThvvc.m4a", "level": "INFO", "name": "VOICE-ASSISTANT", "pid": 18, "job_id": "AJ_4xecx65wFytp", "timestamp": "2025-02-27T195838.442505+00:00"} landing-denis-call | {"message": "unhandled exception while running the job task\nTraceback (most recent call last):\n File \"/app/agent.py\", line 178, in entrypoint\n egress_id = await record_call(ctx, phone_number)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/app/agent.py\", line 68, in record_call\n encoding = protocol.egress.EncodingOptions(\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nValueError: Protocol message EncodingOptions has no \"audio_sample_rate\" field.", "level": "ERROR", "name": "livekit.agents", "pid": 18, "job_id": "AJ_4xecx65wFytp", "timestamp": "2025-02-27T195838.442622+00:00"} you gıve me wrong parameters . @millions-hair-24956
g
Görünüşe göre
EncodingOptions
içinde
audio_sample_rate
alanı bulunmuyor ve bu nedenle bir
ValueError
alıyorsunuz. Bu, LiveKit Python SDK'sında
EncodingOptions
sınıfının bu alanı desteklemediğini gösteriyor. Doğru parametreleri kullanarak `EncodingOptions`'ı nasıl ayarlayabileceğinizi göstereyim:
Copy code
from livekit import protocol

# Define encoding options without audio_sample_rate
encoding_options = protocol.egress.EncodingOptions(
    audio_bitrate=64000  # Set the desired audio bitrate
    # Remove audio_sample_rate as it is not supported
)

# Use encoding options in your egress request
file_output = protocol.egress.EncodedFileOutput(
    filepath="outbound-905421950620-room-Ba6GxXTThvvc.m4a",
    encoding_options=encoding_options
)

# Example egress request
egress_request = protocol.egress.RoomCompositeEgressRequest(
    room_name="room-Ba6GxXTThvvc",
    audio_only=True,
    file_outputs=[file_output]
)

# Function to start recording
async def record_call(ctx, phone_number):
    try:
        res = await ctx.api.egress.start_room_composite_egress(egress_request)
        print(f"Recording started with egress_id: {res.egress_id}")
        return res.egress_id
    except Exception as e:
        print(f"Failed to start recording: {str(e)}")
        raise
Açıklamalar: - audio_bitrate: Ses bitrate'ini ayarlamak için kullanılır.
audio_sample_rate
alanı desteklenmediği için kaldırılmıştır. - encoding_options:
EncodingOptions
içinde sadece desteklenen alanları kullanın. Bu değişiklikler,
ValueError
hatasını çözmenize yardımcı olacaktır. Başka bir konuda yardıma ihtiyacınız olursa, lütfen belirtin. Sources: - https://docs.livekit.io/home/egress/api/#DirectFileOutput - https://docs.livekit.io/home/egress/api/ 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
m
| 2025-02-27T201934.798Z INFO sip sip/inbound.go:173 processing invite {"nodeID": "NE_JqUsGrfwQTjf", "callID": "SCL_XubV68egB4ys", "fromIP": "162.243.10.169", "toIP": "18.184.217.4:5060", "fromHost": "1.1.1.1", "fromUser": "100", "toHost": "1.1.1.1", "toUser": "100", "sipTag": "31326238643930343133633401383835363736313535", "sipCallID": "1060962311795574933117669"} sip_server | 2025-02-27T201934.802Z DEBUG sip sip/inbound.go:413 Rejecting inbound flood {"nodeID": "NE_JqUsGrfwQTjf", "callID": "SCL_XubV68egB4ys", "fromIP": "162.243.10.169", "toIP": "18.184.217.4:5060", "fromHost": "1.1.1.1", "fromUser": "100", "toHost": "1.1.1.1", "toUser": "100", "sipTag": "31326238643930343133633401383835363736313535", "sipCallID": "1060962311795574933117669"} sip_server | 2025-02-27T201934.802Z INFO sip sip/inbound.go:714 Closing inbound call {"nodeID": "NE_JqUsGrfwQTjf", "callID": "SCL_XubV68egB4ys", "fromIP": "162.243.10.169", "toIP": "18.184.217.4:5060", "fromHost": "1.1.1.1", "fromUser": "100", "toHost": "1.1.1.1", "toUser": "100", "sipTag": "31326238643930343133633401383835363736313535", "sipCallID": "1060962311795574933117669", "reason": "flood"} how to prevent this ? @millions-hair-24956
g
Görünüşe göre SIP sunucunuz, gelen çağrıları "flood" (aşırı yük) olarak algılıyor ve bu nedenle çağrılar reddediliyor. Bu tür sorunları önlemek için aşağıdaki adımları izleyebilirsiniz: 1. Rate Limiting (Hız Sınırlandırma): Gelen çağrılar için hız sınırlandırma uygulayarak, belirli bir süre içinde kabul edilebilecek maksimum çağrı sayısını sınırlayabilirsiniz. Bu, sunucunun aşırı yüklenmesini önlemeye yardımcı olabilir. 2. IP Whitelisting (IP Beyaz Listeleme): Sadece belirli IP adreslerinden gelen çağrılara izin vererek, istenmeyen veya kötü niyetli çağrıları engelleyebilirsiniz. Bu, güvenilir IP adreslerini beyaz listeye ekleyerek yapılabilir. 3. Firewall Ayarları: Güvenlik duvarı kurallarınızı gözden geçirerek, sadece belirli IP adreslerinden veya IP aralıklarından gelen SIP trafiğine izin verebilirsiniz. 4. SIP Trunk Ayarları: SIP trunk sağlayıcınızın ayarlarını kontrol edin ve sadece belirli numaralardan veya IP adreslerinden gelen çağrılara izin verildiğinden emin olun. 5. Log Analizi: Logları düzenli olarak analiz ederek, hangi IP adreslerinden veya numaralardan aşırı çağrı geldiğini tespit edebilir ve bu adresleri engelleyebilirsiniz. Bu adımlar, SIP sunucunuzun aşırı yüklenmesini önlemeye yardımcı olabilir. Daha fazla ayrıntı veya başka bir konuda yardım ister misiniz? Sources: - https://livekit-users.slack.com/archives/C07FRP66XGE/p1731980365.334299 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.