Skip to content

Commit

Permalink
Merge branch 'feat/loading-sound' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Jan 15, 2024
2 parents 0cb80f0 + cc7804f commit ceab928
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions helpers/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ class TTS(str, Enum):
"Je suis désolé, j'ai rencontré une erreur. Pouvez-vous répéter votre demande ?"
)
GOODBYE = f"Merci de votre appel, j'espère avoir pu vous aider. N'hésitez pas à rappeler, j'ai tout mémorisé. {CONFIG.workflow.bot_company} vous souhaite une excellente journée !"
HELLO = f"Bonjour, je suis {CONFIG.workflow.bot_name}, l'assistant {CONFIG.workflow.bot_company} ! Je suis spécialiste des sinistres. Lorsque vous entendrez un bip, c'est que je travaille. Mais d'abord, quel est l'objet de votre appel ?"
HELLO = f"Bonjour, je suis {CONFIG.workflow.bot_name}, l'assistant {CONFIG.workflow.bot_company} ! Je suis spécialiste des sinistres. Je ne peux pas travailler et écouter en même temps. Lorsque je travaillerai, vous entendrez une petite musique. Après, au bip, ce sera à votre tour de parler. Je suis là pour vous aider. Quel est l'objet de votre appel ?"
TIMEOUT_SILENCE = "Je suis désolé, je n'ai rien entendu. Si vous avez besoin d'aide, dites-moi comment je peux vous aider."
WELCOME_BACK = f"Bonjour, je suis {CONFIG.workflow.bot_name}, l'assistant {CONFIG.workflow.bot_company} ! Je vois que vous avez déjà appelé il y a moins de {CONFIG.workflow.conversation_timeout_hour} heures. Lorsque vous entendrez un bip, c'est que je travaille. Laissez-moi quelques secondes pour récupérer votre dossier..."
WELCOME_BACK = f"Bonjour, je suis {CONFIG.workflow.bot_name}, l'assistant {CONFIG.workflow.bot_company} ! Je vois que vous avez déjà appelé il y a moins de {CONFIG.workflow.conversation_timeout_hour} heures. Laissez-moi quelques secondes pour récupérer votre dossier..."
35 changes: 16 additions & 19 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,6 @@ async def call_event_post(request: Request, call_id: UUID) -> None:
client=client,
text=TTSPrompt.WELCOME_BACK,
)
await handle_media(
call=call,
client=client,
file="acknowledge.mp3",
)
await intelligence(call, client)

elif event_type == "Microsoft.Communication.CallDisconnected": # Call hung up
Expand All @@ -301,12 +296,6 @@ async def call_event_post(request: Request, call_id: UUID) -> None:
speech_text = event.data["speechResult"]["speech"]
_logger.info(f"Recognition completed ({call.id}): {speech_text}")

await handle_media(
call=call,
client=client,
file="acknowledge.mp3",
)

if speech_text is not None and len(speech_text) > 0:
call.messages.append(
CallMessageModel(content=speech_text, persona=CallPersona.HUMAN)
Expand All @@ -319,12 +308,6 @@ async def call_event_post(request: Request, call_id: UUID) -> None:
result_information = event.data["resultInformation"]
error_code = result_information["subCode"]

await handle_media(
call=call,
client=client,
file="acknowledge.mp3",
)

# Error codes:
# 8510 = Action failed, initial silence timeout reached
# 8532 = Action failed, inter-digit silence timeout reached
Expand Down Expand Up @@ -405,9 +388,22 @@ async def call_event_post(request: Request, call_id: UUID) -> None:


async def intelligence(call: CallModel, client: CallConnectionClient) -> None:
# Start loading sound
await handle_media_loop(
call=call,
client=client,
file="loading.wav",
)

chat_res = await gpt_chat(call)
_logger.info(f"Chat ({call.id}): {chat_res}")

try:
# Cancel loading sound
client.cancel_all_media_operations()
except ResourceNotFoundError:
_logger.debug(f"Call hung up before playing ({call.id})")

if chat_res.intent == IndentAction.TALK_TO_HUMAN:
await handle_play(
call=call,
Expand Down Expand Up @@ -825,7 +821,7 @@ async def handle_recognize_text(
await handle_recognize_media(
call=call,
client=client,
file="ready.mp3",
file="ready.wav",
)


Expand All @@ -851,14 +847,15 @@ async def handle_recognize_media(
_logger.debug(f"Call hung up before recognizing ({call.id})")


async def handle_media(
async def handle_media_loop(
client: CallConnectionClient,
call: CallModel,
file: str,
context: Optional[str] = None,
) -> None:
try:
client.play_media_to_all(
loop=True,
operation_context=context,
play_source=FileSource(f"{CONFIG.resources.public_url}/{file}"),
)
Expand Down
Binary file removed resources/acknowledge.mp3
Binary file not shown.
Binary file added resources/loading.wav
Binary file not shown.
Binary file removed resources/ready.mp3
Binary file not shown.
Binary file added resources/ready.wav
Binary file not shown.

0 comments on commit ceab928

Please sign in to comment.