Voiceprint Recognition Service API
Feature Introduction
Voiceprint recognition provides functions for voiceprint registration, verification, and deregistration.
Call Limitations
- Voiceprint samples must be in PCM or WAV format, and the audio should be mono.
- The bit depth of the voiceprint samples must be 16-bit, and the sampling rate must be 16000 Hz.
- The duration of the voiceprint samples must be between 3 to 20 seconds, with a recommended duration of 5 to 10 seconds.
URL
http://<ip_address>:7800Interaction Process
User Information Query API
Queries the voiceprint registration status of a specified user. This can be used to check user information or to verify the availability of a username before registration.
Request Line
POST /checkUser HTTP/1.1Request Headers
| Name | Type | Required | Description |
|---|---|---|---|
| Content-type | String | Yes | Must be "application/json" |
Request Parameters
The client sends a request where parameters need to be set in the body. The meaning of each parameter is as follows:
| Parameter | Type | Required | Description |
|---|---|---|---|
| user_name | String | Yes | Username to be checked |
Sample request body:
{
"user_name": "test"
}Response Results
The Content-Type field of the HTTPS headers in the response is application/json, and the response results are contained in the HTTP Body. The fields in the response are as follows:
| Name | Type | Description |
|---|---|---|
| task_id | String | Task ID, used for troubleshooting |
| status | String | Status code |
| message | String | Description of the status code |
| data | Object | Returned information |
| ├─ user_name | String | Voiceprint username |
| ├─ enroll_num | Integer | Number of successful registrations for this user |
| ├─ update_time | String | Time of the last successful registration |
| ├─ group_id | Integer | ID of the group this voiceprint belongs to |
Successful Response
The status field in the body is 00000.
Example of a successful response:
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "00000",
"message": "success",
"data": {
"user_name": "test",
"enroll_num": 0,
"update_time": "",
"group_id": null
}
}Error Response
Any status field in the body that is not 00000 is considered an error response, and this field can be used as an indicator of whether the response was successful.
Example of an error response:
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "22151",
"message": "service error",
"data": {
"user_name":"test"
}
}User List Query API
Returns all registered voiceprint information (including completed and incomplete registrations), including usernames, the number of successful registrations, and the time of the last registration. A voiceprint registration is considered complete after 3 successful registrations.
Request Line
GET /getUsers HTTP/1.1Request Parameters
None
Response Results
The Content-Type field of the HTTP Headers in the response is application/json, and the response results are contained in the HTTP Body.
The fields in the response are as follows:
| Name | Type | Description |
|---|---|---|
| task_id | String | Task ID, used for troubleshooting |
| status | String | Status code |
| message | String | Description of the status code |
| data | Object | Returned information |
| ├─ user_name | String | Voiceprint username |
| ├─ enroll_num | Integer | Number of successful registrations for this user |
| ├─ update_time | String | Time of the last successful registration |
| ├─ group_id | Integer | ID of the group this voiceprint belongs to |
Successful Response
The status field in the body is 00000.
Example of a successful response:
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "00000",
"message": "success",
"data": [
{
"user_name": "test1",
"enroll_num": 3,
"update_time": "2022-01-01 12:00:00",
"group_id": 0
},
{
"user_name": "test2",
"enroll_num": 2,
"update_time": "2022-01-01 13:01:00",
"group_id": 0
}
]
}Error Response
Any status field in the body that is not 00000 is considered an error response, and this field can be used as an indicator of whether the response was successful.
Example of an error response:
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "22151",
"message": "service error",
"data": null
}Voiceprint Registration API
The client sends an HTTP POST request with registration information to the server, and the server returns an HTTP response with the result of this registration. A voiceprint registration is considered complete only after 3 successful registrations, meaning the voiceprint registration interface must be called 3 times.
Request Line
POST /enroll HTTP/1.1Request Headers
| Name | Type | Required | Description |
|---|---|---|---|
| Content-type | String | Yes | Must be "application/json" |
Request Parameters
The client sends a request where parameters need to be set in the body. The meaning of each parameter is as follows:
| Parameter | Type | Required | Description | Default Value |
|---|---|---|---|---|
| format | String | Yes | The format of the audio to be registered. See the "Basic Terms" section of the Voiceprint Recognition Service User Manual for details. | Required |
| sample_rate | Integer | Yes | The sample rate of the audio to be registered. See the "Basic Terms" section of the Voiceprint Recognition Service User Manual for details. | Required |
| user_name | String | Yes | Voiceprint username | Required |
| enroll_num | Integer | Yes | The current registration attempt number, ranging from 1 to 3 | Required |
| group_id | Integer | No | The ID of the group to which the voiceprint belongs, ranging from 0 to 99 | 0 |
| data | String | Yes | Base64-encoded string of the audio data to be registered | Required |
Note: The
user_namemust be globally unique (even ifgroup_idis different). Username specifications: 4 to 16 characters, and can include numbers, letters, underscores, and hyphens. Thegroup_iddefines the comparison scope during verification. If not specified, the default ID is 0. If thegroup_idvalues differ during the 3 registration requests, the value from the 3rd request will be used.
Example of a request body:
{
"format": "wav",
"sample_rate": 16000,
"user_name": "test",
"enroll_num": 1,
"data": "base64 encoded audio data"
}Response Results
The Content-Type field of the HTTPS headers in the response is application/json, and the response results are contained in the HTTP Body.
The fields in the response are as follows:
| Name | Type | Description |
|---|---|---|
| task_id | String | Task ID, used for troubleshooting |
| status | String | Status code |
| message | String | Description of the status code |
| data | Object | Registration information |
Successful Response
The status field in the body is 00000.
Example of a successful response:
- First registration successful
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "00000",
"message": "the first time you enroll successfully, you need to enroll twice more",
"data": {
"user_name": "test",
"enroll_num": 1
}
}- Second registration successful
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "00000",
"message": "the second registration is successful, please register one more time",
"data": {
"user_name":"test",
"enroll_num": 2
}
}- Third registration successful
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "00000",
"message": "the third registration is successful, registration completed",
"data": {
"user_name":"test",
"enroll_num": 3
}
}Error Response
Any status field in the body that is not 00000 is considered an error response, and this field can be used as an indicator of whether the response was successful.
Example of an error response:
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "22131",
"message": "invalid operation: the registration process has already been completed",
"data": {
"user_name":"test",
"enroll_num": 3
}
}Voiceprint Verification API
The client sends an HTTP POST request with verification information to the server, and the server returns an HTTP response with the result of the verification. Verification can be in "1-v-1" or "1-v-N" mode. For related concepts, please refer to the "Basic Terms" section of the Voiceprint Recognition Service User Manual.
Request Line
POST /verify HTTP/1.1Request Headers
| Name | Type | Required | Description |
|---|---|---|---|
| Content-type | String | Yes | Must be "application/json" |
Request Parameters
The client sends a request where parameters need to be set in the body. The meaning of each parameter is as follows:
| Parameter | Type | Required | Description | Default Value |
|---|---|---|---|---|
| format | String | Yes | The format of the audio to be verified. See the "Basic Terms" section of the Voiceprint Recognition Service User Manual for details. | Required |
| sample_rate | Integer | Yes | The sample rate of the audio to be verified. See the "Basic Terms" section of the Voiceprint Recognition Service User Manual for details. | Required |
| user_name | String | No | Specify user_name for 1-v-1 verification. If not specified, 1-v-N verification will be performed. For concepts of "1-v-1" and "1-v-N", please refer to the "Basic Terms" section of the Voiceprint Recognition Service User Manual. | Empty |
| group_id | List<Integer> | No | For 1-v-N verification, specify the range of IDs to verify against. Supports multiple IDs; if not provided, all IDs will be used (i.e., verification across all groups). For 1-v-1 verification, this field is not applicable. | Empty |
| data | String | Yes | Base64-encoded string of the audio data to be verified | Required |
Example of a request body:
1-v-1 Verification
{
"format": "wav",
"sample_rate": 16000,
"user_name": "test",
"data": "base64 encoded audio data"
}1-v-N Verification (Global Matching)
{
"format": "wav",
"sample_rate": 16000,
"data": "base64 encoded audio data"
}1-v-N Verification (Specified Matching Groups)
{
"format": "wav",
"sample_rate": 16000,
"group_id": [0, 1, 2],
"data": "base64 encoded audio data"
}Response Results
The Content-Type field of the HTTPS headers in the response is application/json, and the response results are contained in the HTTP Body.
The fields in the response are as follows:
| Name | Type | Description |
|---|---|---|
| task_id | String | Task ID, used for troubleshooting |
| status | String | Status code |
| message | String | Description of the status code |
| data | Object | Verification information |
Successful Response
The status field in the body is 00000.
The confidence field indicates the confidence level (matching similarity) of the verification.
Example of a successful response:
1-v-1 Verification
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "00000",
"message": "success",
“data”:{
"user_name":"test",
"confidence":0.76
}
}1-v-1 Verification
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status":"00000",
"message":"success",
"data":[
{
"user_name":"test3",
"confidence":0.98,
"group_id":0
},
{
"user_name":"test1",
"confidence":0.76,
"group_id":0
},
{
"user_name":"test2",
"confidence":0.71,
"group_id":1
}
]
}Error Response
Any status field in the body that is not 00000 is considered an error response, and this field can be used as an indicator of whether the response was successful.
Example of a error response:
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "22102",
"message": "the user_name hasn't been registered completely",
"data": {
"user_name":"test",
"enroll_num": 2
}
}Voiceprint Deregistration API
The client sends an HTTP POST request with deregistration information to the server, and the server returns an HTTP response with the result of the deregistration.
Request Line
POST /unregister HTTP/1.1Request Headers
| Name | Type | Required | Description |
|---|---|---|---|
| Content-type | String | Yes | Must be "application/json" |
Request Parameters
The client sends a request where parameters need to be set in the body. The meaning of each parameter is as follows:
| Parameter | Type | Required | Description |
|---|---|---|---|
| user_name | String | Yes | Voiceprint username to be deregistered |
Sample request body:
{
"user_name": "test"
}Response Results
The Content-Type field of the HTTPS headers in the response is application/json, and the response results are contained in the HTTP Body.
The fields in the response are as follows:
| Name | Type | Description |
|---|---|---|
| task_id | String | Task ID, used for troubleshooting |
| status | String | Status code |
| message | String | Description of the status code |
| data | Object | User information |
Successful Response
The status field in the body is 00000.
Example of a successful response:
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "00000",
"message": "success",
"data": {
"user_name": "test"
}
}Error Response
Any status field in the body that is not 00000 is considered an error response, and this field can be used as an indicator of whether the response was successful.
Example of an error response:
{
"task_id":"4848d4f8-b511-4c69-a1c1-61a54bbb3bb8",
"status": "22135",
"message": "unregistration failed: this user_name hasn't been registered",
"data": {
"user_name": "test"
}
}Service Status Codes
Every response from the service will include the status and message fields, which indicate the status code and description of the status code. The service status codes are as follows:
| Status Code | Reason |
|---|---|
| 00000 | Success |
| 22111 | Missing parameter |
| 22121 | Invalid parameter |
| 22123 | JSON string error |
| 22124 | Audio data in data does not meet the required constraints |
| 22131 | Subsequent registration completed, this registration is invalid |
| 22132 | Previous registration incomplete, this registration is invalid |
| 22133 | user_name has not been registered |
| 22134 | Insufficient registration attempts |
| 22135 | Deregistration failed |
| 22136 | No available user_name |
| 22151 | Default service error |
| 22152 | Request decoder error |
Best Practices
- Before registering a voiceprint, call the “User Information Query Interface” to check the availability of the username. Once you confirm the username is not registered, proceed with the “Voiceprint Registration Interface.”
- Longer audio lengths for registration and verification generally improve recognition accuracy but slow down recognition speed. It is recommended to balance accuracy and speed, with a suggested audio length of 5 to 10 seconds.
- During voiceprint verification, the voiceprint confidence (matching similarity) is returned. You might set the threshold to 0.7 (i.e., confidence above 0.7 is considered the same person).
FAQ
"Voiceprint mismatch with that of the initial registration" during registration
The second or third registration differs significantly from the initial registration, preventing completion. You can deregister the voiceprint and attempt registration again.