getVoices
Retrieve available voice IDs for speech synthesis, including system voices and cloned voices, to select appropriate digital human voices for audio generation.
Instructions
#工具说明:查询可用的发音人ID。
样例1:
用户输入:我之前克隆过哪些声音? 思考过程: 1.用户想要查询可用的发音人ID,需要使用“getVoices”工具。 2.工具需要参数,isSystem,一个参数。 3.从“克隆过的”可以推测希望查询克隆发音人ID,因此参数的值为“false”
样例2:
用户输入:我想用一个二十岁左右温柔小姐姐的声音。 思考过程: 1.用户想要查询可用的发音人ID,需要使用“getVoices”工具。 2.工具需要参数,isSystem,一个参数。 3.用户未明确指出发音人ID的来源,因此不传任何值。 4.从接口返回的内容中寻找describe中“二十岁”左右,gender中为“female”的音色,优先推荐给用户
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| isSys | No | 是否是系统音色,true获取系统音色,false获取克隆音色, 空查询所有音色 |
Implementation Reference
- src/mcp_server_baidu_digitalhuman/dhserver.py:55-74 (registration)Registration of the 'getVoices' tool using @mcp.tool decorator with name, description, and usage examples.
@mcp.tool( name="getVoices", description=( """ #工具说明:查询可用的发音人ID。 # 样例1: 用户输入:我之前克隆过哪些声音? 思考过程: 1.用户想要查询可用的发音人ID,需要使用“getVoices”工具。 2.工具需要参数,isSystem,一个参数。 3.从“克隆过的”可以推测希望查询克隆发音人ID,因此参数的值为“false” # 样例2: 用户输入:我想用一个二十岁左右温柔小姐姐的声音。 思考过程: 1.用户想要查询可用的发音人ID,需要使用“getVoices”工具。 2.工具需要参数,isSystem,一个参数。 3.用户未明确指出发音人ID的来源,因此不传任何值。 4.从接口返回的内容中寻找describe中“二十岁”左右,gender中为“female”的音色,优先推荐给用户 """) ) - The handler function for 'getVoices' tool. Accepts isSys parameter, retrieves DHApiClient, calls get_voices, handles exceptions, returns MCPVoicesResponse.
async def getVoices( isSys: Annotated[Optional[bool], Field(description="是否是系统音色,true获取系统音色,false获取克隆音色, 空查询所有音色", default=None)] ) -> MCPVoicesResponse: """ Get the list of available voices via DH API. Args: isSys: 是否是系统音色: true获取系统音色, false获取克隆音色, 空查询所有音色 """ try: client = await getDhClient() ret = await client.get_voices(isSys) return ret except Exception as e: return MCPVoicesResponse(error=str(e)) - Helper method in DHApiClient that performs the actual HTTP GET request to Baidu Digital Human API endpoint for voices, transforms response to MCPVoicesResponse.
async def get_voices(self, isSys: Optional[bool] = None) -> MCPVoicesResponse: """Get the list of available voices from the API.""" async def api_call(): param = "" if isSys == True: param = "true" elif isSys == False: param = "false" return await self._make_request(f"api/digitalhuman/open/v1/tts/persons?isSystem={param}") def transform_data(data, mcp_class): return mcp_class(voices=data if len(data) > 0 else None) return await self._handle_api_request( api_call=api_call, response_model_class=VoicesResponse, mcp_response_class=MCPVoicesResponse, error_msg="No voices found.", transform_func=transform_data, ) - Output schema for getVoices tool: MCPVoicesResponse, which includes list of voices (VoiceInfo objects).
class MCPVoicesResponse(BaseDHResponse): """ MCP 音色列表响应 """ voices: Optional[List[VoiceInfo]] = None - VoiceInfo model used in MCPVoicesResponse for individual voice details (perId, name, gender).
class VoiceInfo(BaseModel): """ 音色数据 """ perId: str name: str gender: Annotated[Optional[str], Field(description="性别", default=None)]