API reference
The gender identification feature identifies the gender (male or female) of a speaker in an audio file.
Billing and concurrency limits
Gender identification offers two billing methods: Free Edition and Commercial Edition. For more information, see Free Edition and Commercial Edition. To upgrade from the Free Edition to the Commercial Edition, see Upgrade from the Free Edition to the Commercial Edition.
For more information about billing methods, see Billing methods.
For more information about concurrency limits, see Concurrency and QPS.
Usage notes
The supported input format is PCM encoding (uncompressed PCM or WAV files) with a 16-bit audio bit depth and a mono sound channel.
The audio duration must be less than 60 seconds.
The supported audio sampling rate is 8000 Hz.
Endpoint
Access Type | Description | URL |
Public network access | All servers can use the public network access URL. The software development kit (SDK) uses this URL by default. No configuration is required. | wss://nls-gateway-cn-shanghai.aliyuncs.com/ws/v1 |
Alibaba Cloud China (Shanghai) ECS internal network access | If you use an Alibaba Cloud Elastic Compute Service (ECS) instance in the China (Shanghai) region, you can use the internal network access URL. ECS instances in the classic network cannot access AnyTunnel. This means you cannot access the Voice Service over the internal network. To use AnyTunnel, create a Virtual Private Cloud (VPC) and access the service from within the VPC. Note
| ws://nls-gateway-cn-shanghai-internal.aliyuncs.com:80/ws/v1 |
Interaction flow
1. Authentication
The client uses a token for authentication when it establishes a WebSocket connection with the server. For more information about how to obtain a token, see Overview of obtaining a token.
2. Start detection
The client sends a request that the server validates. To configure the parameters in the request message, use the `set` methods of the `CommonRequest` object in the SDK. The parameters are described as follows.
Parameter Name | Parameter Type | Description |
namespace | String | The namespace. When you create a `CommonRequest` object, set this parameter to `GenderIdentification`. |
format | String | The audio coding format. Default value: PCM. Supported formats: PCM and WAV. |
sample_rate | Integer | The audio sampling rate. Default value: 8000. Unit: Hz. |
3. Receive identification results
The client sends audio data in a loop and continuously receives identification results.
The `onEvent` event indicates that the server detected a voice event. The following code shows a sample event:
{ "header":{ "namespace":"GenderIdentification", "name":"TaskResult", "status":20000000, "message_id":"6b97ae72cf434e19aa797996fad9****", "task_id":"ce70e356743b47b9b80dc283bdf0****", "status_text":"Gateway:SUCCESS:Success." }, "payload":{ "type":3, "score":243.18978881835938 } }The following table describes the parameters of the `header` object.
Parameter Name
Type
Description
namespace
String
The namespace to which the message belongs.
name
String
The message name. `TaskResult` indicates an audio event.
status
Integer
The status code. It indicates whether the request was successful. For more information, see Service status codes.
status_text
String
The status message.
task_id
String
The globally unique ID (GUID) of the task. Record this value for troubleshooting.
message_id
String
The ID of the message.
The following table describes the parameters of the `payload` object.
Parameter Name
Type
Description
type
Integer
The gender.
2: Female
3: Male
0: Gender not identified
The other values are reserved and not available.
score
Float
The confidence level of the current result. Valid values: [-1000.0, 500.0]. A larger value indicates a higher confidence level.
4. End identification
The client notifies the server after all audio data has been sent. After the identification is complete, the server notifies the client that the detection is finished.
Service status codes
Each service response includes a `status` field, which is the service status code. The following sections describe the general, gateway, and configuration error codes.
General error codes
Error code
Cause
Solution
40000001
Identity authentication failed
Check whether the token is correct and has not expired.
40000002
Invalid message
Check whether the sent message meets the requirements.
40000004
Idle timeout
Confirm whether data has not been sent to the server for 10 seconds.
40000005
Too many requests
Check whether the number of concurrent connections or requests per second exceeds the limit. If the number of concurrent connections exceeds the limit, upgrade from the Free Edition to the Commercial Edition, or scale out the concurrent resources for the Commercial Edition.
40000000
Default client error code
Check the corresponding error message.
40000010
The 3-month free trial for new users has expired.
To continue to use the service, you must pay for the Commercial Edition. Go to the console. On the Service Management and Activation page, find the target service and click Upgrade to Commercial Edition.
41010120
Client timeout error
The client has not sent data for 10 or more seconds, which caused a client timeout error.
41160001
Invalid sample_rate parameter
Check the setting of the sample_rate parameter.
41160002
Invalid audio format parameter
Check the setting of the audio format parameter.
41160003
Audio decoding failed
Check whether the audio format is valid.
41160004
The audio duration is too long
Check whether the audio duration exceeds 60 seconds.
Gateway error codes
Error code
Cause
Solution
40010001
Unsupported API
Upgrade to the latest SDK.
40010002
Unsupported instruction
Upgrade to the latest SDK.
40010003
Invalid instruction
Upgrade to the latest SDK.
40010004
The client disconnected prematurely
Check whether the connection was closed before the request was completed.
40010005
Incorrect task status
An instruction was sent that cannot be processed in the current task state.
Configuration error codes
Error code
Cause
Solution
40020105
The application does not exist
The application cannot be found during route parsing.
40020106
The AppKey and token do not match
Check whether the AppKey of the application is correct and whether the AppKey and the token belong to the same Alibaba Cloud account.
40020503
RAM user authentication failed
Use your Alibaba Cloud account to grant the RAM user the permissions to access the POP API.