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.
To set up the Music Player Integration, follow these steps:
Install Dependencies:
Ensure you have the required Python libraries installed:
bash
pip install pygame requests pydantic
Run the Server:
Execute the main.py
script to start the MCP server:
bash
python main.py
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.
The Music Player Integration provides several voice commands to control music playback:
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.
To check if music is currently playing, use the isPlaying
function:
isPlaying()
This returns Yes
if music is playing, otherwise No
.
To stop the currently playing music, use the stopplay
function:
stopplay()
This stops the music and returns the status: 已停止
(Stopped).
To pause the currently playing music, use the pauseplay
function:
pauseplay()
This pauses the music and returns the status: 已暂停
(Paused).
To resume paused music, use the unpauseplay
function:
unpauseplay()
This resumes playback and returns the status: 已恢复播放
(Resumed).
The project uses the following key components:
The server is built using the FastMCP framework, which provides a modular and extensible architecture for voice agents.
PyGame is used to handle audio playback. The music is downloaded as a temporary file and played using PyGame's mixer.music
module.
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.
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.
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.