Skip to main content
Glama
orishu
by orishu

voice_notification

Convert text to speech notifications using Grok Voice API to alert users when Claude Code completes tasks.

Instructions

Generate a voice notification using Grok Voice API and play it.

Args: text: The text to convert to speech (default: "Done!")

Returns: str: Confirmation message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textNoDone!

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Primary MCP tool handler for voice_notification. Decorated with @app.tool() to register it as an MCP tool. Calls the helper function to generate and play the voice.
    @app.tool()
    def voice_notification(text: str = "Done!") -> str:
        """
        Generate a voice notification using Grok Voice API and play it.
    
        Args:
            text: The text to convert to speech (default: "Done!")
    
        Returns:
            str: Confirmation message
        """
        success, message = generate_and_play_voice(text, GROK_API_KEY)
        return message
  • server.py:28-40 (handler)
    Secondary MCP tool handler (HTTP server variant) for voice_notification. Identical logic to stdio version.
    @app.tool()
    def voice_notification(text: str = "Done!") -> str:
        """
        Generate a voice notification using Grok Voice API and play it.
    
        Args:
            text: The text to convert to speech (default: "Done!")
    
        Returns:
            str: Confirmation message
        """
        success, message = generate_and_play_voice(text, GROK_API_KEY)
        return message
  • Supporting utility that performs the core voice generation via WebSocket to Grok's realtime API (wss://api.x.ai/v1/realtime), collects PCM audio, saves to WAV, and plays using system audio players (afplay, aplay, etc.).
    def generate_and_play_voice(text: str, api_key: str) -> Tuple[bool, str]:
        """
        Generate a voice notification using Grok Voice API and play it.
    
        Args:
            text: The text to convert to speech
            api_key: Grok API key
    
        Returns:
            Tuple of (success: bool, message: str)
        """
        try:
            uri = "wss://api.x.ai/v1/realtime"
            headers = {
                "Authorization": f"Bearer {api_key}"
            }
    
            ws = websocket.create_connection(uri, header=headers)
            ws.settimeout(5)
    
            # Send session configuration
            session_config = {
                "type": "session.update",
                "session": {
                    "modalities": ["text", "audio"],
                    "instructions": "You are a text-to-speech system. Your only job is to speak exactly what the user provides, word for word. Do not add any greeting, introduction, or response. Just speak the exact text given.",
                    "voice": "alloy",
                    "input_audio_format": "pcm16",
                    "output_audio_format": "pcm16",
                    "input_audio_transcription": {"model": "whisper-1"},
                    "turn_detection": {"type": "server_vad"}
                }
            }
            ws.send(json.dumps(session_config))
    
            # Send a text message
            message = {
                "type": "conversation.item.create",
                "item": {
                    "type": "message",
                    "role": "user",
                    "content": [{"type": "input_text", "text": f"Speak this exactly: {text}"}]
                }
            }
            ws.send(json.dumps(message))
    
            # Trigger response
            ws.send(json.dumps({"type": "response.create"}))
    
            # Collect audio data
            audio_data = b''
            start = time.time()
            while time.time() - start < 10:  # timeout after 10 seconds
                try:
                    msg = ws.recv()
                    data = json.loads(msg)
                    if data.get("type") == "response.output_audio.delta":
                        audio_data += base64.b64decode(data['delta'])
                    elif data.get("type") == "response.done":
                        break
                except websocket.WebSocketTimeoutException:
                    break
                except websocket.WebSocketConnectionClosedException:
                    break
                except json.JSONDecodeError:
                    continue
                except Exception:
                    break
    
            ws.close()
    
            if not audio_data:
                return False, "No audio data received from API"
    
            # Create temporary WAV file
            with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_file:
                temp_wav_path = temp_file.name
    
            with wave.open(temp_wav_path, 'wb') as wf:
                wf.setnchannels(1)
                wf.setsampwidth(2)  # 16 bits
                wf.setframerate(24000)
                wf.writeframes(audio_data)
    
            # Play the audio
            played_successfully = False
            try:
                subprocess.run(["afplay", temp_wav_path], check=True, capture_output=True)
                played_successfully = True
            except subprocess.CalledProcessError:
                pass
            except FileNotFoundError:
                # afplay not available (non-macOS), try other players
                for player in ["aplay", "paplay", "play"]:
                    try:
                        subprocess.run([player, temp_wav_path], check=True, capture_output=True)
                        played_successfully = True
                        break
                    except (subprocess.CalledProcessError, FileNotFoundError):
                        continue
    
            # Clean up temp file
            try:
                os.unlink(temp_wav_path)
            except OSError:
                pass
    
            if played_successfully:
                return True, f"Voice notification played: '{text}'"
            else:
                return False, f"Voice notification generated but failed to play: '{text}'"
    
        except Exception as e:
            return False, f"Error: {e}"
  • stdio_server.py:18-18 (registration)
    Creates the FastMCP application instance named "voice-notification".
    app = FastMCP("voice-notification")
  • server.py:21-21 (registration)
    Creates the FastMCP application instance named "voice-notification" for HTTP server.
    app = FastMCP("voice-notification")
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the action ('generate and play') but fails to disclose critical behavioral traits like authentication requirements, rate limits, side effects (e.g., audio playback), or error handling. This is a significant gap for a tool that interacts with an external API and produces audio output.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, Args, Returns) and uses minimal sentences. It avoids redundancy, though the 'Args' and 'Returns' labels are slightly verbose; overall, it's efficient and front-loaded with the main action.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (API interaction, audio output) and no annotations, the description is incomplete—it lacks behavioral details and usage context. However, the presence of an output schema (explaining the return value) mitigates some gaps, making it minimally adequate but with clear room for improvement.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description includes an 'Args' section that explains the 'text' parameter as 'The text to convert to speech', adding meaning beyond the input schema (which has 0% description coverage and only defines type and default). However, it doesn't elaborate on constraints (e.g., length, language) or provide examples, so it partially compensates but not fully.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Generate a voice notification using Grok Voice API and play it.' This specifies the verb ('generate and play'), resource ('voice notification'), and technology ('Grok Voice API'). However, with no sibling tools, differentiation is not applicable, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or context. It lacks any usage instructions, such as when voice notifications are appropriate or what scenarios it's designed for, leaving the agent without operational context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/orishu/mcpvoicenotif'

If you have feedback or need assistance with the MCP directory API, please join our Discord server