Skip to main content
Glama
CryptoDappDev

Piper TTS MCP Server

speak

Convert text to speech and play it through speakers with customizable voice, speed, and volume settings for audio output.

Instructions

Convert text to speech and play it through the speakers.

Args:
    text: The text to convert to speech
    speaker_id: Voice speaker ID (default: 0)
    length_scale: Speech speed control (default: 1.1, lower = faster)
    noise_scale: Voice variation control (default: 0.667)
    noise_w_scale: Pronunciation variation control (default: 0.333)
    volume: Volume level from 0.01 to 1.00 (default: 0.15)

Returns:
    Success or error message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
speaker_idNo
length_scaleNo
noise_scaleNo
noise_w_scaleNo
volumeNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core execution logic of the 'speak' tool: validates parameters, calls TTS service at localhost:5000, receives audio, plays it using pygame (memory or file fallback), handles errors.
    try:
        # Validate volume parameter
        volume = max(0.01, min(1.00, volume))  # Clamp between 0.01 and 1.00
        
        # Prepare data for TTS API
        data = {
            "text": text,
            "speaker_id": speaker_id,
            "length_scale": length_scale,
            "noise_scale": noise_scale,
            "noise_w_scale": noise_w_scale
        }
        
        # Make request to TTS service
        response = requests.post(
            "http://localhost:5000",
            headers={"Content-Type": "application/json"},
            json=data,
            timeout=30
        )
        
        if response.status_code != 200:
            return f"TTS service error: HTTP {response.status_code}"
        
        # Try to play audio from memory first, fallback to file method
        try:
            # Initialize pygame mixer
            pygame.mixer.init()
            pygame.mixer.music.set_volume(volume)
            
            # Create in-memory file-like object
            audio_data = io.BytesIO(response.content)
            
            # Load and play from memory
            pygame.mixer.music.load(audio_data)
            pygame.mixer.music.play()
            
            # Wait for playback to complete
            while pygame.mixer.music.get_busy():
                pygame.time.wait(100)
                
        except Exception as memory_error:
            # Fallback to file method if memory method fails
            filename = f"speak_{int(time.time())}.wav"
            with open(filename, "wb") as f:
                f.write(response.content)
            
            pygame.mixer.init()
            pygame.mixer.music.set_volume(volume)
            pygame.mixer.music.load(filename)
            pygame.mixer.music.play()
            
            # Wait for playback to complete
            while pygame.mixer.music.get_busy():
                pygame.time.wait(100)
            
            # Clean up the audio file
            try:
                os.remove(filename)
            except Exception:
                pass  # Ignore cleanup errors
        
        return f"Successfully spoke: '{text}'"
        
    except requests.exceptions.ConnectionError:
        return "Error: TTS service not available at localhost:5000"
    except requests.exceptions.Timeout:
        return "Error: TTS service request timed out"
    except Exception as e:
        return f"Error: {str(e)}"
  • Input schema defined by function parameters with type annotations, default values, and comprehensive docstring describing args and return.
    def speak(
        text: str,
        speaker_id: Optional[int] = 0,
        length_scale: Optional[float] = 1.1,
        noise_scale: Optional[float] = 0.667,
        noise_w_scale: Optional[float] = 0.333,
        volume: Optional[float] = 0.15
    ) -> str:
        """
        Convert text to speech and play it through the speakers.
        
        Args:
            text: The text to convert to speech
            speaker_id: Voice speaker ID (default: 0)
            length_scale: Speech speed control (default: 1.1, lower = faster)
            noise_scale: Voice variation control (default: 0.667)
            noise_w_scale: Pronunciation variation control (default: 0.333)
            volume: Volume level from 0.01 to 1.00 (default: 0.15)
        
        Returns:
            Success or error message
        """
  • server.py:18-18 (registration)
    The @mcp.tool() decorator registers the 'speak' function as an MCP tool with FastMCP instance.
    @mcp.tool()
Behavior3/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 discloses that the tool plays speech through speakers and returns a success or error message, which covers basic behavior. However, it lacks details on potential side effects (e.g., audio output interruption), permissions, or error handling, leaving gaps in transparency.

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

Conciseness5/5

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

The description is well-structured and front-loaded with the core purpose, followed by a clear breakdown of parameters and returns. Every sentence adds value without redundancy, making it efficient and easy to parse for an agent.

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

Completeness4/5

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

Given the tool's complexity (6 parameters) and no annotations, the description does a good job covering parameters and basic behavior. With an output schema present, it doesn't need to detail return values. However, it could improve by addressing potential constraints like audio device requirements or usage limits.

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

Parameters5/5

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

The description adds significant meaning beyond the input schema, which has 0% coverage. It explains each parameter's purpose (e.g., 'speaker_id: Voice speaker ID', 'length_scale: Speech speed control'), including default values and effects (e.g., 'lower = faster'), fully compensating for the schema's lack of descriptions.

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

Purpose5/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 with a specific verb ('Convert text to speech and play it through the speakers'), identifying both the action and resource. It distinguishes itself by specifying the exact functionality without ambiguity, and since there are no sibling tools, no differentiation is needed.

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

Usage Guidelines3/5

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

The description implies usage for text-to-speech conversion but provides no explicit guidance on when to use this tool versus alternatives. With no sibling tools mentioned, there's no context for comparison, leaving the agent to infer usage based on the stated purpose alone.

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/CryptoDappDev/piper-tts-mcp'

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