Logo

C SDK

Short Speech Recognition C SDK

Before using the SDK, please read the Interface Protocol first. For details, refer to Cloud API.

How to Use SDK Demo

The SDK is divided into Windows/Linux versions, each system includes x86/x64 bit libraries (stored in the libs directory), and the platform-specific run scripts facilitate execution on their respective platforms.

  • Windows-x86 : run-x86.bat
  • Windows-x64 : run-x64.bat
  • Linux-x86 : run-x86.sh
  • Linux-x64 : run-x64.sh

When compiling code with g++, you need to use -lasr to specify the required library.

Key Interface Description

Function NameParametersDescription
getAsrVersionNoneGet SDK version number
asrGetTokenchar * appId : appId, char* appSecret : appSecretGet token, return in JSON format. Response example: {"status":"00000","message":"success","data":{"app_id":"string","token":"string","expiration_time":1686622013}}. The expiration_time is the token expiration time, the token can be reused before expiration. When using, you need to extract data.token and pass it to the corresponding interface
getAsrParamsNoneGet recognition parameters, refer to AsrParams structure description
startRecognizechar* token: obtained through the asrGetToken interface
AsrParams params: speech recognition parameters. Refer to the AsrParams structure description
RecognizerListener listener: speech recognition callback. Refer to the RecognizerListener structure description
Start short speech recognition.
asrFeedchar * taskId: taskId returned by onStart, char* data: audio data
int length: array length.
Send audio data, need to be called multiple times in the listener's onStart callback.
stopRecognizeNoneStop short speech recognition.

AsrParams Structure

Field DefinitionDescriptionRequiredDefault Value
const char *langTypeRecognition languageYesNone
const char *formatAudio formatNopcm
int sampleRateAudio sampling rateNo16000
bool enableIntermediateResultWhether to return intermediate recognition results, if enabled, the intermediate recognition results will be returned in the Listener's onIntermediateResult functionNofalse
bool enablePunctuationPredictionWhether to add punctuation in post-processingNofalse
bool enableInverseTextNormalizationWhether to perform ITN in post-processingNofalse
int maxSentenceSilenceSpeech sentence breaking detection threshold. Silence longer than this threshold is considered as a sentence break.
The valid parameter range is 200~1200. Unit: Milliseconds
No450
bool enableWordsWhether to return word informationNofalse
bool enableModalParticleFilterWhether to remove modal particlesNofalse
const char *hotwordsIdHotwords IDNoNone
float hotwordsWeightHotwords weight, the range is [0.1, 1.0]No0.4
const char *correctionWordsIdForced correction vocabulary IDNoNone
const char *forbiddenWordsIdForbidden words IDNoNone

RecognizerListener Structure

Function DefinitionDescription
void (*onStart)(const char * taskId)Recognition start callback, need to call feed to send audio data in the callback
void (*onIntermediateResult)(const char * taskId, int index, const char *msg)Intermediate result callback, need to set enableIntermediateResult to true in the parameters first
void (*onResult)(const char * taskId, const char *msg)Recognition result callback, the final recognition result is returned after recognition stops
void (*onStop)(const char * taskId)Recognition stop callback
void (*onError)(const char * taskId, const char *code, const char * msg)Recognition error callback. code is the error code, msg is the error message
void (*onWarning)(const char * taskId, const char *code, const char * msg)Recognition warning callback. code is the error code, msg is the error message
void (*onGetVolume)(const char * taskId, float volume)Real-time volume callback

Sample Code

Please refer to asr-demo.cpp

Status Code List

Error CodeError MessageDescriptionSolution
110002UnauthorizedUnauthorizedChange parameters to authorized abilities or contact business department to add AI abilities
110003APP ID ExpiredAPP ID expiredContact business department to extend the validity period of appid
110004Calling Quota ExceededExceeded the call quotaContact business department to increase the approval period or number of calls
110010Online Capabilities Not AuthorizedCloud API capabilities are not approvedContact business department to add authorization for Cloud API capabilities
120000Network ErrorNetwork errorCheck the network connection status of the device
200000Invalid ParameterThe parameter is incorrectCheck parameters (parameters are not compliant, incorrect, or empty strings)
210203Invalid Number Of ChannelsThe number of audio channels is incorrectCheck the number of audio channels (WAV audio channel number is not 1)
210000Gateway Timeout In Receiving DataThe gateway timed out when receiving dataCheck if data is being sent normally
210100Invalid Calling SequenceThe calling sequence is incorrectCall in the normal sequence