{"slug": "create-ai-voice-responses-for-slack-bots", "title": "Create AI Voice Responses for Slack Bots", "summary": "A developer published a step-by-step guide for building a Slack bot that replies with synthesized speech, using the ElevenLabs text-to-speech REST API and Python. The tutorial wires Slack's Events API to a Flask endpoint that calls ElevenLabs for MP3 audio, then uploads the clip back to the channel via the Slack SDK's files_upload and chat_postMessage methods.", "body_md": "If you’ve ever wished your Slack bot could *talk* back to you, you’re not alone. Adding voice responses turns a plain text interaction into a more engaging, accessible experience—perfect for status updates, alerts, or just a little fun. In this article we’ll walk through building a Slack bot that speaks using modern text‑to‑speech (TTS) and voice‑cloning technology. We’ll use **ElevenLabs** as the TTS engine (the affiliate link is included below) and glue everything together with a few lines of Python.\n\n**TL;DR** – By the end of this guide you’ll have a Slack bot that receives a message, generates a realistic voice clip with ElevenLabs, uploads it to Slack, and posts the audio file back to the channel.\n\nAll of this is possible today without building a deep learning model from scratch. Services like ElevenLabs provide high‑quality, low‑latency TTS APIs that can even clone a voice from a few minutes of audio.\n\nElevenLabs offers a straightforward REST API for generating speech. Sign up through the affiliate link below, grab your API key, and you’re ready to go:\n\nOnce you have the key, you can request speech in a variety of voices, set speaking rates, and even use your own cloned voice model (if you’ve uploaded a sample). The API returns an MP3 stream that we’ll later upload to Slack.\n\nFirst, create a Slack app:\n\n`chat:write`` files:write``app_mentions:read`` xoxb-`).\nYou’ll also need the **Signing Secret** under **Basic Information** for request verification.\n\nBelow is a minimal Python function that sends a prompt to ElevenLabs and returns the raw MP3 bytes.\n\n``` python\nimport requests\n\nELEVENLABS_API_KEY = \"YOUR_ELEVENLABS_API_KEY\"\nELEVENLABS_TTS_URL = \"https://api.elevenlabs.io/v1/text-to-speech/EXAMPLE_VOICE_ID\"\n\ndef synthesize_speech(text: str) -> bytes:\n    \"\"\"Call ElevenLabs TTS and return MP3 data.\"\"\"\n    headers = {\n        \"xi-api-key\": ELEVENLABS_API_KEY,\n        \"Content-Type\": \"application/json\"\n    }\n    payload = {\n        \"text\": text,\n        \"model_id\": \"eleven_monolingual_v1\",\n        \"voice_settings\": {\n            \"stability\": 0.75,\n            \"similarity_boost\": 0.85\n        }\n    }\n    response = requests.post(ELEVENLABS_TTS_URL, json=payload, headers=headers)\n    response.raise_for_status()\n    return response.content\n```\n\n**Tip:** Replace `EXAMPLE_VOICE_ID` with the ID of the voice you want to use. You can list your voices via the `/v1/voices` endpoint or use a cloned voice ID if you’ve uploaded a custom sample.\n\nSlack doesn’t support streaming audio directly in a message, but you can upload an MP3 file and share it. Here’s a helper that takes the MP3 bytes from the previous step and posts it back to the channel where the bot was mentioned.\n\n``` python\nfrom slack_sdk import WebClient\nfrom slack_sdk.errors import SlackApiError\n\nSLACK_BOT_TOKEN = \"xoxb-YOUR_SLACK_BOT_TOKEN\"\nslack_client = WebClient(token=SLACK_BOT_TOKEN)\n\ndef upload_and_post(audio_bytes: bytes, channel: str, title: str = \"Voice reply\"):\n    try:\n        # Upload the file first\n        upload_resp = slack_client.files_upload(\n            channels=channel,\n            file=audio_bytes,\n            filename=\"reply.mp3\",\n            title=title,\n            filetype=\"mp3\"\n        )\n        # Share the file in a message\n        slack_client.chat_postMessage(\n            channel=channel,\n            text=f\"Here’s the voice response:\",\n            attachments=[\n                {\n                    \"fallback\": title,\n                    \"title\": title,\n                    \"file_id\": upload_resp[\"file\"][\"id\"]\n                }\n            ]\n        )\n    except SlackApiError as e:\n        print(f\"Slack error: {e.response['error']}\")\n```\n\nNow let’s create a simple Flask endpoint that Slack will hit whenever the bot is mentioned. The flow is:\n\n`event_callback` with the message text.`synthesize_speech`.\n\n``` python\nfrom flask import Flask, request, jsonify\nimport hmac\nimport hashlib\nimport os\n\napp = Flask(__name__)\n\nSLACK_SIGNING_SECRET = os.getenv(\"SLACK_SIGNING_SECRET\")\n\ndef verify_slack_request(req):\n    timestamp = req.headers.get(\"X-Slack-Request-Timestamp\")\n    sig_basestring = f\"v0:{timestamp}:{req.get_data(as_text=True)}\"\n    my_sig = \"v0=\" + hmac.new(\n        SLACK_SIGNING_SECRET.encode(),\n        sig_basestring.encode(),\n        hashlib.sha256\n    ).hexdigest()\n    slack_sig = req.headers.get(\"X-Slack-Signature\")\n    return hmac.compare_digest(my_sig, slack_sig)\n\n@app.route(\"/slack/events\", methods=[\"POST\"])\ndef slack_events():\n    if not verify_slack_request(request):\n        return \"Invalid request\", 403\n\n    data = request.json\n    # Respond to URL verification challenge\n    if data.get(\"type\") == \"url_verification\":\n        return jsonify({\"challenge\": data[\"challenge\"]})\n\n    # Only handle app_mention events\n    if data.get(\"event\", {}).get(\"type\") == \"app_mention\":\n        event = data[\"event\"]\n        channel = event[\"channel\"]\n        user_text = event[\"text\"]\n        # Remove the bot mention part\n        cleaned_text = user_text.split(\">\")[1].strip() if \">\" in user_text else user_text\n\n        # Generate speech\n        audio = synthesize_speech(cleaned_text)\n\n        # Post back to Slack\n        upload_and_post(audio, channel, title=f\"Reply to <@{event['user']}>\")\n\n    return \"\", 200\n\nif __name__ == \"__main__\":\n    app.run(port=3000)\n```\n\n**What you need to run this:**\n\n`pip install flask slack_sdk requests`` SLACK_SIGNING_SECRET``SLACK_BOT_TOKEN`` ELEVENLABS_API_KEY`\nExpose the Flask server with a tool like `ngrok` and add the public URL to your Slack app’s **Event Subscriptions** (subscribe to `app_mention`).\n\n`EXAMPLE_VOICE_ID` with that ID. Your bot can now sound like your team lead, mascot, or even yourself.`/voice speed=1.2 text=Hello`).\nYou now have a fully functional Slack bot that listens, converts text to a natural‑sounding voice, and replies with an audio file—all powered by ElevenLabs. Play around with different voices, experiment with voice cloning, and consider adding a UI in Slack to let users pick their favorite voice.\n\n🔊 **Ready to give your Slack bot a voice?** Try ElevenLabs today and bring your bots to life: [https://try.elevenlabs.io/kr07zfuqn1bp](https://try.elevenlabs.io/kr07zfuqn1bp)\n\nHappy coding! 🚀", "url": "https://wpnews.pro/news/create-ai-voice-responses-for-slack-bots", "canonical_source": "https://dev.to/voice_developer/create-ai-voice-responses-for-slack-bots-4el1", "published_at": "2026-10-06 22:53:53+00:00", "updated_at": "2026-10-06 23:17:37.933485+00:00", "lang": "en", "topics": ["ai-tools", "generative-ai", "developer-tools"], "entities": ["Slack", "ElevenLabs", "Flask", "Python"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/create-ai-voice-responses-for-slack-bots", "markdown": "https://wpnews.pro/news/create-ai-voice-responses-for-slack-bots.md", "text": "https://wpnews.pro/news/create-ai-voice-responses-for-slack-bots.txt", "jsonld": "https://wpnews.pro/news/create-ai-voice-responses-for-slack-bots.jsonld"}}