### Python SDK Quick Start Source: https://www.xfyun.cn/doc/spark/Web.html Provides a quick start guide for integrating the Spark AI Python SDK, including installation and a basic code example for calling the Spark Max model. ```APIDOC ## Python SDK Quick Start ### Description Provides a quick start guide for integrating the Spark AI Python SDK, including installation and a basic code example for calling the Spark Max model. **Note:** Project only supports Python 3.8+ ### Step 1: Install Package Execute the following command in your Python environment: ```bash pip install --upgrade spark_ai_python ``` ### Step 2: Python Code Example ```python from sparkai.llm.llm import ChatSparkLLM, ChunkPrintHandler from sparkai.core.messages import ChatMessage # URL for Spark Max model. For other model versions, please refer to the documentation (https://www.xfyun.cn/doc/spark/Web.html) SPARKAI_URL = 'wss://spark-api.xf-yun.com/v3.5/chat' # API Key information for Spark model. Please check the iFlytek Open Platform console (https://console.xfyun.cn/services/bm35) SPARKAI_APP_ID = '' SPARKAI_API_SECRET = '' SPARKAI_API_KEY = '' # Domain for Spark Max model. For other model versions, please refer to the documentation (https://www.xfyun.cn/doc/spark/Web.html) SPARKAI_DOMAIN = 'generalv3.5' if __name__ == '__main__': spark = ChatSparkLLM( spark_api_url=SPARKAI_URL, spark_app_id=SPARKAI_APP_ID, spark_api_key=SPARKAI_API_KEY, spark_api_secret=SPARKAI_API_SECRET, spark_llm_domain=SPARKAI_DOMAIN, streaming=False, ) messages = [ChatMessage( role="user", content='你好呀' )] handler = ChunkPrintHandler() a = spark.generate([messages], callbacks=[handler]) print(a) ``` For more Python SDK features, please visit GitHub (opens new window). ``` -------------------------------- ### Python SDK Quick Start Example Source: https://www.xfyun.cn/doc/spark/Web.html This example shows how to initialize and use the ChatSparkLLM client for making a simple chat request. Ensure you have Python 3.8+ and your API credentials configured. ```python from sparkai.llm.llm import ChatSparkLLM, ChunkPrintHandler from sparkai.core.messages import ChatMessage #星火认知大模型Spark Max的URL值,其他版本大模型URL值请前往文档(https://www.xfyun.cn/doc/spark/Web.html)查看 SPARKAI_URL = 'wss://spark-api.xf-yun.com/v3.5/chat' #星火认知大模型调用秘钥信息,请前往讯飞开放平台控制台(https://console.xfyun.cn/services/bm35)查看 SPARKAI_APP_ID = '' SPARKAI_API_SECRET = '' SPARKAI_API_KEY = '' #星火认知大模型Spark Max的domain值,其他版本大模型domain值请前往文档(https://www.xfyun.cn/doc/spark/Web.html)查看 SPARKAI_DOMAIN = 'generalv3.5' if __name__ == '__main__': spark = ChatSparkLLM( spark_api_url=SPARKAI_URL, spark_app_id=SPARKAI_APP_ID, spark_api_key=SPARKAI_API_KEY, spark_api_secret=SPARKAI_API_SECRET, spark_llm_domain=SPARKAI_DOMAIN, streaming=False, ) messages = [ChatMessage( role="user", content='你好呀' )] handler = ChunkPrintHandler() a = spark.generate([messages], callbacks=[handler]) print(a) ``` -------------------------------- ### Install OpenAI SDK Source: https://www.xfyun.cn/doc/spark/HTTP%E8%B0%83%E7%94%A8%E6%96%87%E6%A1%A3.html Installs the necessary OpenAI SDK for Python. This is a prerequisite for using the SDK-based request example. ```bash # 安装openai SDK pip install openai ``` -------------------------------- ### Configure and Start ASR Session Source: https://www.xfyun.cn/doc/asr/voicedictation/SparkChain-Linux-SDK.html Example of configuring AudioAttributes and starting an ASR session. Sets sample rate, encoding, and channels. ```cpp SparkChain::AudioAttributes attr; attr.setSampleRate(16000); //输入音频采样率:16K:16000,8K:8000 attr.setEncoding("raw"); //输入音频的编码格式.raw: pcm原始音频格式 attr.setChannels(1); //输入音频的声道 1:单声道(默认) 2:双声道 asr.start(attr); ``` -------------------------------- ### Example Authorization URL Source: https://www.xfyun.cn/doc/words/business_license/API.html An example URL demonstrating how authorization parameters are appended for API requests. ```http http://api.xf-yun.com/v1/private/sff4ea3cf?authorization=YXBpX2tleT0iOTEyMDVhZmUwZDE3ZTM4YzYxYmUzNWZjYTM0NjUwM2MiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0iOU1WYktFMndUWjJmS1A5NzdvbkpFSjBLT3d2Mk1WQ3lybnIydjY4YzNWZz0i&host=api.xf-yun.com%3A-1&date=Tue%2C+24+Nov+2020+03%3A28%3A17+GMT ``` -------------------------------- ### Start Session with AIkit SDK Source: https://www.xfyun.cn/doc/asr/AIkit_offline_iat/Android-SDK.html Initiates a session using the AIkit SDK's start method. Requires an ability ID and optional parameters for configuring the session. Handles success or failure of the session start. ```Java AiRequest.Builder paramBuilder = AiRequest.builder(); //paramBuilder.param("lmLoad", false); //paramBuilder.param("vadLoad", false); //paramBuilder.param("lmOn", false); //paramBuilder.param("numLoad", false); //paramBuilder.param("puncLoad", false); //paramBuilder.param("vadLinkOn", false); //paramBuilder.param("vadOn", false); //paramBuilder.param("postprocOn", false); //paramBuilder.param("vadResponsetime", 6000); //paramBuilder.param("vadSpeechEnd", 200); //paramBuilder.param("dialectType", 0); //paramBuilder.param("htkNeed", true); //paramBuilder.param("readableNeed", true); //paramBuilder.param("pgsNeed", true); //paramBuilder.param("plainNeed", true); //paramBuilder.param("vadNeed", true); AiHandle handle = AiHelper.getInst().start("ee62fa27c",paramBuilder.build(),null); if (!handle.isSuccess()) { Log.e(TAG, "ERROR::START | handle code:" + handle.getCode()); return; } ``` -------------------------------- ### Example GET Request URL Source: https://www.xfyun.cn/doc/spark/asr_llm/Ifasr_llm.html This is an example of a GET request URL for the Ifasr_llm API, demonstrating how to include query parameters for authentication and task identification. ```url https://office-api-ist-dx.iflyaisol.com/v2/getResult?accessKeyId=testaccesskeyid&dateTime=2018-02-27T16%3A54%3A01%2B0800&orderId=DKHJQ20180208100000DD&signatureRandom=2bec2cc6-186a-414c-8c68-5d30a6fb14bb ``` -------------------------------- ### Get Engine Start Identifier Source: https://www.xfyun.cn/doc/mscapi/iOS/iosbasic.html Retrieves the identifier string used with `MSPSetParam` to start the engine. ```Objective-C (NSString *)ENGINE_START ``` -------------------------------- ### Example Proxy Server Configuration Source: https://www.xfyun.cn/doc/voiceservice/ise/Android-SDK.html An example of how to configure proxy settings within the SpeechUtility.createUtility method, separating parameters with a comma. ```java SpeechUtility.createUtility(context, SpeechConstant.APPID + "," + "12345678" + "," + "net_type=custom, proxy_ip=192.168.1.2, proxy_port=8080"); ``` -------------------------------- ### Initialize AIKit SDK (V2.2.13+) Source: https://www.xfyun.cn/doc/asr/AIkit_awaken/Windows-SDK.html Initialize the AIKit SDK using a builder pattern for configuration. This example demonstrates setting application details, authorization, and logging parameters. Ensure the work directory has read/write permissions. ```cpp AIKIT_Configurator::builder() .app() .appID("") .apiKey("") .apiSecret("") .workDir("./") //示例为当前路径 .auth() .ability("e867a88f2") .log() .logLevel(LOG_LVL_INFO) .logPath("./"); int ret = AIKIT_Init(); if(ret != 0){ printf("AIKIT_Init failed:%d\n",ret); goto exit; } ``` -------------------------------- ### Getting Segment Start Time Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Retrieve the start time (in milliseconds) of a translated segment using `bg`. ```cpp int bg() = 0 ``` -------------------------------- ### Running the Demo Source: https://www.xfyun.cn/doc/voiceservice/ise/Linux-SDK.html Steps to run the provided demo for the Speech Evaluation SDK on Linux. This involves downloading the SDK, compiling the sample, and executing the demo binary. ```bash source 64bit_make.sh cd ../../bin/ ./ise_online_sample ``` -------------------------------- ### Python Full Example for Song Recognition Source: https://www.xfyun.cn/doc/voiceservice/song-recognition/API.html This snippet demonstrates how to use the Song Recognition API with Python. It includes authentication setup using API key, timestamp, and checksum, and sends an audio URL for recognition. Ensure you have the 'requests', 'base64', 'json', 'time', and 'hashlib' libraries installed. ```python #_*_encoding:utf-8_*_ import requests import base64 import json import time import hashlib class demo: def __init__(self): self.url = "http://webqbh.xfyun.cn/v1/service/v1/qbh" self.AUDIO_URL = AUDIO_URL def music_iat(self): curtime = str(int(time.time())) print(curtime) # 使用audio_url传输音频数据时,http request body须为空。 # 直接把音频二进制数据写入到Http Request Body时,不需要设置audio_url参数 param = { "audio_url":self.AUDIO_URL } base64_param = base64.urlsafe_b64encode(json.dumps(param).encode('utf-8')) tt = str(base64_param, 'utf-8') m2 = hashlib.md5() m2.update((apikey+ curtime+ tt).encode('utf-8')) checksum = m2.hexdigest() header = { "X-CurTime": curtime, "X-Param": base64_param, "X-Appid": appid, "X-CheckSum":checksum, } res = requests.post(self.url,headers= header) result = res.content print(result.decode("utf-8")) if __name__ == "__main__": # 在控制台获取appid等信息 appid = "" apikey = "" # 音频url地址 AUDIO_URL = "https://xfyun-doc.cn-bj.ufileos.com/1537253485018707/qlzw2.wav" demo = demo() demo.music_iat() ``` -------------------------------- ### Authentication Example URL Source: https://www.xfyun.cn/doc/words/picture-document-reconstruction/API.html This example URL demonstrates how to include authentication parameters for API requests. Ensure all parameters like host, date, and authorization are correctly formatted. ```url ws://ws-api.xf-yun.com/v1/private/ma008db16?host=ws-api.xf-yun.com&date=Thu%2C+24+Mar+2022+03%3A47%3A02+GMT&authorization=YXBpX2tleT0iMWRhYTM5NGJkZDRkYjhkNTVkNTJkMzg3MmY4NGFlZGEiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0iSlBRRnhHWE83TmpMSkoxZnd5dS9FSHF0L2tnZmUxb0tJNktQMkRoMmE3TT0i ``` -------------------------------- ### Start Document Summary Request Example Source: https://www.xfyun.cn/doc/spark/ChatDoc-API.html Example of a form-data request to initiate a document summary. Requires the file ID. ```json { "fileId": "" } ``` -------------------------------- ### Configuring Proxy Server for MSPLogin Source: https://www.xfyun.cn/doc/voiceservice/ise/Windows-SDK.html This example shows how to configure proxy server settings within the params parameter of the MSPLogin function. It includes an example with specific host and port values. ```c MSPLogin(NULL, NULL, "appid = 12345678, net_type=custom, proxy_ip=192.168.1.2, proxy_port=8080"); ``` -------------------------------- ### Response Parameters Example for Listing Repositories Source: https://www.xfyun.cn/doc/spark/ChatDoc-API.html Example of response parameters when listing repositories, including repository details like ID, name, description, tags, and creation time. ```json { "flag": true, "code": 0, "desc": null, "data": [{ "repoId": "9d1a5beea01e4b4a80f12f66f1ee23b0", "repoName": "云平台产品说明", "repoDesc": "云平台所有产品说明", "repoTags": "", "createTime": "2024-02-18 17:47:37" }], "sid": "0b953bd85e4c4675a8700ba705d69953" } ``` -------------------------------- ### Query Result Request Example Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html Example of a GET request to query the result of a transcription task using the order ID and other parameters. ```http https://raasr.xfyun.cn/v2/api/getResult?signa=Wv23VLOg%2F6sQ1BDx4DKnnxtgiwQ%3D&orderId=DKHJQ2022090217220902175209AAEBD000015&appId=3e79d91c&resultType=predict&ts=1662112340 ``` -------------------------------- ### Audio Synthesis Syntax Example Source: https://www.xfyun.cn/doc/spark/reproduction.html This example demonstrates the syntax for the audio synthesis interface, showing how to represent phonemes, durations, and syllables. ```text sil:6;欢[=huan1]-h1:16;@-uan1:24;迎[=ying2]-ing2:20;使[=shi3]-sh3:24;@-iii3:14;用[=yong4]-iong4:24;科[=ke1]-k1:20;@-e1:14;大[=da4]-d4:12;@-a4:24;讯[=xun4]-x4:22;@-vn4:20;飞[=fei1]-f1:16;@-ei1:22;语[=yu3]-v3:32;音[=yin1]-in1:26;合[=he2]-h2:26;@-e2:18;成[=cheng2]-ch2:18;@-eng2:14;系[=xi4]-x4:20;@-i4:12;统[=tong3]*-t3:20;@-ong3:12;sil:82; ``` -------------------------------- ### Asynchronous Callback Example Source: https://www.xfyun.cn/doc/asr/ifasr_new/API.html Example of an asynchronous callback notification when a transcription task is completed. This shows the GET request format with order ID and status. ```http GET http://ip:prot/server/xxx?orderId=DKHJQ202004291620042916580FBC96690001F&status=1 ``` -------------------------------- ### 运行离线语音合成 Demo Source: https://www.xfyun.cn/doc/tts/offline_tts/Linux-SDK.html 在 SDK 目录下,根据系统位数选择对应的 make.sh 脚本进行编译,然后运行 tts_offline_sample 可查看运行结果。 ```bash # 编译 64 位 SDK ./64bit_make.sh # 编译 32 位 SDK ./32bit_make.sh ``` ```bash # 进入 bin 目录 cd ../../bin/ # 运行离线语音合成示例 ./tts_offline_sample ``` -------------------------------- ### MSPLogin with Server URL Example Source: https://www.xfyun.cn/doc/asr/voicedictation/Linux-SDK.html Demonstrates how to configure the server URL when logging into the MSP service. Replace 'YourDomainName' with your actual domain. ```c MSPLogin(NULL, NULL, "appid = 12345678, server_url = http://sdk.openspeech.cn/msp.do"); ``` -------------------------------- ### Get Dialog Context Response Example Source: https://www.xfyun.cn/doc/voiceservice/telrobot-capability-midware/API.html Example of a response payload for retrieving dynamic context data, showing a map of string keys to string values. ```json { "key1": "value1", "性别": "男", "姓名": "张三" } ``` -------------------------------- ### Start AI Session with Parameters Source: https://www.xfyun.cn/doc/tts/AIkit_offline_tts/Android-SDK.html Initiate a session for an AI capability using the start method. This method requires a capability ID and an AiRequest object containing necessary parameters like voice, language, and encoding. ```java AiRequest.Builder paramBuilder = AiRequest.builder(); paramBuilder.param("vcn", $paramValue); paramBuilder.param("language", $paramValue); //paramBuilder.param("pitch", 50); //paramBuilder.param("volume", 50); //paramBuilder.param("speed", 50); //paramBuilder.param("reg", 0); //paramBuilder.param("rdn", 0); paramBuilder.param("textEncoding", $paramValue); AiHandle handle = AiHelper.getInst().start("e2e44feff",paramBuilder.build(),null); if (!handle.isSuccess()) { Log.e(TAG, "ERROR::START | handle code:" + handle.getCode()); return; } ``` -------------------------------- ### JSON Object Output Prompt Example Source: https://www.xfyun.cn/doc/spark/%E6%8E%A8%E7%90%86%E6%9C%8D%E5%8A%A1-http.html Example prompt to guide the model to generate a JSON object, specifying the desired keys and data types for the output. ```json [ {"role": "user", "content": "请给我一个关于上海的JSON对象,包含城市名称(city)和人口数量(population)。"} ] ``` -------------------------------- ### Initiate ASR Request Example Source: https://www.xfyun.cn/doc/asr/ifasr_new/Linux.html Example of calling the aRun method to start an ASR transcription task. Specify the audio file path and desired result type. ```cpp char* filePath = "../../test_file/cn_test.pcm"; raAsr.aRun(audioPath,"transfer"); ``` -------------------------------- ### Speed Transcription API Python Full Example Code Source: https://www.xfyun.cn/doc/asr/speedTranscription/API.html A complete Python code example demonstrating the usage of the Speed Transcription API, including necessary imports and setup. ```APIDOC ## Python Full Example Code ### Description This is a complete Python code example for using the Speed Transcription API. ```python #!/usr/bin/python3 # -*- coding:utf-8 -*- from fileupload import seve_file import requests import datetime import hashlib import base64 import hmac import json import os import re path_pwd = os.path.split(os.path.realpath(__file__))[0] os.chdir(path_pwd) ``` ``` -------------------------------- ### Start Recording Source: https://www.xfyun.cn/doc/mscapi/iOS/iosbasic.html Begins the audio recording process. Returns YES if recording starts successfully, otherwise NO. ```Objective-C - (BOOL)start ``` -------------------------------- ### ASR LLM Callback URL Example Source: https://www.xfyun.cn/doc/spark/asr_llm/Ifasr_llm.html Example of a GET request to a callback URL for asynchronous ASR results. The URL includes orderId and status parameters to notify the user of the transcription completion. ```http GET http://ip:prot/server/xxx?orderId=DKHJQ202004291620042916580FBC96690001F&status=1 ``` -------------------------------- ### Java SDK Demo Link Source: https://www.xfyun.cn/doc/spark/sparkos_interactive.html Access the Java SDK demo for Spark OS to see practical implementation examples. This link leads to an external repository. ```text JAVA-SDK-DEMO(opens new window) ``` -------------------------------- ### Proxy Server Configuration Example Source: https://www.xfyun.cn/doc/asr/voicedictation/Linux-SDK.html Example of how to configure proxy server settings within the MSPLogin interface. Replace placeholders with your actual proxy server address and port. ```c MSPLogin(NULL, NULL, "appid = 12345678, net_type=custom, proxy_ip=192.168.1.2, proxy_port=8080"); ``` -------------------------------- ### Few-Shot Prompting with Example for Travel Recommendation Style Source: https://www.xfyun.cn/doc/spark/Prompt%E5%B7%A5%E7%A8%8B%E6%8C%87%E5%8D%97.html This prompt uses few-shot learning by providing an example ('案例') within triple quotes to guide the AI on the desired tone and format for recommending travel destinations. The AI is asked to emulate the style of the provided example. ```text prompt:【 假设你是一名资深旅行顾问,请参照三引号中的案例的语气和提供攻略的方式为我推荐中国旅行目的地 案例: '''伊豆急行之[黑船电车] 日本小众玩法:来伊豆不可错过的海景列车一一黑船电车。 交通攻略:伊豆急行线来往最多的是普通列车,线路和窗外的景色与黑船电车是一样的,但是黑船电车拥有180度的面朝大海的座位。需要注意的是黑船号每天只有三班,分别是早上,中午,下午各一班,一定记得看下时刻表。玩法推荐:强烈推荐购买伊豆急行一日券/两日券。一日券价格为1200日元/一人;二日券价格为2000日元/人。血 行程路线:有名的城崎海岸(门胁吊桥、门胁灯塔)、伊豆高原(大室山)、以及小众的下田市的白滨海岸,都可坐此列车到达。黑船雷事主要行驶於熟海~伊豆急下田''' 】 response:【 当然,我很高兴你对中国旅行感兴趣。我为你推荐的目的地是: 旅行目的地推荐:[丽江古城] 介绍: 欢迎来到中国的丽江古城,这是一个充满历史和文化底蕴的古老城市。被联合国教科文组织列为世界文化遗产,丽江以其古老的街道、古朴的建筑和多元的民族文化而著称。 交通攻略: 前往丽江古城的最佳方式是搭乘飞机直达丽江机场,然后从机场出发前往市区。在市区,你可以选择乘坐当地的出租车或巴士,或者步行欣赏沿途的风景。 玩法推荐: 探索丽江古城的独特之处,建议你在清晨或傍晚时分漫步在古老的街巷中,感受它的宁静和神秘。你还可以品味当地美食,尝试纳西族传统小吃,感受浓厚的民俗风情。 行程路线: 在丽江古城,你可以游览束河古镇、丽江大研古城等著名景点。此外,你还可以前往玉龙雪山,欣赏雄伟的自然风光。在这里,每一个角落都弥漫着浓厚的历史氛围,让你仿佛穿越回古老的时光。 】 ``` -------------------------------- ### Get Dialog Context Request Example Source: https://www.xfyun.cn/doc/voiceservice/telrobot-capability-midware/API.html Example of a request payload for retrieving dynamic context data for an incoming call. Includes call relation ID, business ID, app ID, and robot ID. ```json { "call_relation_id":"1111", "business_id":"167", "app_id":"3333", "robot_id":"4444" } ``` -------------------------------- ### Example Authentication URL Source: https://www.xfyun.cn/doc/voiceservice/suntone/API.html This is an example URL demonstrating how authentication parameters are appended for API requests. ```url wss://cn-east-1.ws-api.xf-yun.com/v1/private/s8e098720?host=cn-east-1.ws-api.xf-yun.com&date=Tue%2C+16+Aug+2022+08%3A28%3A38+GMT&authorization=YXBpX2tleT0iYXBpa2V5WFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFgiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0iS3NIa2xFWWJ2Y0hiYldLSnpDQ1J2aEZnSXl1VkowTEcxczVNQ04vMDJzWT0i ``` -------------------------------- ### Initiating an ASR Request Source: https://www.xfyun.cn/doc/asr/ifasr_new/Android.html Example of calling the aRun method to start an ASR task with a local audio file. ```java String filePath = "/sdcard/iflytek/asr/cn_test.pcm"; String resultType = "transfer"; mRAASR.aRun(filePath,resultType,"12345"); ``` -------------------------------- ### Example Output Formats Source: https://www.xfyun.cn/doc/asr/AIkit_commandWord/iOS-SDK.html Demonstrates various output formats for capability results, including pgs, htk, plain, vad, and readable JSON. ```text pgs: 我想 pgs: 我想听 pgs: 我想听周杰 pgs: 我想听周杰伦 pgs: 我想听周杰伦专辑 htk: 我想听 周杰伦专辑 plain: 我想听周杰伦专辑 vad: {"sc":"0","ws":[{"bg":"78","ed":"303","status":"SpeechNormal"}]} readable: {"sc":"12784","mode":"fsa","ismandarin":"true","bg":"78","ed":"303","ws":[{"sc":"0","w":"我想听","slot":"albumwant","pinyin":"","boundary":""},{"sc":"0","w":"周杰伦专辑","slot":"album","pinyin":"","boundary":""}]} vad: {"sc":"0","ws":[{"bg":"-1","ed":"-1","status":"SpeechAutoFinish"}]} readable: {"sc":"0","bg":"-1","ed":"-1","ws":[{"sc":"0","w":"。"}]} ``` -------------------------------- ### ASR LLM Upload Request Example Source: https://www.xfyun.cn/doc/spark/asr_llm/Ifasr_llm.html Example of a GET request to the audio upload API. This includes essential parameters like accessKeyId, dateTime, duration, fileName, fileSize, language, and signatureRandom for initiating an audio transcription task. ```http https://office-api-ist-dx.iflyaisol.com/v2/upload?accessKeyId=testaccesskeyid&dateTime=2018-04-13T20%3A22%3A53%2B0800&duration=56352&fileName=1%E5%88%86%E9%92%9F%E9%9F%B3%E9%A2%91.mp3&fileSize=397144&language=en&signatureRandom=a0289d60-26b3-4601-ad18-d2179dc95fd2 ``` -------------------------------- ### Final URL Construction Example Source: https://www.xfyun.cn/doc/nlp/VideoModeration/API.html This example shows how to append the generated signature and other authentication parameters to the API endpoint URL. ```text https://audit.iflyaisol.com//audit/v2/syncText?accessKeyId=simpleAPIKey&accessKeySecret=simpleAPISecret&utc=2023-02-23T06%3A40%3A54%2B0000&signature=mH2xDQ5f+mO/Pi6DbrxXrzYQxF0=&appId=simpleAPPID&uuid=44dfa903-adb2-45d3-a1fe-fd8a53f86b2a ———————————————————————————————————————————————————————————————————————————————————————————————————————————————— 注意:黑白名单使用鉴权与文本合规鉴权完全一致,只是url地址有变动。具体业务参数通过json以post的形式发送给服务端。 ``` -------------------------------- ### Get Extraction Result Response Example Source: https://www.xfyun.cn/doc/spark/ChatDoc-API.html This is an example of a response containing extracted question-answer pairs from a document. It includes a flag, session ID, status code, description, and a data array with extracted question, answer, and reference chunk indices. ```json { "flag": true, "sid": "9746244f046340e2869630e5f6fe8daa", "code": 0, "desc": null, "data": [{ "id": "664d98e4e241e050529c74c7", "question": "在《鹧鸪天》中,“殷勤昨夜三更雨,又得浮生一日凉”这句诗的含义是什么?", "answer": "在《鹧鸪天》中,“殷勤昨夜三更雨,又得浮生一日凉”这句诗的含义是表达了作者对自然美景的欣赏和对生活的感悟。", "chunkIndexReferences": [1,2,3], "answerChunkIndexReferences": [1,2,3] }] } ``` -------------------------------- ### Configure and Start Voice Wakeuper Source: https://www.xfyun.cn/doc/asr/awaken/iOS-SDK.html Set up wake-up parameters, including resource paths, thresholds, service type, and keep-alive mode. Then, start the wake-up listening service. Ensure system recording permissions are granted. ```Objective-C #import "iflyMSC/IFlyMSC.h" //获取唤醒单例对象 _iflyVoiceWakeuper = [IFlyVoiceWakeuper sharedInstance]; //设置唤醒协议委托 _iflyVoiceWakeuper.delegate = self; //设置唤醒参数 //生成唤醒资源路径并设置唤醒资源,唤醒资源需要定制,与唤醒词一一对应。 NSString *resPath = [[NSBundle mainBundle] resourcePath]; NSString *wordPath = [[NSString alloc] initWithFormat:@"%@/ivw/%@.jet",resPath,APPID_VALUE]; NSString *ivwResourcePath = [IFlyResourceUtil generateResourcePath:wordPath]; [_iflyVoiceWakeuper setParameter:ivwResourcePath forKey:@"ivw_res_path"]; //设置唤醒门限值,新唤醒引擎的默认门限制值为1450 //门限设置要和资源中的唤醒词个数匹配,以;分割。 //例如:0:1450,0代表第一个唤醒词 1450,代表第一个唤醒词门限 //根据下载的SDK中的说明来设置。 //0:表示第一个唤醒词,1450表示唤醒词对应的门限值; //1:表示第二个唤醒词,1450表示唤醒词对应的门限值 [_iflyVoiceWakeuper setParameter:@"0:1450;1:1450;" forKey:@"ivw_threshold"]; //设置唤醒的服务类型,目前仅支持wakeup [_iflyVoiceWakeuper setParameter:@"wakeup" forKey:@"ivw_sst"]; //设置唤醒的工作模式 //keep_alive表示一次唤醒成功后是否继续录音等待唤醒。1:表示继续;0:表示唤醒终止 [_iflyVoiceWakeuper setParameter:@"1" forKey:@"keep_alive"]; //启动唤醒 int bRet = [self.iflyVoiceWakeuper startListening]; ``` -------------------------------- ### Starting an AI Session with Parameters Source: https://www.xfyun.cn/doc/asr/AIkit_commandWord/Android-SDK.html Initiate an AI session using the start method, configuring various parameters like language, VAD settings, and decoding thresholds via AiRequest.Builder. The returned AiHandle object indicates the success or failure of the session start. ```java AiRequest.Builder paramBuilder = AiRequest.builder(); paramBuilder.param("languageType", $paramValue); paramBuilder.param("vadOn", $paramValue); //paramBuilder.param("vadLinkOn", false); paramBuilder.param("vadEndGap", $paramValue); //paramBuilder.param("beamThreshold", 20); //paramBuilder.param("hisGramThreshold", 3000); //paramBuilder.param("vadSpeechEnd", 80); //paramBuilder.param("vadResponsetime", 1000); //paramBuilder.param("postprocOn", false); AiHandle handle = AiHelper.getInst().start("e75f07b62",paramBuilder.build(),null); if (!handle.isSuccess()) { Log.e(TAG, "ERROR::START | handle code:" + handle.getCode()); return; } ``` -------------------------------- ### FileDownloadListener Interface Source: https://www.xfyun.cn/doc/mscapi/Android/androidutil.html Implement this interface to get progress, status, and results of file downloads. Provides callbacks for download start, progress, and completion. ```java com.iflytek.cloud.util public interface FileDownloadListener ``` ```java void onStart() ``` ```java void onProgress(int percent) ``` ```java void onCompleted(java.lang.String filePath, SpeechError error) ``` -------------------------------- ### FaceRequest Methods Source: https://www.xfyun.cn/doc/mscapi/Android/androidverifier.html Provides methods for managing face recognition sessions, including starting recognition, canceling operations, setting and getting parameters, and destroying the session. ```APIDOC ## FaceRequest ### Description Provides methods for managing face recognition sessions, including starting recognition, canceling operations, setting and getting parameters, and destroying the session. ### Methods #### `sendRequest(byte[] img, RequestListener listener)` * **Description**: Starts face registration, verification, detection, and focusing. * **Parameters**: * `img` (byte[]) - Image data. * `listener` (RequestListener) - Listener for recognition status and results. * **Returns**: (int) Error code; 0 for success, otherwise an error code defined in `ErrorCode`. * **See Also**: `setParameter(String, String)`, `FaceRequest(Context)`, `RequestListener`, `cancel()` #### `cancel()` * **Description**: Cancels the current face recognition session. * **See Also**: `sendRequest(byte[], RequestListener)` #### `setParameter(String key, String value)` * **Description**: Sets session parameters before the session starts, such as the business type. * **Parameters**: * `key` (String) - Parameter name. * `value` (String) - Parameter value. * **Returns**: (boolean) `true` if the setting is successful, `false` otherwise. * **See Also**: `getParameter(String)`, `sendRequest(byte[], RequestListener)` #### `getParameter(String key)` * **Description**: Retrieves the current value of a specified parameter. * **Parameters**: * `key` (String) - Parameter name. * **Returns**: (String) The parameter value. * **See Also**: `setParameter(String, String)` #### `destroy()` * **Description**: Destroys the face recognition session. ```