跳至主要内容

用户词典注册 API

通过使用用户词典注册 API,可以将想要用于单词注册或单词强调的词语保存到任意的profile中。例如,在应用程序中,可以通过为每个最终用户切换 profile 来实现针对每个用户的用户词典功能。

客户端应用程序的角色

通常,客户端应用程序预期会执行以下实现:

  1. 为每个最终用户将显示、读音和类别的集合(对于 End to End 引擎,是显示、替代显示和单词强调度的集合)保存到数据库等中。
  2. 当数据有更新时,使用用户词典注册API更新 profile。
  3. 在发送语音识别请求时指定profileId
备注

请尽量不要将 profile 作为主数据,而是在客户端应用程序中保持用户词典信息并进行备份。

使用方法

有关API的详细信息,请参阅参考文档。以下将展示每个用例的使用示例。

认证

用户词典注册 API 使用 APPKEY 作为认证信息。在 HTTP 请求时,请在 Authorization header 中指定 Bearer {APPKEY}

注册单词

Endpoint 如下:

POST https://acp-api.amivoice.com/profilewords/{连接引擎名}/{profileId}

路径参数中的{连接引擎名}设置为像-a-general这样的语音识别引擎。另外,请在路径参数{配置文件ID}中指定要创建的配置文件的名称。关于配置文件ID可以使用的字符,请参考"可使用的字符"。

对于 Hybrid 引擎的单词注册,要注册的单词数据以以下 JSON 格式指定:

{
"profilewords": [
{
"written": "显示",
"spoken": "读音"
},
{
"written": "显示",
"spoken": "读音",
"classname": "类名"
}
, ...
]
}

对于 End to End 引擎的单词强调,指定如下:

{
"profilewords": [
{
"written": "显示"
},
{
"written": "显示",
"biasing": 单词强调度
},
{
"written": "显示",
"alternativewritten": "替代显示",
"biasing": 单词强调度
}
, ...
]
}

单词强调度以0.0~1.0的数值指定。

信息

字符编码请使用以下任一方法描述

  • 直接使用UTF-8描述(例:"あ")
  • Unicode转义序列(例:\u3042)

以下是使用curl命令的示例。这是将AmiVoice あみぼいすAOI あおい注册到会話_汎用引擎(-a-general)的test profileId的示例。

curl -sS https://acp-api.amivoice.com/profilewords/-a-general/test \
-H "Authorization: Bearer {APPKEY}" \
-H "Content-Type: application/json" \
-d '{"profilewords":[{"written":"AmiVoice","spoken":"あみぼいす"},{"written":"AOI","spoken":"あおい"}]}'

响应如下,以URL编码的JSON格式返回:

{"profilewords":[{"written":"AOI","spoken":"\u3042\u304a\u3044"},{"written":"AmiVoice","spoken":"\u3042\u307f\u307c\u3044\u3059"}]}

使用jq命令或各种编程语言的JSON解析器格式化结果如下:

{
"profilewords": [
{
"written": "AOI",
"spoken": "あおい"
},
{
"written": "AmiVoice",
"spoken": "あみぼいす"
}
]
}
信息

无法添加词语。添加时请设置所有词语。

获取已注册的词语

Endpoint 如下,路径参数与注册单词相同:

GET https://acp-api.amivoice.com/profilewords/{连接引擎名}/{profileId}

以下是使用curl命令获取会話_汎用引擎(-a-general)中testprofileId设置的词语列表的示例:

curl -sS https://acp-api.amivoice.com/profilewords/-a-general/test \
-H "Authorization: Bearer {APPKEY}"

将响应中Unicode转义的字符串解码并格式化后如下所示:

{
"profilewords": [
{
"written": "AOI",
"spoken": "あおい"
},
{
"written": "AmiVoice",
"spoken": "あみぼいす"
}
]
}

获取类别列表

Endpoint 如下,路径参数与注册单词中的含义相同:

GET https://acp-api.amivoice.com/classnames/{连接引擎名}

使用curl命令获取指定会話_汎用引擎(-a-general)的类别列表如下:

curl -sS https://acp-api.amivoice.com/classnames/-a-general \
-H "Authorization: Bearer {APPKEY}"

响应

{"classnames":["\u56fa\u6709\u540d\u8a5e","\u540d\u524d","\u540d\u524d(\u540d)","\u99c5\u540d","\u5730\u540d","\u4f1a\u793e\u540d","\u90e8\u7f72\u540d","\u5f79\u8077\u540d","\u8a18\u53f7","\u62ec\u5f27\u958b\u304d","\u62ec\u5f27\u9589\u3058","\u5143\u53f7"]}

将响应中Unicode转义的字符串解码并格式化后如下所示:

{
"classnames": [
"固有名詞",
"名前",
"名前(名)",
"駅名",
"地名",
"会社名",
"部署名",
"役職名",
"記号",
"括弧開き",
"括弧閉じ",
"元号"
]
}

从 profile 中删除词语

要删除所有词语,请注册一个空数组。

curl -sS https://acp-api.amivoice.com/profilewords/-a-general/test \
-H "Authorization: Bearer {APPKEY}" \
-H "Content-Type: application/json" \
-d '{"profilewords": []}'

响应以URL编码的JSON格式返回,如下所示:

{
"profilewords": []
}