Logo

C SDK

Real-time Speech Recognition C SDK

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

1 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.

2 Key Interface Description

Function NameParametersDescription
getAsrVersionNoneGet SDK version number
asrGetTokenchar* appId : appId, char* appSecret : appSecret, bool proEnvironment : Whether it is a production environmentGet token, return in JSON format:
{"status":"00000","message":"success","data":{"app_id":"string","token":"string","expiration_time":1686622013}}
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
startTranscribechar* token : obtained through the asrGetToken interface
AsrParams params : recognition parameters. Refer to the AsrParams structure description
TranscriberListener listener : recognition callback. Refer to the TranscriberListener structure description
Start real-time 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
stopTranscribeNoneStop real-time speech recognition
sentenceEndchar* taskIdForce sentence ending (only valid for real-time speech recognition)
speakerStartchar* taskId, char* speakerIdCustomize speaker number (only valid for real-time speech recognition)

AsrParams Structure

Field DefinitionDescriptionRequiredDefault Value
const char *langTypeLanguage optionYesNone
const char *formatAudio encoding 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: MillisecondsNo450
bool enableWordsWhether to return word informationNofalse
bool enableModalParticleFilterWhether to enable modal particle filteringNofalse
const char *hotwordsIdHotwords IDNoNone
float hotwordsWeightHotwords weight, the range is [0.1, 1.0]No0.4
const char *correctionWordsIdForced correction vocabulary ID
Supports multiple IDs, separated by a vertical bar; all indicates using all IDs.
NoNone
const char *forbiddenWordsIdForbidden words ID
Supports multiple IDs, separated by a vertical bar; all indicates using all IDs.
NoNone

TranscriberListener Structure

Function DefinitionDescription
void (*onStart)(const char * taskId)Recognition start callback, need to call feed to send audio data in the callback
void (*onSentenceBegin)(const char * taskId, const char *msg)Sentence start callback
void (*onSentenceEnd)(const char * taskId, const char *msg)Sentence end 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 (*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

3 Sample Code

Please refer to asr-demo.cpp

4 Status Code List

Error CodeError MessageDescriptionSolution
110002UnauthorizedUnauthorizedChange parameters to an authorized ability or contact the business department to add AI abilities
110003APP ID ExpiredAPP ID expiredContact the business department to extend the validity period of the APP ID
110004Calling Quota ExceededExceeded the call quotaContact the business department to increase the approved period or number of calls
110010Online Capabilities Not AuthorizedCloud API capabilities are not approvedContact the 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