User Dictionary (Word Registration and Keyword Biasing)
AmiVoice API has a user dictionary feature. For words that are not recognized or difficult to recognize, you can use "word registration" for the Hybrid engine and "keyword biasing(boosting)" for the End to End engine.
Here, we first introduce a procedure to easily try out the user dictionary function.
Quick Start
To run the Python sample code, you need the requests library. Save the following code with a file name such as quickstart.py.
python -m pip install requests
Run it with the following command.
python quickstart.py
Depending on your environment, use python3 or py instead of python.
Register a User Dictionary
You can use the User Dictionary Registration API or register a user dictionary from the MyPage. Here, we will register "とりぷるだぶる" to be recognized as "WWW" for the "会話_汎用" engine (-a-general) as follows:
- macOS / Linux
- Windows (PowerShell)
- Windows (Command Prompt)
- MyPage
- Python
- Replace
{API_key}with your account's API key. - Replace
{profile_id}with any profile ID you want to use. For example, if you want to use a profile ID of "test", replace{profile_id}in the following with "test".
curl https://acp-api.amivoice.com/profilewords/-a-general/{profile_id} \
-H "Authorization: Bearer {API_key}" \
-H "Content-Type: application/json" \
-d '{"profilewords":[{"written":"WWW","spoken":"とりぷるだぶる"}]}' | jq
- If the
curlcommand is not installed, download the package for your OS from https://curl.se/ or use a package manager to install curl. - The About Result Text is Unicode escaped. In the above command,
jqis used to format the response for better readability. Ifjqis not installed, try running without the| jqpart. You can download thejqcommand package for your OS from https://stedolan.github.io/jq/ or install it using a package manager.
- Replace
{API_key}with your account's API key. - Replace
{profile_id}with any profile ID you want to use. For example, if you want to use a profile ID of "test", replace{profile_id}in the following with "test".
curl.exe https://acp-api.amivoice.com/profilewords/-a-general/{profile_id} `
-H "Authorization: Bearer {API_key}" `
-H "Content-Type: application/json" `
-d '{"profilewords":[{"written":"WWW","spoken":"とりぷるだぶる"}]}' | jq
- In PowerShell,
curlis an alias forInvoke-WebRequest, so please explicitly usecurl.exe. Windows 10 version 1803 and later includecurl.exeby default. If it's not included, please install it from https://curl.se/. - The About Result Text is Unicode escaped. In the above command,
jqis used to format the response for better readability. Ifjqis not installed, try running without the| jqpart. You can download thejqcommand package for your OS from https://stedolan.github.io/jq/ or install it using a package manager.
- Replace
{API_key}with your account's API key. - Replace
{profile_id}with any profile ID you want to use. For example, if you want to use a profile ID of "test", replace{profile_id}in the following with "test".
curl https://acp-api.amivoice.com/profilewords/-a-general/{profile_id} ^
-H "Authorization: Bearer {API_key}" ^
-H "Content-Type: application/json" ^
-d "{""profilewords"":[{""written"":""WWW"",""spoken"":""とりぷるだぶる""}]}" | jq
- Windows 10 version 1803 and later include
curlby default. If it's not included, please install it from https://curl.se/. - In Command Prompt, you cannot use
'(single quotation) to specify JSON strings, so use"(double quotation) instead. Also, escape the double quotations used internally (use""or\"). - The About Result Text is Unicode escaped. In the above command,
jqis used to format the response for better readability. Ifjqis not installed, try running without the| jqpart. You can download thejqcommand package for your OS from https://stedolan.github.io/jq/ or install it using a package manager.
User dictionary registration on MyPage is done in the "User Dictionary Registration" section of the "Recognition Rate Adjustment" page (you can access it directly from this link. Login is required for access.
Follow these steps to register words directly:
- Select [-a-general] from the engine name dropdown and click [Confirm].
- From [New Word Registration], select the [Register New Words by Direct Input] tab, enter "WWW" in [Written] and "とりぷるだぶる" in [Spoken].
- Click the [Add] button.
- The registration is complete when you can confirm that the entered word appears in the [Registered Word List].
When registering a user dictionary on MyPage, the profile ID of the profile to be registered becomes the service ID. For example, if the service ID is "user01", the profile ID will also be "user01".
- Replace
{API_key}with your account's API key. - Replace
{profile_id}with any profile ID you want to use. For example, if you want to use a profile ID of "test", replace{profile_id}in the following with "test".
import requests
import json
dgn = "-a-general" # Specify the connection engine name
pid = "{profile_id}" # Replace with the profile ID you want to use
api_key = "{API_key}" # Replace with your actual API key
endpoint = f"https://acp-api.amivoice.com/profilewords/{dgn}/{pid}"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
data = {
"profilewords": [
{"written": "WWW", "spoken": "とりぷるだぶる"}
]
}
# Send POST request
response = requests.post(endpoint, headers=headers, json=data)
# Check the response status code
if response.status_code == 200:
# Display JSON response
response_json = response.json()
print(json.dumps(response_json, indent=4, ensure_ascii=False))
else:
print(f"Error: {response.status_code}{response.text}")
Prepare an Audio File
Prepare an audio file you want to transcribe. You can use the following sample audio (www.wav) as is.
For supported audio file formats, please see Audio Formats.
Execute Speech Recognition
Execute the following. Replace {API_key} with your account's API key, {profile_id} with the profile ID of the profile you want to use, and www.wav with the path to the audio file you want to use.
- curl (macOS / Linux)
- curl (Windows PowerShell)
- curl (Windows Command Prompt)
- Python
curl https://acp-api.amivoice.com/v1/recognize \
-F u={API_key} \
-F d="grammarFileNames=-a-general profileId=:{profile_id}" \
-F a=@www.wav | jq
- If the
curlcommand is not installed, download the package for your OS from https://curl.se/ or use a package manager to install curl. - The About Result Text is Unicode escaped. In the above command,
jqis used to format the response for better readability. Ifjqis not installed, try running without the| jqpart. You can download thejqcommand package for your OS from https://stedolan.github.io/jq/ or install it using a package manager.
curl.exe https://acp-api.amivoice.com/v1/recognize `
-F u={API_key} `
-F d="grammarFileNames=-a-general profileId=:{profile_id}" `
-F a=@www.wav | jq
- In PowerShell,
curlis an alias forInvoke-WebRequest, so please explicitly usecurl.exe. Windows 10 version 1803 and later includecurl.exeby default. If it's not included, please install it from https://curl.se/. - The About Result Text is Unicode escaped. In the above command,
jqis used to format the response for better readability. Ifjqis not installed, try running without the| jqpart. You can download thejqcommand package for your OS from https://stedolan.github.io/jq/ or install it using a package manager.
curl https://acp-api.amivoice.com/v1/recognize ^
-F u={API_key} ^
-F d="grammarFileNames=-a-general profileId=:{profile_id}" ^
-F a=@www.wav | jq
- Windows 10 version 1803 and later include
curlby default. If it's not included, please install it from https://curl.se/. - The About Result Text is Unicode escaped. In the above command,
jqis used to format the response for better readability. Ifjqis not installed, try running without the| jqpart. You can download thejqcommand package for your OS from https://stedolan.github.io/jq/ or install it using a package manager.
import requests
api_key = "{API_key}"
pid = "{profile_id}" # e.g., test
with open("www.wav", "rb") as f:
response = requests.post(
"https://acp-api.amivoice.com/v1/recognize",
data={
"d": f"grammarFileNames=-a-general profileId=:{pid}",
"u": api_key
},
files={"a": f}
)
print(response.json())
Check the Result
If successful, JSON like the following will be returned. The transcription result is included in the text field.
{
"results": [
{
"tokens": [ ... ],
"confidence": 0.94,
"starttime": 500,
"endtime": 2084,
"tags": [],
"rulename": "",
"text": "WWW"
}
],
"utteranceid": "20260611/18/019eb5f848ac0a3013ba94cb_20260611_181648",
"text": "WWW",
"code": "",
"message": ""
}
For details on the response content, please see Speech Recognition Result Format.
Next Steps
In the case of the Hybrid engine, by default, the speech recognition engine can only recognize words that are pre-registered. Therefore, to recognize proper nouns or other words unknown to the engine, you need to additionally register the information for those words. This function is called "word registration".
On the other hand, the End to End engine has a different speech recognition mechanism from the Hybrid engine and does not have "pre-registered words". To recognize words that are not recognized or difficult to recognize, you perform "keyword biasing" to increase the frequency of occurrence of those words.
This section explains the following in order:
- Word Registration for Hybrid Engine
- Keyword Biasing for End to End Engine
- How to Register User Dictionary
- Profile
- User Dictionary Tips
Please see the following for API references:
User dictionaries are not supported for some languages. For details, please see the Supported Languages by AmiVoice API.
AmiVoice Tech Blog also introduces various tips for user dictionary.
- Register words that are not recognized by speech recognition! Tips for word registration in AmiVoice
- Explanation of "Classes" that can be selected with the word registration function of AmiVoice API (general-purpose engine)
- [For intermediate users] About automatic conversion of word spoken in AmiVoice
- AmiVoice's word registration API gives you more freedom in speech recognition!
- AmiVoice API Update: End-to-End ”Keyword Biasing” Feature