Updated on 2023-11-10 GMT+08:00

HTTP Interface

Functions

This API is used for real-time recognition of short sentences. The audio duration cannot exceed 30s.

URI

POST /v1/{project_id}/asr/short-audio

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Request Message

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

It is used to obtain the permission to call APIs. For details about how to obtain a user token, see Authentication. The token is the value of X-Subject-Token in the response header.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

config

Yes

Config object

Configuration information.

data

Yes

String

Audio data (encoded by Base64). The size of the encoded audio data cannot exceed 2 MB. The audio duration cannot exceed 30 seconds. For example, /+MgxAAUeHpMAUkQAANhuRAC..... If the prefix data:audio/mp3;base64, is carried, an error is reported.

Table 4 Config

Parameter

Mandatory

Type

Description

audio_format

Yes

String

Audio format. For details about the supported audio formats, see Table 5.

property

Yes

String

Model feature string in use, which is generally in the Language_Sampling rate_Domain format. The sampling rate must be the same as the audio sampling rate. For details about the value range, see Table 6.

add_punc

No

String

Whether to add punctuation marks to the recognition result. The value can be yes or no. The default value is no.

digit_norm

No

String

Whether to convert digits in the speech into Arabic numerals. The value can be yes or no. The default value is yes. Currently, the international website does not support this parameter.

vocabulary_id

No

String

Hot word table ID. If no hot word table is used, this field can be left blank. Currently, the international website does not support this parameter.

need_word_info

No

String

Whether to output the word segmentation result in the recognition result. The value can be yes or no. The default value is no. Currently, this parameter is not supported on HUAWEI CLOUD (International).

Table 5 Value range of audio_format

Value

Description

pcm16k16bit

16 kHz, 16-bit mono-channel audio recording data

pcm8k16bit

8 kHz, 16-bit mono-channel audio recording data

wav

Format with the WAV encapsulation header. The format is automatically determined by the encapsulation header. Currently, only the 8 kHz/16 kHz sampling rate, mono channel, and pcm encoding format are supported.

Table 6 Value range of property

Value

Description

english_8k_common

English speech recognition with a sampling rate of 8 kHz

english_16k_common

English speech recognition with a sampling rate of 16 kHz

Response parameters

Status code: 200

Table 7 Response body parameters

Parameter

Mandatory

Type

Description

trace_id

Yes

String

Internal token used to trace a specific process in logs. This parameter is not included when the API fails to be called.

In some error cases, this field may not exist.

result

Yes

Result object

If the calling is successful, this parameter indicates the recognition result. Otherwise, this parameter is invalid.

Table 8 Result

Parameter

Mandatory

Type

Description

text

Yes

String

Recognition result of a successful call

score

Yes

Float

Confidence of a successful call. The value ranges from 0 to 1.

word_info

No

Array of WordInfo objects

Word segmentation information list Currently, this parameter is not supported on HUAWEI CLOUD (International).

Table 9 WordInfo

Parameter

Mandatory

Type

Description

start_time

No

Integer

Start time

end_time

No

Integer

End time

word

No

String

Word segmentation

Status code: 400

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Error code returned when the API fails to be called. This parameter is not included when the API is successfully called.

error_msg

String

Error message when the API call fails. This parameter is not included when the API is successfully called.

Example Requests

The endpoint is the request URL for calling an API. Endpoints vary according to services and regions. For details, see Endpoints.

  • Upload a short audio and quickly obtain the recognition result.
    POST https://{endpoint}/v1/{project_id}/asr/short-audio
    
    Request Header:
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    
    Request body: 
    {
      "config":
      {
        "audio_format": "wav",
        "property": "english_8k_common",
        "add_punc": "yes",
      },
      "data": "/+MgxAAUeHpMAUkQAANhuRAC..."
    }

Example Responses

Status code: 200

Example response (successful request)

{
  "trace_id": "567e8537-a89c-13c3-a882-826321939651",
  "result":{
   "text": "Nice to meet you",
    "score": 0.9,
  }
}

Status code: 400

Failure response example

{ 
    "error_code":"SIS.0001", 
    "error_msg":"***" 
}

Status Codes

For details about status codes, see Status Codes.

Error Codes

For details about error codes, see Error Codes.