### Uninitialize SDK Example Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Example of how to call the unInit method to release SDK resources and fully exit. ```java SparkChain.getInst().unInit(); //SDK逆初始化 ``` -------------------------------- ### Start ASR Session Example Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Example of how to call the aRun method to start an ASR session with specified parameters. ```java String filePath = "/sdcard/iflytek/asr/cn_test.pcm"; String resultType = "transfer"; mRAASR.aRun(filePath,resultType,"12345"); ``` -------------------------------- ### Callback Implementation Example Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html An example C++ implementation of the RaAsrCallbacks interface, demonstrating how to process transcription results and handle errors. ```APIDOC ## Callback Implementation Example ### Description This example shows a C++ class `RaAsrCallbacksImpl` that inherits from `RaAsrCallbacks` and implements the `onResult` and `onError` methods to process ASR outcomes. ### Code Example ```cpp class RaAsrCallbacksImpl :public RaAsrCallbacks{ void onResult(RaAsrResult* result, void* usrTag){ int status = result->status(); string orderResult = result->orderResult(); string orderId = result->orderId(); int failType = result->failType(); long originalDuration = result->originalDuration(); long realDuration = result->realDuration(); int taskEstimateTime = result->taskEstimateTime(); vector transResult = result->transResult(); for (RaAsrTransResult * raAsrTransResult : transResult) { int bg = raAsrTransResult->bg(); int ed = raAsrTransResult->ed(); string dst = raAsrTransResult->dst(); string segId = raAsrTransResult->segId(); vector tags = raAsrTransResult->tags(); vector roles = raAsrTransResult->roles(); } } void onError(RaAsrError* error, void* usrTag){ string orderId = error->orderId(); int errCode = error->code(); string errMsg = error->errMsg(); finish = true; } }; RaAsrCallbacksImpl *mRAASRCallbacks = new RaAsrCallbacksImpl(); raAsr.registerCallbacks(mRAASRCallbacks); ``` ``` -------------------------------- ### Query Transcription Result Request Example Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82 This is an example URL for querying the transcription result of an order. Ensure the 'signa' parameter is correctly generated. ```http https://raasr.xfyun.cn/v2/api/getResult?signa=Wv23VLOg%2F6sQ1BDx4DKnnxtgiwQ%3D&orderId=DKHJQ2022090217220902175209AAEBD000015&appId=3e79d91c&resultType=predict&ts=1662112340 ``` -------------------------------- ### Asynchronous Callback Example for Transcription Completion Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82 This example shows the format of an asynchronous callback received when a transcription order is completed. It includes the order ID and status. ```http GET http://ip:prot/server/xxx?orderId=DKHJQ202004291620042916580FBC96690001F&status=1 ``` -------------------------------- ### ASR Callbacks Implementation Example Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Provides a concrete implementation of the RaAsrCallbacks interface to handle transcription results and errors. This example demonstrates how to access status, results, order IDs, and error information. ```cpp class RaAsrCallbacksImpl :public RaAsrCallbacks{ void onResult(RaAsrResult* result, void* usrTag){ int status = result->status();//订单流程状态 string orderResult = result->orderResult();//转写结果(返回的是云端转写的原始结果,开发者自行解析) string orderId = result->orderId();//订单号 int failType = result->failType();//订单异常状态 long originalDuration = result->originalDuration();//原始音频时长 long realDuration = result->realDuration();//真实音频时长 int taskEstimateTime = result->taskEstimateTime();//订单预估耗时 //以下为翻译结果,开发者根据需求自行获取 vector transResult = result->transResult();//获取翻译结果 for (RaAsrTransResult * raAsrTransResult : transResult) { int bg = raAsrTransResult->bg();//开始时间 int ed = raAsrTransResult->ed();//结束时间 string dst = raAsrTransResult->dst();//翻译结果 string segId = raAsrTransResult->segId();//段落序号 vector tags = raAsrTransResult->tags();//标签 vector roles = raAsrTransResult->roles();//角色 } } void onError(RaAsrError* error, void* usrTag){ string orderId = error->orderId();//订单号 int errCode = error->code();//错误码 string errMsg = error->errMsg();//错误信息 finish = true; } }; RaAsrCallbacksImpl *mRAASRCallbacks = new RaAsrCallbacksImpl(); raAsr.registerCallbacks(mRAASRCallbacks); ``` -------------------------------- ### Initiate ASR Request Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Starts an ASR task by providing the audio file path and desired result type. ```cpp char* filePath = "../../test_file/cn_test.pcm"; raAsr.aRun(audioPath,"transfer"); ``` -------------------------------- ### RAASRCallbacks Implementation Example Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Example implementation of the RAASRCallbacks interface to process speech recognition results and errors. Register this callback with the RAASR instance. ```java RAASRCallbacks mRAASRCallbacks = new RAASRCallbacks() { @Override public void onResult(RAASR.RaAsrResult result, Object o) { int status = result.getStatus();//订单流程状态 String orderResult = result.getOrderResult();//转写结果 RAASR.RaAsrTransResult[] transResults = result.getTransResult();//翻译结果实例 String orderId = result.getOrderId();//转写订单ID int failType = result.getFailType();//订单异常状态 long originalDuration = result.getOriginalDuration();//原始音频时长,单位毫秒 long realDuration = result.getRealDuration();//真实音频时长,单位毫秒 int taskEstimateTime = result.getTaskEstimateTime();//订单预估耗时,单位毫秒 } @Override public void onError(RAASR.RaAsrError raAsrError, Object o) { String errMsg = raAsrError.getErrMsg();//错误信息 int errCode = raAsrError.getCode();//错误码 String orderId = raAsrError.getOrderId();//转写订单ID int failType = raAsrError.getFailType();//订单异常状态 } }; mRAASR.registerCallbacks(mRAASRCallbacks); ``` -------------------------------- ### RAASRTransResult Begin Time Method Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Returns the start time of the translated segment. ```cpp virtual int bg() = 0; ``` -------------------------------- ### Query ASR Result Example Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Example of how to call the aGetResult method to query the ASR results using an order ID and result type. ```java String resultType = "transfer"; mRAASR.aGetResult(orderId,resultType,"12345"); ``` -------------------------------- ### aRun Method Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Starts a session and initiates audio processing. This method is used to begin the transcription or other specified tasks. ```APIDOC ## aRun Method ### Description Starts a session and initiates audio processing. This method is used to begin the transcription or other specified tasks. ### Method Signature `public int aRun(String fileName, String resultType, Object usrTag)` ### Parameters #### Path Parameters - **fileName** (String) - Required - The name of the audio file, preferably with the actual audio suffix to avoid transcoding issues. - **resultType** (String) - Optional - Callback task type. If empty or omitted, it defaults to transcription callback. - `transfer`: Transcription - `translate`: Translation - `predict`: Quality inspection - **usrTag** (Object) - Optional - User-defined identifier. ### Request Example ```java String filePath = "/sdcard/iflytek/asr/cn_test.pcm"; String resultType = "transfer"; mRAASR.aRun(filePath, resultType, "12345"); ``` ``` -------------------------------- ### Successful File Upload Response Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82 Example of a successful response after uploading a file, including the order ID and task estimate time. ```json { "code": "000000", "descInfo": "success", "content": { "orderId": "DKHJQ202209021522090215490FAAE7DD0008C", "taskEstimateTime": 28000 } } ``` -------------------------------- ### Configure Transcription Parameters Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Configure transcription parameters using the RAASR instance. Examples include setting the language, hot words, and role separation. ```java mRAASR.transLanguage("en");//翻译目标语种 mRAASR.language("cn");//识别语种 ... mRAASR.roleType(0);//是否开启角色分离,0:关闭,1:打开 ``` -------------------------------- ### ASR Transcription Result Response Example Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html This is an example of a successful JSON response when querying for ASR transcription results. It includes order information and the transcription content, which itself is a JSON string. ```json { "code": "000000", "descInfo": "success", "content": { "orderInfo": { "orderId": "DKHJQ2022090510220905100562536FEF00062", "failType": 0, "status": 4, "originalDuration": 200, "realDuration": 1878 }, "orderResult": "{\"lattice\":[{\"json_1best\":{\"st\":{\"sc\":\"0.86\",\"pa\":\"0\",\"rt\":[{\"ws\":[{\"cw\":[{\"w\":\"这\",\"wp\":\"n\",\"wc\":\"1.0000\"}],\"wb\":1,\"we\":16},{\"cw\":[{\"w\":\"是\",\"wp\":\"n\",\"wc\":\"1.0000\"}],\"wb\":17,\"we\":36},{\"cw\":[{\"w\":\"一\",\"wp\":\"n\",\"wc\":\"1.0000\"}],\"wb\":37,\"we": ``` -------------------------------- ### Configure Speech Recognition Parameters Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Set transcription parameters using methods on the RAASR instance. Examples include setting the translation target language, recognition language, and role separation. ```cpp raAsr.transLanguage("en");//翻译目标语种 raAsr.language("cn");//识别语种 ... raAsr.roleType(0);//是否开启角色分离,0:关闭,1:打开 ``` -------------------------------- ### Failed File Upload Response Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82 Example of a failed response, indicating a general transcription business error. ```json { "code": "26600", "descInfo": "转写业务通用错误" } ``` -------------------------------- ### RAASR API - aRun Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Initiates a session for ASR processing. After registering callbacks, developers can call this method to start the session. It processes audio files and returns results based on the specified type. ```APIDOC ## aRun ### Description Starts an ASR processing session using the provided audio file. This method is called after registering necessary callbacks. ### Method Signature `int aRun(string fileName, string resultType = "transfer", void* usrTag = nullptr);` ### Parameters #### Path Parameters - **fileName** (string) - Required - The name of the audio file to process. It's recommended to include the actual file extension for better transcoding. - **resultType** (string) - Optional - The type of callback task. Defaults to "transfer" (transcription). Other options include "translate" (translation) and "predict" (quality inspection). - **usrTag** (void*) - Optional - A user-defined identifier. ### Request Example ``` char* filePath = "../../test_file/cn_test.pcm"; raAsr.aRun(audioPath,"transfer"); ``` ``` -------------------------------- ### Get Result API Endpoint Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82 This is the endpoint for retrieving the transcription results. It uses the GET method. ```HTTP GET https://raasr.xfyun.cn/v2/api/getResult ``` -------------------------------- ### SDK Initialization Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Initializes the SDK with the provided configuration object. ```cpp int32_t init(SparkChainConfig* config); ``` -------------------------------- ### Initialize SDK Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Initialize the SDK once globally with your application credentials and configuration. Ensure you have obtained the appId, apiKey, and apiSecret from the XFYun platform. ```java SparkChainConfig config = SparkChainConfig.builder() .appID("$appId") .apiKey("$apiKey") .apiSecret("$apiSecret"); int ret = SparkChain.getInst().init(getApplicationContext(), config); ``` -------------------------------- ### SDK Uninitialization Method Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Provides the method signature for SDK uninitialization. ```cpp int32_t unInit(); ``` -------------------------------- ### SparkChainConfig Builder Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Demonstrates the use of the builder pattern to configure SparkChain settings. ```cpp SparkChainConfig* config = SparkChainConfig::builder() .appID("your_app_id") .apiKey("your_api_key") .apiSecret("your_api_secret") .uid("your_uid") .workDir("/path/to/workdir") .logLevel(1) .logPath("/path/to/log") .build(); ``` -------------------------------- ### Initialize SparkChain SDK Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Initialize the SparkChain SDK using the provided application ID, API key, and API secret. This is a one-time global initialization required before using any speech-to-text functionalities. ```cpp SparkChainConfig* config = SparkChainConfig::builder(); config->appID("$appId") ->apiKey("$apiKey") ->apiSecret("$apiSecret");//从平台获取的授权appid,apikey,apisecrety int ret = SparkChain::init(config); ``` -------------------------------- ### RAASR Class Definition Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Defines the RAASR class with the aRun method for starting an ASR session. ```java public class RAASR { public int aRun(String fileName,String resultType,Object usrTag) { ... } } ``` -------------------------------- ### Initialize RAASR for Speech Recognition Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Construct an instance of the RAASR class using your API key for authentication. Note that this API key differs from the one used for SDK initialization. ```cpp class SPARKCHAIN_API RAASR { public: RAASR(const string apiKey); } ``` ```cpp RAASR raAsr(RAAsrAPIKey);//RTASR 初始化 ``` -------------------------------- ### Get Result Call Limit Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82 Indicates the maximum number of times the 'getResult' API can be called for a transcription task. ```Text Cannot exceed 100 times ``` -------------------------------- ### 获取结果接口 Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82 用于获取已上传音频文件的转写结果。支持GET请求方式。 ```APIDOC ## 获取结果接口 ### Description 用于获取已上传音频文件的转写结果。支持GET请求方式。 ### Method GET ### Endpoint https://raasr.xfyun.cn/v2/api/getResult ### Parameters #### Query Parameters - **taskId** (string) - Required - The ID of the task for which to retrieve results. ### Request Example (No specific request example provided in the source) ### Response #### Success Response (200) - **data** (object) - Contains the transcription result. - **text** (string) - The transcribed text. - **status** (string) - The status of the transcription task (e.g., 'SUCCESS', 'PROCESSING', 'FAILED'). #### Response Example ```json { "data": { "text": "This is the transcribed text.", "status": "SUCCESS" }, "message": "success", "status": 0 } ``` ``` -------------------------------- ### Uninitialization Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Releases SDK resources when the SDK needs to be completely exited. ```APIDOC ## Uninitialization ### Description Releases SDK resources when the SDK needs to be completely exited. ### Method `SparkChain.getInst().unInit();` ### Example ```java SparkChain.getInst().unInit(); // SDK uninitialization ``` ``` -------------------------------- ### Get Transcription Result Endpoint Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html This specifies the HTTP POST endpoint for retrieving ASR transcription results. The Content-Type header should be multipart/form-data. ```http POST http[s]://raasr.xfyun.cn/v2/api/getResult ``` ```http Content-Type: multipart/form-data; ``` -------------------------------- ### SparkChainConfig API Methods Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Provides methods to configure the SparkChain SDK, including setting application credentials, user identifiers, working directories, and logging options. ```APIDOC ## SparkChainConfig API ### Description Methods for configuring the SparkChain SDK before initialization. ### Methods - **appID(const char* appid)**: Sets the user's application ID. - **apiKey(const char* apiKey)**: Sets the user's API key. - **apiSecret(const char* apiSecret)**: Sets the user's API secret. - **uid(const char* uid)**: Sets a user-defined identifier. - **workDir(const char* workDir)**: Sets the SDK's working directory. - **logLevel(int logLevel)**: Sets the logging level. - **logPath(const char* logPath)**: Sets the path for log file storage. ### Static Method - **builder()**: Constructs a SparkChain instance. ``` -------------------------------- ### Enable Standard WAV Format Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Enables processing for standard WAV audio format (16k/16bit/mono). ```cpp void standardWav(int standardWav); ``` -------------------------------- ### Get Transcription Result Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html Retrieves the transcription results for a given task ID. The results are available after the transcription process is complete and are stored for 72 hours. ```APIDOC ## GET /v2/api/getResult ### Description Retrieves the transcription results for a previously uploaded audio file using its task ID. The results are available for 72 hours after completion. Each task ID can be queried up to 100 times. ### Method GET ### Endpoint http[s]: //raasr.xfyun.cn/v2/api/getResult ### Parameters #### Query Parameters - **taskId** (string) - Required - The unique identifier of the transcription task obtained from the upload response. ### Request Example (No specific request example provided in the source, but it would typically be a GET request with the taskId as a query parameter.) ### Response #### Success Response (200) - **status** (string) - The status of the transcription task (e.g., 'SUCCESS', 'PROCESSING', 'FAILED'). - **result** (string) - The transcribed text if the status is 'SUCCESS'. - **message** (string) - A message describing the status or any errors. #### Response Example { "status": "SUCCESS", "result": "This is the transcribed text from the audio file.", "message": "Transcription completed successfully." } ``` -------------------------------- ### RAASR API Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html API for real-time automatic speech recognition (RAASR) operations, including starting recognition, querying results, and setting recognition parameters. ```APIDOC ## RAASR API ### Description Handles real-time automatic speech recognition tasks and configurations. ### Methods - `aRun(String fileName, String resultType, Object usrTag)`: Initiates a recognition request. Returns an integer status code. - `aGetResult(String orderId, String resultType, Object usrTag)`: Queries the result of a recognition task. Returns an integer status code. - `language(String language)`: Sets the recognition language. - `hotWord(String hotWord)`: Sets hot words to improve recognition accuracy for specific terms (format: word1|word2|word3). - `candidate(int candidate)`: Enables or disables multi-candidate results. - `roleType(int roleType)`: Enables or disables speaker diarization (role separation). - `roleNum(int roleNum)`: Sets the number of speakers for role separation. - `pd(String pd)`: Sets domain personalization parameters. - `audioMode(String audioMode)`: Specifies the audio upload mode (e.g., 'urlLink'). - `audioUrl(String audioUrl)`: Provides the audio URL when `audioMode` is 'urlLink'. - `standardWav(int standardWav)`: Specifies if the audio is in standard WAV format (16k/16bit/mono). - `languageType(int languageType)`: Selects the language identification mode. - `trackMode(int trackMode)`: Sets the mode for channel-based transcription. - `transLanguage(String transLanguage)`: Specifies the target language for translation (must differ from recognition language). - `transMode(int transMode)`: Sets the translation mode. - `engSegMax(int engSegMax)`: Controls the maximum number of words per segment. - `engSegMin(int engSegMin)`: Controls the minimum number of words per segment. - `engSegWeight(float engSegWeight)`: Sets the weight for segment word count. - `engSmoothproc(boolean engSmoothproc)`: Enables or disables the smoothing process. - `engColloqproc(boolean engColloqproc)`: Enables or disables the colloquialism regularization process. - `engVadMdn(int engVadMdn)`: Sets the far/near field mode. - `engVadMargin(int engVadMargin)`: Determines if leading/trailing silence information is included. - `engRlang(int engRlang)`: Converts Cantonese recognition results to specific characters. - `registerCallbacks(RAASRCallbacks cbs)`: Registers a callback listener for recognition events. ``` -------------------------------- ### Include SDK Headers Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Include the necessary header files for SparkChain ASR functionality in your C++ project. ```cpp #include "../../include/sparkchain.h" #include "../../include/sc_raAsr.h" ``` -------------------------------- ### RaAsrTransResult Structure Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html The RaAsrTransResult structure provides details for each translated segment, including segment ID, translated text, start and end times, tags, and roles. ```APIDOC ## RaAsrTransResult Structure ### Description This structure contains information for individual translated segments. ### Methods - `segId()`: Returns the segment ID. - `dst()`: Returns the translated text. - `bg()`: Returns the start time of the segment in milliseconds. - `ed()`: Returns the end time of the segment in milliseconds. - `tags()`: Returns a vector of tags associated with the segment. - `roles()`: Returns a vector of roles associated with the segment. ``` -------------------------------- ### Real-time ASR Constructor Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Construct an RAASR instance using the provided API key for authentication. Note that this API key may differ from the one used for SDK initialization. ```java public class RAASR { public RAASR(String apiKey) { ... } } ``` ```java RAASR mRAASR = new RAASR(raAsrApiKey); ``` -------------------------------- ### Voice Transcription API - Get Result Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html This code snippet indicates the endpoint for retrieving transcription results from the API. It specifies the URL and HTTP method for fetching the converted text. ```http 2、获取结果:http[s]: //raasr.xfyun.cn/v2/api/getResult 请求方式 | getResult[GET] ``` -------------------------------- ### SDK Uninitialization Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Releases SDK resources when the application is exiting. ```cpp SparkChain::unInit(); //SDK逆初始化 ``` -------------------------------- ### SparkChainConfig Class Definition Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Defines the configuration structure for initializing the SparkChain SDK, including methods for setting application credentials, user ID, working directory, log level, and log path. ```cpp class SPARKCHAIN_API SparkChainConfig { public: static SparkChainConfig* builder(); virtual ~SparkChainConfig(); //配置appid virtual SparkChainConfig* appID(const char* appid) = 0; //配置apiKey virtual SparkChainConfig* apiKey(const char* apiKey) = 0; //配置apiSecret virtual SparkChainConfig* apiSecret(const char* apiSecret) = 0; //配置用户自定义标识 virtual SparkChainConfig* uid(const char* uid) = 0; //配置SDK工作路径 virtual SparkChainConfig* workDir(const char* workDir) = 0; //配置日志等级 virtual SparkChainConfig* logLevel(int logLevel ) = 0; //配置日志存储路径 virtual SparkChainConfig* logPath(const char* logPath) = 0; }; ``` -------------------------------- ### Java SDK Demo for Voice Transcription Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html This snippet links to a Java SDK demo for voice transcription. It is useful for developers integrating the transcription service using Java. ```java 语音转写demo java语言(opens new window) ``` ```java 语音转写JAVA-SDK-DEMO(opens new window) ``` -------------------------------- ### Set Audio URL Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Provides the URL for audio files when using the 'urlLink' audio mode. ```cpp void audioUrl(string audioUrl); ``` -------------------------------- ### Sample Response for getResult API Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82 This is a sample JSON response from the getResult API, showing the structure of the returned data, including order information and transcription results. ```json { "code": "000000", "descInfo": "success", "content": { "orderInfo": { "orderId": "DKHJQ2022090510220905100562536FEF00062", "failType": 0, "status": 4, "originalDuration": 200, "realDuration": 1878 }, "orderResult": "{\"lattice\":[{\"json_1best\":{\"st\":{\"sc\":\"0.86\",\"pa\":\"0\",\"rt\":[{\"ws\":[{\"cw\":[{\"w\":\"这\",\"wp\":\"n\",\"wc\":\"1.0000\"}],\"wb\":1,\"we\":16},{\"cw\":[{\"w\":\"是\",\"wp\":\"n\",\"wc\":\"1.0000\"}],\"wb\":17,\"we\":36},{\"cw\":[{\"w\":\"一\",\"wp\":\"n\",\"wc\":\"1.0000\"}],\"wb\":37,\"we\":52},{\"cw\":[{\"w\":\"条\",\"wp\":\"n\",\"wc\":\"1.0000\"}],\"wb\":53,\"we\":80},{\"cw\":[{\"w\":\"测试\",\"wp\":\"n\",\"wc\":\"1.0000\"}],\"wb\":81,\"we :116},{\"cw\":[{\"w\":\"音频\",\"wp\":\"n\",\"wc\":\"1.0000\"}],\"wb\":117,\"we\":172},{\"cw\":[{\"w\":\"。\",\"wp\":\"p\",\"wc\":\"0.0000\"}],\"wb\":172,\"we\":172},{\"cw\":[{\"w\":\"\",\"wp\":\"g\",\"wc\":\"0.0000\"}],\"wb\":172,\"we\":172}]}],\"bg\":\"50\",\"rl\":\"0\",\"ed\":\"1840\"}}"}],"lattice2":[{"lid":"0","end":"1840","begin":"50","json_1best":{"st":{"sc":"0.86","pa":"0","rt":[{"nb":"1","nc":"1.0","ws":[{"cw":[{"w":"这","wp":"n","wc":"1.0000"}],"wb":1,"we":16},{"cw":[{"w":"是","wp":"n","wc":"1.0000"}],"wb":17,"we":36},{"cw":[{"w":"一","wp":"n","wc":"1.0000"}],"wb":37,"we":52},{"cw":[{"w":"条","wp":"n","wc":"1.0000"}],"wb":53,"we":80},{"cw":[{"w":"测试","wp":"n","wc":"1.0000"}],"wb":81,"we":116},{"cw":[{"w":"音频","wp":"n","wc":"1.0000"}],"wb":117,"we":172},{"cw":[{"w":"。","wp":"p","wc":"0.0000"}],"wb":172,"we":172},{"cw":[{"w":"","wp":"g","wc":"0.0000"}],"wb":172,"we":172}]}],"pt":"reserved","bg":"50","si":"0","rl":"0","ed":"1840"}},"spk":"段落-0"}]}", "taskEstimateTime": 0 } } ``` -------------------------------- ### Python SDK Demo for Voice Transcription Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html This snippet provides a link to a Python SDK demo for voice transcription. It is intended for developers using Python to integrate the transcription service. ```python 语音转写demo python语言(opens new window) ``` ```python PYTHON-SDK-DEMO(opens new window) ``` -------------------------------- ### Set Audio Upload Mode Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Defines how audio data is uploaded to the service. ```cpp void audioMode(string audioMode); ``` -------------------------------- ### SparkChain API Methods Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Core methods for managing the SparkChain SDK lifecycle, including initialization and deinitialization. ```APIDOC ## SparkChain API ### Description Core methods for initializing and deinitializing the SparkChain SDK. ### Methods - **init(SparkChainConfig* config)**: Initializes the SDK with the provided configuration. Returns an integer status code. - **unInit()**: Deinitializes the SDK and releases resources. Returns an integer status code. ``` -------------------------------- ### RTASRResult Original Duration Method Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Returns the duration of the original audio file. ```cpp virtual long originalDuration() = 0; ``` -------------------------------- ### File Upload Request URL Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82 This is the URL for initiating the file upload process. It includes query parameters for configuration. ```http https://raasr.xfyun.cn/v2/api/upload?duration=200&signa=Je5YsBvPcsbB4qy8Qvzd367fiv0%3D&fileName=%E9%98%B3%E5%85%89%E6%80%BB%E5%9C%A8%E9%A3%8E%E9%9B%A8%E5%90%8E.speex-wb&fileSize=11895&sysDicts=uncivilizedLanguage&appId=3e79d91c&ts=1662101767 ``` -------------------------------- ### 文件上传接口 Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82 用于上传音频文件进行转写。推荐使用https协议以提高安全性。 ```APIDOC ## 文件上传接口 ### Description 用于上传音频文件进行转写。推荐使用https协议以提高安全性。 ### Method POST ### Endpoint https://raasr.xfyun.cn/v2/api/upload ### Parameters #### Request Body - **audio** (file) - Required - The audio file to be transcribed. - **taskId** (string) - Optional - A unique identifier for the task. - **subType** (string) - Optional - The type of transcription (e.g., 'normal', 'dictation'). - **language** (string) - Optional - The language of the audio (e.g., 'cn', 'en'). ### Request Example (No specific request body example provided in the source) ### Response #### Success Response (200) - **data** (object) - Contains the upload result. - **taskId** (string) - The ID of the uploaded task. - **audioUrl** (string) - The URL of the uploaded audio file. #### Response Example ```json { "data": { "taskId": "your_task_id", "audioUrl": "your_audio_url" }, "message": "success", "status": 0 } ``` ``` -------------------------------- ### SDK Uninitialization Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Releases SDK resources when the application is exiting. ```APIDOC ## SDK Uninitialization ### Description Call this method to release all resources allocated by the SDK when the application is shutting down. ### Method `SparkChain::unInit();` ``` -------------------------------- ### Set Domain Personalization Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Configures domain-specific personalization parameters for ASR. ```cpp void pd(string pd); ``` -------------------------------- ### SparkChainConfig API Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Provides methods to configure the SparkChain SDK, including setting application IDs, API keys, and logging preferences. ```APIDOC ## SparkChainConfig API ### Description Methods for configuring the SparkChain SDK. ### Methods - `appID(String appID)`: Sets the user's appID. - `apiKey(String apiKey)`: Sets the user's apiKey. - `apiSecret(String apiSecret)`: Sets the user's apiSecret. - `uid(String uid)`: Sets a custom user identifier. - `workDir(String workDir)`: Sets the SDK working directory. - `logLevel(int logLevel)`: Sets the logging level. - `logPath(String logPath)`: Sets the path for saving logs. - `builder()`: Static method to construct a SparkChain instance. ``` -------------------------------- ### RTASRResult Status Method Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Returns the current status of the ASR order. ```cpp virtual int status() = 0; ``` -------------------------------- ### SparkChain API Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Core API for managing the SparkChain instance, including initialization and deinitialization. ```APIDOC ## SparkChain API ### Description Manages the SparkChain instance lifecycle and initialization. ### Methods - `getInst()`: Static method to get the SparkChain instance. - `init(Context context, SparkChainConfig config)`: Initializes the SDK with a configuration object. Returns an integer status code. - `init(Context context)`: Initializes the SDK with default configuration. Returns an integer status code. - `unInit()`: Deinitializes the SDK. Returns an integer status code. - `getInitCode()`: Retrieves the SDK initialization result code. ``` -------------------------------- ### RTASRResult Translation Result Method Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Returns the translation results for the order. ```cpp virtual vector transResult() = 0; ``` -------------------------------- ### Enable Multiple Candidates Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Enables the generation of multiple recognition candidates. ```cpp void candidate(int candidate); ``` -------------------------------- ### RTASRResult Order Result Method Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Returns the transcribed text result for the order. ```cpp virtual string orderResult() = 0; ``` -------------------------------- ### File Upload Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html Uploads audio file information and configuration parameters to initiate a transcription task. Returns an order ID upon successful upload. ```APIDOC ## POST /v2/api/upload ### Description Initiates an audio transcription task by uploading file metadata and configuration parameters. A unique order ID is returned upon successful upload, which is required for subsequent API calls. ### Method POST ### Endpoint https://raasr.xfyun.cn/v2/api/upload ### Parameters #### Query Parameters - **fileName** (String) - Required - The name of the audio file, preferably with the correct extension. - **fileSize** (Long) - Required - The size of the audio file in bytes. This is primarily for local file stream validation. - **duration** (Long) - Required - The actual duration of the audio in seconds. - **language** (String) - Optional - The language of the audio. Defaults to 'cn'. Supported values include 'cn', 'en', 'ja', 'ko', 'ru', 'fr', 'es', 'vi', 'ar', 'de', 'it', 'hi', and various Chinese dialects. - **callbackUrl** (String) - Optional - A URL to receive asynchronous notifications upon task completion. The URL will have parameters like `orderId` and `status` appended. - **hotWord** (String) - Optional - A pipe-separated list of hot words to improve recognition of specialized terms. Each hot word must be between 2 and 16 characters. - **candidate** (Short) - Optional - Enables multi-candidate output. 0: Disabled (default), 1: Enabled. - **roleType** (Short) - Optional - Enables speaker role separation. 0: Disabled (default), 1: Enabled. - **roleNum** (Short) - Optional - The number of speakers for role separation (0-10). Defaults to 0 (blind scoring). Only effective if role separation is enabled. - **pd** (String) - Optional - Specifies the domain for personalized recognition. Options include 'court', 'edu', 'finance', 'medical', 'tech', 'culture', 'isp', 'sport', 'gov', 'game', 'ecom', 'mil', 'com', 'life', 'ent', 'car', 'audio'. - **audioMode** (String) - Optional - The method for uploading audio. 'fileStream' (default) or 'urlLink'. - **audioUrl** (String) - Optional - The URL of the audio file when `audioMode` is 'urlLink'. Must be URL-encoded if it contains special characters. - **standardWav** (Int) - Optional - Specifies if the audio is in standard PCM/WAV format (16k/16bit/mono). 0: No (default), 1: Yes. - **languageType** (Int) - Optional - Language recognition mode. For 'cn', options are 1: Auto English/Chinese (default), 2: Chinese with some English, 4: Pure Chinese. - **trackMode** (Short) - Optional - Specifies track separation mode for transcription (supported for 'cn', 'en'). 1: No separation (default), 2: Dual-channel separation (requires dual-channel audio). - **transLanguage** (String) - Optional - The target language for translation. Must be different from the transcription language. - **transMode** (Short) - Optional - Translation mode. Defaults to 2 (paragraph translation). Options: 1: VAD-based, 2: Paragraph-based, 3: Full document. - **eng_seg_max** (Int) - Optional - Maximum number of words for segmenting text (0-500). - **eng_seg_min** (Int) - Optional - Minimum number of words for segmenting text (0-50). - **eng_seg_weight** (Float) - Optional - Weight for word count-based segmentation (0-0.05). - **eng_smoothproc** (boolean) - Optional - Enables smooth processing. `true` to enable (default), `false` to disable. - **eng_colloqproc** (boolean) - Optional - Enables colloquialism regularization. `true` to enable, `false` to disable (default). - **eng_vad_mdn** (int) - Optional - Far-field or near-field mode. 1: Far-field (default), 2: Near-field. - **eng_vad_margin** (int) - Optional - Whether to include leading/trailing silence information. 0: Do not show, 1: Show (default). - **eng_rlang** (int) - Optional - Font conversion for Cantonese transcription. 0: Simplified Chinese, 1: Traditional Chinese (default). ### Request Example ```json https://raasr.xfyun.cn/v2/api/upload?duration=200&signa=Je5YsBvPcsbB4qy8Qvzd367fiv0%3D&fileName=%E9%98%B3%E5%85%89%E6%80%BB%E5%9C%A8%E9%A3%8E%E9%9B%A8%E5%90%8E.speex-wb&fileSize=11895&sysDicts=uncivilizedLanguage&appId=3e79d91c&ts=1662101767 ``` ### Request Body (Not applicable for this endpoint as parameters are sent via query string. For audio stream mode, the audio file should be in the body with `Content-Type: application/octet-stream`.) ### Response #### Success Response (200) - **code** (String) - Success code ('000000'). - **descInfo** (String) - Success message ('success'). - **content** (Object) - Contains the order ID and estimated task time. - **orderId** (String) - The unique identifier for the transcription task. - **taskEstimateTime** (Int) - Estimated time for task completion in milliseconds. #### Response Example (Success) ```json { "code": "000000", "descInfo": "success", "content": { "orderId": "DKHJQ202209021522090215490FAAE7DD0008C", "taskEstimateTime": 28000 } } ``` #### Error Response - **code** (String) - Error code (e.g., '26600'). - **descInfo** (String) - Error message (e.g., '转写业务通用错误'). #### Response Example (Failure) ```json { "code": "26600", "descInfo": "转写业务通用错误" } ``` ``` -------------------------------- ### Generate Base String for Signature Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82 Constructs the base string by concatenating AppID and timestamp, used for signature generation. ```text baseString 由 appid 和当前时间戳 ts 拼接而成; 假如 appid = 595f23df,ts = 1512041814,则 baseString = 595f23df1512041814 ``` -------------------------------- ### Import SparkChain AAR Library Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Add this configuration to your main Module's build.gradle file to include the SparkChain.aar library in your Android project. ```gradle implementation files('libs/SparkChain.aar') ```