API reference
The language identification feature detects the language spoken in an audio file. It currently supports Chinese, English, and Cantonese.
Billing and concurrency limits
Language identification offers two billing modes: 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 Free Edition to Commercial Edition.
For more information about billing methods, see Billing methods.
For information about concurrency and queries per second (QPS) limits, see Concurrency and QPS limits.
Usage notes
The supported input format is PCM encoding (uncompressed PCM or WAV files) with a 16 bit audio bit depth and a single channel (mono).
The audio duration must be less than 60 seconds, with a recommended effective duration of more than 5 seconds.
The supported audio sample rate is 8000 Hz.
Endpoints
Access type | Description | URL |
Public network access | All servers can use the public network access URL. The software development kit (SDK) is pre-configured with this URL, so no setup is required. | wss://nls-gateway-cn-shanghai.aliyuncs.com/ws/v1 |
Alibaba Cloud ECS internal network access in Shanghai | If you use an Alibaba Cloud ECS instance in the China (Shanghai) region, you can use the internal network access URL. ECS instances in a classic network cannot access AnyTunnel and therefore cannot access the Voice Service over the internal network. To use AnyTunnel, create a 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 establishing a WebSocket connection with the server. For more information about how to obtain a token, see Obtain a token.
2. Start detection
The client sends a request, and the server validates it. You can set the parameters in the request message using the `set` methods of the `CommonRequest` object in the SDK. The parameters are described below.
Parameter Name | Parameter type | Description |
namespace | String | The namespace. When you create a `CommonRequest`, set this parameter to `LanguageIdentification`. |
format | String | The audio coding format. Default value: PCM. Supported formats: PCM and WAV. |
sample_rate | Integer | The audio sample rate. Default value: 8000. Unit: Hz. |
language_type | String | The language type.
|
3. Receive detection results
The client sends audio data in a loop and continuously receives detection results.
The `onEvent` event indicates that the server has detected a voice event. The following is an example:
{ "header":{ "namespace":"LanguageIdentification", "name":"TaskResult", "status":20000000, "message_id":"6b97ae72cf434e19aa797996fad9****", "task_id":"ce70e356743b47b9b80dc283bdf0****", "status_text":"Gateway:SUCCESS:Success." }, "payload":{ "language":"engl", "score":-0.5 } }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 this message.
Parameters of the `payload` object:
Parameter name
Parameter type
Description
language
Integer
The language.
mand: Chinese
engl: English
cant: Cantonese
Empty: The language is not detected.
score
Float
The confidence level of the result. The value ranges from -1000.0 to 0.0. A larger value indicates a higher confidence level.
4. End detection
The client notifies the server after all audio data has been sent. After the detection is complete, the server notifies the client.
Service status codes
Each response from the service includes a `status` field, which is the service status code. The following tables list 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
Verify that no data has been sent to the server-side for 10 seconds.
40000005
Too many requests
Check whether the number of concurrent connections or requests per second has exceeded the limit. If the concurrency limit is exceeded, upgrade from the Free Edition to the Commercial Edition, or scale out resources for the Commercial Edition.
40000000
Default client error code
Check the corresponding error message.
40000010
The trial period has ended, and the Commercial Edition is not activated, or the account has an overdue payment.
Log on to the console to confirm the service activation status and your account balance.
41010120
Client timeout error
The client has not sent data for 10 or more consecutive seconds, causing a client timeout error.
41160001
Incorrect sample rate parameter
Check the sample rate parameter settings.
41160002
Incorrect audio format parameter
Check the audio format parameter settings.
41160003
Audio decoding failed
Check whether the audio format is valid.
41160004
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
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
Application does not exist
The application could not be found during route parsing.
40020106
AppKey and token do not match
Check whether the AppKey is correct and whether the token belongs to the same account as the AppKey.
40020503
RAM user authentication failed
Use your Alibaba Cloud account to grant the RAM user the required access permissions to call POP API operations.