feat: handle voiceGreeting message type - TTS for bot join greeting
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
5d40657aef
commit
33daa8dc74
1 changed files with 26 additions and 0 deletions
|
|
@ -303,6 +303,32 @@ class TeamsbotService:
|
|||
websocket=websocket,
|
||||
)
|
||||
|
||||
elif msgType == "voiceGreeting":
|
||||
greetingText = message.get("text", "")
|
||||
greetingLang = message.get("language", self.config.language)
|
||||
logger.info(f"[WS-DEBUG] Voice greeting request: text={greetingText[:60]}..., language={greetingLang}")
|
||||
if greetingText and voiceInterface:
|
||||
try:
|
||||
ttsResult = await voiceInterface.textToSpeech(
|
||||
text=greetingText,
|
||||
languageCode=greetingLang,
|
||||
voiceName=self.config.voiceId
|
||||
)
|
||||
if ttsResult and isinstance(ttsResult, dict):
|
||||
audioContent = ttsResult.get("audioContent")
|
||||
if audioContent:
|
||||
await websocket.send_text(json.dumps({
|
||||
"type": "playAudio",
|
||||
"sessionId": sessionId,
|
||||
"audio": {
|
||||
"data": base64.b64encode(audioContent if isinstance(audioContent, bytes) else audioContent.encode()).decode(),
|
||||
"format": "mp3",
|
||||
}
|
||||
}))
|
||||
logger.info(f"Voice greeting TTS sent for session {sessionId}")
|
||||
except Exception as ttsErr:
|
||||
logger.warning(f"Voice greeting TTS failed for session {sessionId}: {ttsErr}")
|
||||
|
||||
elif msgType == "ping":
|
||||
await websocket.send_text(json.dumps({"type": "pong"}))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue