Deadmon commited on
Commit
43b917a
·
verified ·
1 Parent(s): 13df605

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -9
main.py CHANGED
@@ -5,7 +5,7 @@ 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
@@ -61,12 +61,12 @@ class SilenceAndCallLogicProcessor(FrameProcessor):
61
  self.last_activity_ts = time.time()
62
  self.silence_prompts_count = 0
63
 
64
- async def process_frame(self, frame: Frame, direction: FrameDirection):
65
  if isinstance(frame, (UserStartedSpeakingFrame, TextFrame)) and direction == FrameDirection.UPSTREAM:
66
  self._reset_activity_timer()
67
  if isinstance(frame, TTSStartedFrame) and direction == FrameDirection.DOWNSTREAM:
68
  self._bot_is_speaking = True
69
- elif isinstance(frame, TTSEndFrame) and direction == FrameDirection.DOWNSTREAM:
70
  self._bot_is_speaking = False
71
  self.last_activity_ts = time.time()
72
  await self.push_frame(frame, direction)
@@ -152,16 +152,12 @@ class PhoneChatbotApp:
152
  return False
153
 
154
  async def run(self):
155
- # Validate environment variables (Hugging Face Secrets)
156
- required_keys = [
157
- "deepgram", "elevenlabs", "dailyco", "azure_openai"
158
- ]
159
  missing_keys = [key for key in required_keys if not os.environ.get(key)]
160
  if missing_keys:
161
  logger.error(f"Missing Hugging Face Secrets: {', '.join(missing_keys)}")
162
  sys.exit(1)
163
 
164
- # Validate ElevenLabs voice ID
165
  voice_id = os.environ.get("ELEVENLABS_VOICE_ID", "cgSgspJ2msm6clMCkdW9")
166
  if not self.validate_voice_id(voice_id):
167
  logger.error(f"Invalid ElevenLabs voice ID: {voice_id}")
@@ -212,4 +208,4 @@ async def main():
212
  await app.run()
213
 
214
  if __name__ == "__main__":
215
- asyncio.run(main())
 
5
  import logging
6
  from pipecat.frames.frames import (
7
  TextFrame, UserStartedSpeakingFrame, UserStoppedSpeakingFrame,
8
+ TTSStartedFrame, BotStoppedSpeakingFrame
9
  )
10
  from pipecat.pipeline.pipeline import Pipeline
11
  from pipecat.pipeline.runner import PipelineRunner
 
61
  self.last_activity_ts = time.time()
62
  self.silence_prompts_count = 0
63
 
64
+ async def process_frame(self, frame, direction: FrameDirection):
65
  if isinstance(frame, (UserStartedSpeakingFrame, TextFrame)) and direction == FrameDirection.UPSTREAM:
66
  self._reset_activity_timer()
67
  if isinstance(frame, TTSStartedFrame) and direction == FrameDirection.DOWNSTREAM:
68
  self._bot_is_speaking = True
69
+ elif isinstance(frame, BotStoppedSpeakingFrame) and direction == FrameDirection.DOWNSTREAM:
70
  self._bot_is_speaking = False
71
  self.last_activity_ts = time.time()
72
  await self.push_frame(frame, direction)
 
152
  return False
153
 
154
  async def run(self):
155
+ required_keys = ["deepgram", "elevenlabs", "dailyco", "azure_openai"]
 
 
 
156
  missing_keys = [key for key in required_keys if not os.environ.get(key)]
157
  if missing_keys:
158
  logger.error(f"Missing Hugging Face Secrets: {', '.join(missing_keys)}")
159
  sys.exit(1)
160
 
 
161
  voice_id = os.environ.get("ELEVENLABS_VOICE_ID", "cgSgspJ2msm6clMCkdW9")
162
  if not self.validate_voice_id(voice_id):
163
  logger.error(f"Invalid ElevenLabs voice ID: {voice_id}")
 
208
  await app.run()
209
 
210
  if __name__ == "__main__":
211
+ asyncio.run(main())