mplayer_main.py

mplayer_main.py

by mplayer
An MCP server implementation for managing and playing music through a voice agent.

Music Player Integration for MCP Voice Agent

Overview

The Music Player Integration for MCP Voice Agent is a server-side implementation that enables voice-controlled music playback within the MCP (Modular Conversational Platform) ecosystem. This project leverages the FastMCP framework to provide seamless integration of music playback capabilities, allowing users to play, pause, stop, and resume music using voice commands.

Tools and Technologies

  • FastMCP: The core framework used to build the MCP server.
  • PyGame: A Python library used for handling audio playback.
  • Requests: A Python library for making HTTP requests to fetch music data from external APIs.
  • JSON: Used for parsing and processing API responses.

Configuration

To set up the Music Player Integration, follow these steps:

  1. Install Dependencies:
    Ensure you have the required Python libraries installed:
    bash pip install pygame requests pydantic

  2. Run the Server:
    Execute the main.py script to start the MCP server:
    bash python main.py

  3. API Integration:
    The server interacts with the NetEase Cloud Music API to fetch and play music. Ensure you have a stable internet connection for seamless music playback.

Usage

The Music Player Integration provides several voice commands to control music playback:

Play Music

To play a song, use the play_music function with the song name or keyword as the parameter:

play_music("Song Name")

This function searches for the song, downloads it, and starts playback.

Check Playback Status

To check if music is currently playing, use the isPlaying function:

isPlaying()

This returns Yes if music is playing, otherwise No.

Stop Playback

To stop the currently playing music, use the stopplay function:

stopplay()

This stops the music and returns the status: 已停止 (Stopped).

Pause Playback

To pause the currently playing music, use the pauseplay function:

pauseplay()

This pauses the music and returns the status: 已暂停 (Paused).

Resume Playback

To resume paused music, use the unpauseplay function:

unpauseplay()

This resumes playback and returns the status: 已恢复播放 (Resumed).

Implementation Details

The project uses the following key components:

FastMCP Server

The server is built using the FastMCP framework, which provides a modular and extensible architecture for voice agents.

PyGame for Audio Playback

PyGame is used to handle audio playback. The music is downloaded as a temporary file and played using PyGame's mixer.music module.

NetEase Cloud Music API

The server fetches music data from the NetEase Cloud Music API. It searches for songs based on the provided keyword and downloads the audio file for playback.

Error Handling

The implementation includes error handling to manage cases where the song is not found or playback fails. If a song cannot be played, the server attempts to play the next available song in the search results.

Example Workflow

  1. User Command: "Play 'Shape of You'"
  2. Server Action: The server searches for "Shape of You" using the NetEase Cloud Music API, downloads the song, and starts playback.
  3. User Command: "Pause music"
  4. Server Action: The server pauses the currently playing music.
  5. User Command: "Resume music"
  6. Server Action: The server resumes playback from where it was paused.

Conclusion

The Music Player Integration for MCP Voice Agent enhances the MCP ecosystem by adding voice-controlled music playback capabilities. This implementation demonstrates how to integrate external APIs and audio libraries to create a seamless user experience for voice-controlled applications.

Features & Capabilities

Categories
mcp_server model_context_protocol python music_playback pygame api_integration voice_agent

Implementation Details

Stats

0 Views
0 Favorites
1 GitHub Stars

Repository Info

mplayer Organization

Similar Servers

continuedev_continue by continuedev
0
0
0