Update main.py
Browse files
main.py
CHANGED
@@ -3,27 +3,24 @@ import os
|
|
3 |
import sys
|
4 |
import time
|
5 |
import logging
|
6 |
-
|
7 |
from pipecat.frames.frames import (
|
8 |
TextFrame, UserStartedSpeakingFrame, UserStoppedSpeakingFrame,
|
9 |
-
TTSStartedFrame,
|
10 |
)
|
11 |
from pipecat.pipeline.pipeline import Pipeline
|
12 |
from pipecat.pipeline.runner import PipelineRunner
|
13 |
from pipecat.pipeline.task import PipelineParams
|
14 |
from pipecat.processors.frame_processor import FrameProcessor, FrameDirection
|
15 |
-
from pipecat.services.elevenlabs.tts import ElevenLabsTTSService
|
16 |
-
from pipecat.services.deepgram.stt import DeepgramSTTService
|
17 |
from pipecat.transports.services.daily import DailyParams, DailyTransport
|
18 |
-
from pipecat.vad.silero import SileroVADAnalyzer
|
19 |
from azure_openai import AzureOpenAILLMService
|
20 |
from elevenlabs import ElevenLabs
|
21 |
|
22 |
-
# Configure logging
|
23 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
24 |
logger = logging.getLogger(__name__)
|
25 |
|
26 |
-
# Configuration constants
|
27 |
SILENCE_TIMEOUT_SECONDS = float(os.environ.get("SILENCE_TIMEOUT_SECONDS", 10))
|
28 |
MAX_SILENCE_PROMPTS = int(os.environ.get("MAX_SILENCE_PROMPTS", 3))
|
29 |
SILENCE_PROMPT_TEXT = "Are you still there?"
|
@@ -62,12 +59,12 @@ class SilenceAndCallLogicProcessor(FrameProcessor):
|
|
62 |
self.last_activity_ts = time.time()
|
63 |
self.silence_prompts_count = 0
|
64 |
|
65 |
-
async def process_frame(self, frame, direction
|
66 |
if isinstance(frame, (UserStartedSpeakingFrame, TextFrame)) and direction == FrameDirection.UPSTREAM:
|
67 |
self._reset_activity_timer()
|
68 |
if isinstance(frame, TTSStartedFrame) and direction == FrameDirection.DOWNSTREAM:
|
69 |
self._bot_is_speaking = True
|
70 |
-
elif isinstance(frame,
|
71 |
self._bot_is_speaking = False
|
72 |
self.last_activity_ts = time.time()
|
73 |
await self.push_frame(frame, direction)
|
@@ -153,10 +150,12 @@ class PhoneChatbotApp:
|
|
153 |
return False
|
154 |
|
155 |
async def run(self):
|
156 |
-
required_keys = [
|
|
|
|
|
157 |
missing_keys = [key for key in required_keys if not os.environ.get(key)]
|
158 |
if missing_keys:
|
159 |
-
logger.error(f"Missing
|
160 |
sys.exit(1)
|
161 |
|
162 |
voice_id = os.environ.get("ELEVENLABS_VOICE_ID", "cgSgspJ2msm6clMCkdW9")
|
@@ -203,10 +202,3 @@ class PhoneChatbotApp:
|
|
203 |
await self.pipeline.stop_when_done()
|
204 |
if self.silence_processor:
|
205 |
await self.silence_processor.stop()
|
206 |
-
|
207 |
-
async def main():
|
208 |
-
app = PhoneChatbotApp()
|
209 |
-
await app.run()
|
210 |
-
|
211 |
-
if __name__ == "__main__":
|
212 |
-
asyncio.run(main())
|
|
|
3 |
import sys
|
4 |
import time
|
5 |
import logging
|
|
|
6 |
from pipecat.frames.frames import (
|
7 |
TextFrame, UserStartedSpeakingFrame, UserStoppedSpeakingFrame,
|
8 |
+
TTSStartedFrame, TTSEndFrame
|
9 |
)
|
10 |
from pipecat.pipeline.pipeline import Pipeline
|
11 |
from pipecat.pipeline.runner import PipelineRunner
|
12 |
from pipecat.pipeline.task import PipelineParams
|
13 |
from pipecat.processors.frame_processor import FrameProcessor, FrameDirection
|
14 |
+
from pipecat.services.elevenlabs.tts import ElevenLabsTTSService
|
15 |
+
from pipecat.services.deepgram.stt import DeepgramSTTService
|
16 |
from pipecat.transports.services.daily import DailyParams, DailyTransport
|
17 |
+
from pipecat.audio.vad.silero import SileroVADAnalyzer
|
18 |
from azure_openai import AzureOpenAILLMService
|
19 |
from elevenlabs import ElevenLabs
|
20 |
|
|
|
21 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
22 |
logger = logging.getLogger(__name__)
|
23 |
|
|
|
24 |
SILENCE_TIMEOUT_SECONDS = float(os.environ.get("SILENCE_TIMEOUT_SECONDS", 10))
|
25 |
MAX_SILENCE_PROMPTS = int(os.environ.get("MAX_SILENCE_PROMPTS", 3))
|
26 |
SILENCE_PROMPT_TEXT = "Are you still there?"
|
|
|
59 |
self.last_activity_ts = time.time()
|
60 |
self.silence_prompts_count = 0
|
61 |
|
62 |
+
async def process_frame(self, frame, direction):
|
63 |
if isinstance(frame, (UserStartedSpeakingFrame, TextFrame)) and direction == FrameDirection.UPSTREAM:
|
64 |
self._reset_activity_timer()
|
65 |
if isinstance(frame, TTSStartedFrame) and direction == FrameDirection.DOWNSTREAM:
|
66 |
self._bot_is_speaking = True
|
67 |
+
elif isinstance(frame, TTSEndFrame) and direction == FrameDirection.DOWNSTREAM:
|
68 |
self._bot_is_speaking = False
|
69 |
self.last_activity_ts = time.time()
|
70 |
await self.push_frame(frame, direction)
|
|
|
150 |
return False
|
151 |
|
152 |
async def run(self):
|
153 |
+
required_keys = [
|
154 |
+
"deepgram", "elevenlabs", "dailyco", "azure_openai"
|
155 |
+
]
|
156 |
missing_keys = [key for key in required_keys if not os.environ.get(key)]
|
157 |
if missing_keys:
|
158 |
+
logger.error(f"Missing environment variables: {', '.join(missing_keys)}")
|
159 |
sys.exit(1)
|
160 |
|
161 |
voice_id = os.environ.get("ELEVENLABS_VOICE_ID", "cgSgspJ2msm6clMCkdW9")
|
|
|
202 |
await self.pipeline.stop_when_done()
|
203 |
if self.silence_processor:
|
204 |
await self.silence_processor.stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|