├── .gitignore ├── AIUIChatDemo ├── README.md ├── README.txt ├── app │ ├── build.gradle │ ├── libs │ │ └── AIUI.jar │ ├── proguard-rules.pro │ └── src │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ │ ├── cfg │ │ │ │ └── aiui_phone.cfg │ │ │ ├── data │ │ │ │ ├── 001_branch_menu.txt │ │ │ │ └── 002_branch_menu.txt │ │ │ └── vad │ │ │ │ └── meta_vad_16k.jet │ │ ├── java │ │ │ └── com │ │ │ │ └── iflytek │ │ │ │ └── aiui │ │ │ │ └── demo │ │ │ │ └── chat │ │ │ │ ├── ChatActivity.java │ │ │ │ ├── ChatApp.java │ │ │ │ ├── common │ │ │ │ └── Constant.java │ │ │ │ ├── db │ │ │ │ ├── Converters.java │ │ │ │ ├── MessageDB.java │ │ │ │ └── MessageDao.java │ │ │ │ ├── di │ │ │ │ ├── AppModule.java │ │ │ │ ├── ChatActivityModule.java │ │ │ │ └── ViewModelKey.java │ │ │ │ ├── model │ │ │ │ ├── InteractMessage.java │ │ │ │ ├── Message.java │ │ │ │ ├── MessageHandler.java │ │ │ │ ├── Settings.java │ │ │ │ ├── data │ │ │ │ │ ├── DynamicEntityData.java │ │ │ │ │ ├── SemanticResult.java │ │ │ │ │ └── SpeakableSyncData.java │ │ │ │ └── handler │ │ │ │ │ ├── DefaultHandler.java │ │ │ │ │ ├── DishSkillHandler.java │ │ │ │ │ ├── DynamicEntityHandler.java │ │ │ │ │ ├── Handler.java │ │ │ │ │ ├── HintHandler.java │ │ │ │ │ ├── JokeHandler.java │ │ │ │ │ ├── NotificationHandler.java │ │ │ │ │ ├── OrderMenuHandler.java │ │ │ │ │ ├── PlayerHandler.java │ │ │ │ │ ├── RadioDisposer.java │ │ │ │ │ ├── StoryHandler.java │ │ │ │ │ ├── TelephoneHandler.java │ │ │ │ │ └── WeatherHandler.java │ │ │ │ ├── repository │ │ │ │ ├── AIUIRepository.java │ │ │ │ ├── ContactRepository.java │ │ │ │ ├── LocationRepo.java │ │ │ │ ├── SettingsRepo.java │ │ │ │ ├── Storage.java │ │ │ │ └── player │ │ │ │ │ ├── AIUIPlayer.java │ │ │ │ │ └── PlayState.java │ │ │ │ └── ui │ │ │ │ ├── PermissionChecker.java │ │ │ │ ├── ViewModelFactory.java │ │ │ │ ├── about │ │ │ │ ├── AboutFragment.java │ │ │ │ └── AboutViewModel.java │ │ │ │ ├── chat │ │ │ │ ├── ChatFragment.java │ │ │ │ ├── ChatViewModel.java │ │ │ │ ├── DataBoundListAdapter.java │ │ │ │ ├── DataBoundViewHolder.java │ │ │ │ ├── ItemListener.java │ │ │ │ ├── MessageListAdapter.java │ │ │ │ ├── PlayerViewModel.java │ │ │ │ └── ScrollSpeedLinearLayoutManger.java │ │ │ │ ├── common │ │ │ │ ├── SingleLiveEvent.java │ │ │ │ ├── visualizer │ │ │ │ │ └── VisualizerView.java │ │ │ │ └── widget │ │ │ │ │ └── PopupWindowFactory.java │ │ │ │ ├── detail │ │ │ │ └── DetailFragment.java │ │ │ │ ├── settings │ │ │ │ ├── SettingViewModel.java │ │ │ │ └── SettingsFragment.java │ │ │ │ └── view │ │ │ │ └── ChatBubbleLayout.java │ │ ├── jniLibs │ │ │ └── armeabi │ │ │ │ └── libaiui.so │ │ └── res │ │ │ ├── anim │ │ │ ├── anim_wave.xml │ │ │ ├── slide_left_in.xml │ │ │ ├── slide_left_out.xml │ │ │ ├── slide_right_in.xml │ │ │ └── slide_right_out.xml │ │ │ ├── drawable-v21 │ │ │ └── ic_menu_manage.xml │ │ │ ├── drawable-xhdpi │ │ │ ├── icon_chat_voice.png │ │ │ ├── icon_keyboard.png │ │ │ └── logo.png │ │ │ ├── drawable-xxhdpi │ │ │ ├── aiui.png │ │ │ ├── insight.png │ │ │ └── user.png │ │ │ ├── drawable │ │ │ ├── corners_edit.xml │ │ │ ├── corners_edit_white.xml │ │ │ ├── ic_feedback_black_24dp.xml │ │ │ ├── ic_info_black_24dp.xml │ │ │ ├── ic_pause_black_24dp.xml │ │ │ ├── ic_play_arrow_black_24dp.xml │ │ │ ├── ic_report_black_24dp.xml │ │ │ ├── ic_settings_black_24dp.xml │ │ │ ├── ic_skip_next_black_24dp.xml │ │ │ ├── ic_skip_previous_black_24dp.xml │ │ │ ├── record_microphone.xml │ │ │ ├── record_microphone_bj.xml │ │ │ ├── send_btn_back.xml │ │ │ └── side_nav_bar.xml │ │ │ ├── layout │ │ │ ├── about_fragment.xml │ │ │ ├── activity_main.xml │ │ │ ├── aiui_player_controller.xml │ │ │ ├── appid_key_preference.xml │ │ │ ├── chat_fragment.xml │ │ │ ├── chat_item.xml │ │ │ ├── detail_fragment.xml │ │ │ ├── layout_microphone.xml │ │ │ └── nav_header_main.xml │ │ │ ├── menu │ │ │ └── drawer.xml │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ ├── icon_chat_add.png │ │ │ ├── icon_chat_expression.png │ │ │ ├── icon_chat_photo.png │ │ │ ├── icon_chat_photograph.png │ │ │ ├── icon_chat_voice.png │ │ │ ├── icon_keyboard.png │ │ │ ├── icon_voice_left1.png │ │ │ ├── icon_voice_left2.png │ │ │ ├── icon_voice_left3.png │ │ │ ├── icon_voice_right1.png │ │ │ ├── icon_voice_right2.png │ │ │ ├── icon_voice_right3.png │ │ │ ├── record_bottom.png │ │ │ └── record_top.png │ │ │ ├── values-zh-rCN │ │ │ └── values-zh-rCN.xml │ │ │ ├── values │ │ │ ├── attr.xml │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── drawables.xml │ │ │ ├── integers.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ │ └── xml │ │ │ ├── filepaths.xml │ │ │ └── pref_settings.xml │ │ └── sample │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── iflytek │ │ │ └── aiui │ │ │ └── demo │ │ │ └── chat │ │ │ ├── NlpDemo.java │ │ │ ├── di │ │ │ ├── AppComponent.java │ │ │ ├── FragmentBuildersModule.java │ │ │ └── ViewModelModule.java │ │ │ └── util │ │ │ └── FucUtil.java │ │ └── res │ │ └── layout │ │ └── nlpdemo.xml ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots │ ├── call_upload.jpg │ ├── call_use.jpg │ ├── menu_item.png │ ├── menu_skill.png │ ├── menu_upload.jpg │ └── menu_use.jpg └── settings.gradle ├── README.md ├── aiui ├── c-sharp │ ├── .gitignore │ ├── README.txt │ ├── aiui_csharp_demo.sln │ ├── aiui_csharp_demo │ │ ├── .gitignore │ │ ├── AIUI │ │ │ ├── audio │ │ │ │ └── test.pcm │ │ │ └── cfg │ │ │ │ └── aiui.cfg │ │ ├── AIUIConstant.cs │ │ ├── AIUISetting.cs │ │ ├── IAIUIAgent.cs │ │ ├── IAIUIBuffer.cs │ │ ├── IAIUIEvent.cs │ │ ├── IAIUIMessage.cs │ │ ├── IDataBundle.cs │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── aiui_csharp_demo.csproj │ │ ├── aiui_csharp_demo.csproj.user │ │ ├── app.config │ │ └── packages.config │ └── packages │ │ ├── NAudio.1.9.0 │ │ ├── .signature.p7s │ │ ├── NAudio.1.9.0.nupkg │ │ └── lib │ │ │ ├── net35 │ │ │ ├── NAudio.dll │ │ │ └── NAudio.xml │ │ │ ├── netstandard2.0 │ │ │ ├── NAudio.dll │ │ │ └── NAudio.xml │ │ │ └── uap10.0.10240 │ │ │ ├── NAudio.dll │ │ │ ├── NAudio.pri │ │ │ └── NAudio.xml │ │ └── Newtonsoft.Json.13.0.1 │ │ ├── .signature.p7s │ │ ├── LICENSE.md │ │ ├── Newtonsoft.Json.13.0.1.nupkg │ │ ├── lib │ │ ├── net20 │ │ │ ├── Newtonsoft.Json.dll │ │ │ └── Newtonsoft.Json.xml │ │ ├── net35 │ │ │ ├── Newtonsoft.Json.dll │ │ │ └── Newtonsoft.Json.xml │ │ ├── net40 │ │ │ ├── Newtonsoft.Json.dll │ │ │ └── Newtonsoft.Json.xml │ │ ├── net45 │ │ │ ├── Newtonsoft.Json.dll │ │ │ └── Newtonsoft.Json.xml │ │ ├── netstandard1.0 │ │ │ ├── Newtonsoft.Json.dll │ │ │ └── Newtonsoft.Json.xml │ │ ├── netstandard1.3 │ │ │ ├── Newtonsoft.Json.dll │ │ │ └── Newtonsoft.Json.xml │ │ └── netstandard2.0 │ │ │ ├── Newtonsoft.Json.dll │ │ │ └── Newtonsoft.Json.xml │ │ └── packageIcon.png ├── c │ ├── AIUI │ │ ├── audio │ │ │ └── weather.pcm │ │ └── cfg │ │ │ └── aiui.cfg │ ├── README.txt │ ├── include │ │ └── aiui │ │ │ ├── AIUI.h │ │ │ ├── AIUICommon.h │ │ │ ├── AIUIConstant.h │ │ │ ├── AIUIErrorCode.h │ │ │ ├── AIUIType.h │ │ │ ├── AIUI_C.h │ │ │ └── AIUI_V2.h │ └── main.c ├── java │ ├── Main.java │ ├── README.txt │ └── aiui-1.0.0.jar └── python │ ├── AIUI │ ├── audio │ │ └── test.pcm │ └── cfg │ │ └── aiui.cfg │ ├── README.txt │ ├── main.py │ └── pyaiui.py ├── docs ├── .gitignore ├── Makefile ├── _static │ ├── .gitkeep │ ├── aiui.css │ └── screenshot_1519613427018.4507411a.png ├── _templates │ └── .gitkeep ├── conf.py ├── index.rst ├── make.bat └── src │ ├── error_code.rst │ └── index.rst ├── postprocess-demo ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── iflytek │ │ │ └── aiint │ │ │ └── demo │ │ │ ├── PostprocessDemoApplication.java │ │ │ └── postprocess │ │ │ ├── ApplicationPostprocessDemo.java │ │ │ └── SkillPostprocessDemo.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── iflytek │ └── aiint │ └── demo │ └── PostprocessDemoApplicationTests.java ├── webapi ├── doc │ ├── apikey.png │ ├── createApp.png │ ├── ip.png │ ├── skill.png │ ├── webapi接口接入文档.docx │ └── webapi接口接入文档.md ├── java │ └── Iat.java ├── nodejs │ └── iat.js └── python │ └── iat.py ├── webapi_v2 ├── c-sharp │ └── WebaiuiDemo.cs ├── doc │ ├── 接口概述.md │ ├── 接口详情.md │ ├── 简介.md │ └── 错误码.md ├── go │ └── WebaiuiDemo.go ├── java │ ├── WebaiuiDemo.java │ └── commons-codec-1.6.jar ├── nodejs │ └── WebaiuiDemo.js ├── php │ └── WebaiuiDemo.php ├── python │ └── WebaiuiDemo.py └── resource │ └── bj_weather.wav ├── webapi_v2_entity ├── doc │ └── 动态实体webapi.md ├── java │ └── WebEntityDemo.java └── python │ └── WebEntityDemo.py └── websocket ├── c-sharp ├── aiui_ws_csharp_demo.sln ├── aiui_ws_csharp_demo │ ├── .gitignore │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── aiui_ws_csharp_demo.csproj │ ├── packages.config │ └── test.pcm └── packages │ └── WebSocketSharp-netstandard.1.0.1 │ ├── .signature.p7s │ ├── WebSocketSharp-netstandard.1.0.1.nupkg │ └── lib │ ├── net35 │ ├── websocket-sharp.dll │ └── websocket-sharp.xml │ ├── net45 │ ├── websocket-sharp.dll │ └── websocket-sharp.xml │ └── netstandard2.0 │ ├── websocket-sharp.dll │ └── websocket-sharp.xml ├── c ├── .gitignore ├── CMakeLists.txt ├── README.txt ├── bin │ └── test.pcm └── src │ ├── aiui.c │ ├── aiui │ ├── aiui_base64.h │ ├── aiui_cJSON.h │ ├── aiui_check_config.h │ ├── aiui_config.h │ ├── aiui_platform_util.h │ ├── aiui_sha1.h │ ├── aiui_sha256.h │ └── aiui_wsclient.h │ ├── aiui_base64.c │ ├── aiui_cJSON.c │ ├── aiui_extern.c │ ├── aiui_main.c │ ├── aiui_platform_util.c │ ├── aiui_sha1.c │ ├── aiui_sha256.c │ └── aiui_wsclient.c ├── go └── aiui_websocket_demo.go ├── java ├── lib │ ├── Java-WebSocket-1.3.7.jar │ └── commons-codec-1.6.jar └── src │ └── com │ └── iflytek │ └── aiui │ └── websocketdemo │ ├── AiuiWsDemo.java │ └── DraftWithOrigin.java ├── js ├── aiui-websocket-demo.js ├── package.json └── weather.pcm └── python ├── aiui_websocket_demo_py3.py └── weather.pcm /.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | *.cache 3 | node_modules 4 | package-lock.json -------------------------------------------------------------------------------- /AIUIChatDemo/README.md: -------------------------------------------------------------------------------- 1 | AIUIChatDemo是一个集成了AIUI SDK的用于演示AIUI功能的产品Demo,同时开放源码供开发者集成时进行参考。 2 | Demo支持通过语音或文本进行交互,并且会对听写和语义的结果进行处理展示。 3 | 4 | ## 动态实体与所见即可说 5 | 6 | ### 介绍 7 | 8 | AIUI动态实体的概念参见[AIUI动态实体](http://xfyun-doc.ufile.ucloud.com.cn/1519615970164780/%E5%AE%9E%E4%BD%93%E4%BB%8B%E7%BB%8D3.pdf)。 9 | 动态实体还有一种特殊的维度,名为所见即可说。该种动态实体上传的内容只会生效使用一次,在上传后生效交互一次后,即会恢复无数据的状态。 该维度适用于一些临时数据,如只在当前屏幕显示的信息,在上传当前屏幕内容数据后,用户根据当前屏幕的内容进行交互,交互过后屏幕内容即会刷新。 10 | 11 | ### 使用 12 | 13 | AIUI动态实体使用参见[AIUI动态实体使用](http://aiui.xfyun.cn/access_docs/aiui-sdk/mobile_doc/%E7%94%A8%E6%88%B7%E4%B8%AA%E6%80%A7%E5%8C%96.html#动态实体)。 14 | 所见即可说使用参见[AIUI所见即可说使用](http://aiui.xfyun.cn/access_docs/aiui-sdk/mobile_doc/%E7%94%A8%E6%88%B7%E4%B8%AA%E6%80%A7%E5%8C%96.html#所见即可说)。 15 | 16 | ### Demo说明 17 | 18 | Demo演示了用户级和自定义两种维度的实体以及所见即可说的使用。 19 | 20 | 用户级实体定义位于src/main/java/com/iflytek/aiui/demo/chat/model/handler/TelephoneHandler.java。上传成功后,通过 ``打电话给xxx``(xxx为手机联系人)就会识别正确的联系人名字并且返回包含联系人信息的电话语义结果。 21 | 22 | 自定义级实体定义位于src/main/java/com/iflytek/aiui/demo/chat/model/handler/OrderMenuHandler.java。上传成功后,通过 ``我要点xxx``来进行点菜。 23 | 24 | 所见即可说实体定义位于src/main/java/com/iflytek/aiui/demo/chat/model/handler/DishSkillHandler.java。 25 | 26 | ## 常见问题 27 | **Q:Demo中AIUI SDK的调用在哪?**
28 | **A:** Demo对于AIUI SDK的调用位于源码src/main/java/com/iflytek/aiui/demo/chat/repository/AIUIRepository.java中。 29 | 同时Demo中也提供了一个完整调用AIUI SDK的简单入口,源码位于src/sample/java/com/iflytek/aiui/demo/chat/NlpDemo.java, 30 | 你可以通过在Manifest中指定Demo入口Activity为NlpDemo进行体验。 31 | 32 | **Q:Demo如何启用唤醒功能?**
33 | **A:** 参考[语音唤醒文档](http://aiui.xfyun.cn/access_docs/aiui-sdk/mobile_doc/%E4%BA%A4%E4%BA%92%E6%8E%A7%E5%88%B6.html#语音唤醒)。 -------------------------------------------------------------------------------- /AIUIChatDemo/README.txt: -------------------------------------------------------------------------------- 1 | AIUIChatDemo是一个集成了AIUI SDK的用于演示AIUI功能的产品Demo,同时开放源码供开发者集成时进行参考。 2 | Demo支持通过语音或文本进行交互,并且会对听写和语义的结果进行处理展示。 3 | 4 | Q:Demo中AIUI SDK的调用在哪? 5 | A:Demo对于AIUI SDK的调用位于源码中src/main/java/com/iflytek/aiui/demo/chat/repository/AIUIRepository.java。 6 | 同时Demo中也提供了一个完整调用AIUI SDK的简单入口,源码位于src/sample/java/com/iflytek/aiui/demo/chat/NlpDemo.java, 7 | 你可以通过在Manifest中指定Demo入口Activity为NlpDemo进行体验。 8 | 9 | Q:Demo如何启用唤醒功能? 10 | A:步骤如下: 11 | 1. 下载唤醒资源,重命名为ivw.jet, 放入src/main/assets/ivw/下 12 | 2. 将平台上下载的唤醒SDK中的Msc.jar放入libs/下,libmsc.so放入src/main/jniLibs/armeabi下 13 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | ext { 3 | support_ver = '26.1.0' 4 | } 5 | android { 6 | compileSdkVersion 26 7 | buildToolsVersion '26.0.2' 8 | defaultConfig { 9 | applicationId "com.iflytek.aiui.demo.chat" 10 | minSdkVersion 18 11 | targetSdkVersion 25 12 | versionCode 19 13 | versionName "1.3.7" 14 | vectorDrawables.useSupportLibrary = true 15 | ndk { 16 | abiFilters 'armeabi' 17 | } 18 | } 19 | 20 | dataBinding { 21 | enabled = true 22 | } 23 | 24 | lintOptions { 25 | abortOnError false 26 | } 27 | 28 | buildTypes { 29 | release { 30 | minifyEnabled false 31 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 32 | } 33 | } 34 | 35 | flavorDimensions 'version' 36 | productFlavors { 37 | sample { 38 | dimension 'version' 39 | versionName "${defaultConfig.versionName}.sample" 40 | 41 | if(file('src/main/jniLibs/armeabi/libmsc.so').exists()) { 42 | buildConfigField 'Boolean', 'WAKEUP_ENABLE', 'true' 43 | } else { 44 | buildConfigField 'Boolean', 'WAKEUP_ENABLE', 'false' 45 | } 46 | } 47 | } 48 | 49 | applicationVariants.all { variant -> 50 | variant.outputs.all { 51 | outputFileName = "AIUIChatDemo-${variant.flavorName}-${variant.buildType.name}-${variant.versionName}.apk" 52 | } 53 | } 54 | 55 | dexOptions { 56 | jumboMode true 57 | } 58 | } 59 | 60 | dependencies { 61 | implementation fileTree(dir: 'libs', include: ['*.jar']) 62 | 63 | implementation 'com.google.dagger:dagger:2.12' 64 | implementation 'com.google.android.gms:play-services-plus:11.8.0' 65 | annotationProcessor 'com.google.dagger:dagger-compiler:2.12' 66 | annotationProcessor 'com.google.dagger:dagger-android-processor:2.12' 67 | implementation 'com.google.dagger:dagger-android:2.12' 68 | implementation 'com.google.dagger:dagger-android-support:2.12' 69 | implementation "com.android.support:support-vector-drawable:$support_ver" 70 | implementation "com.android.support:design:$support_ver" 71 | implementation "com.android.support:appcompat-v7:$support_ver" 72 | implementation "com.android.support:cardview-v7:$support_ver" 73 | implementation "com.android.support:preference-v7:$support_ver" 74 | implementation "com.android.support:preference-v14:$support_ver" 75 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 76 | testImplementation 'junit:junit:4.12' 77 | 78 | implementation "android.arch.lifecycle:extensions:1.1.0" 79 | annotationProcessor "android.arch.lifecycle:compiler:1.1.0" 80 | implementation "android.arch.persistence.room:runtime:1.0.0" 81 | annotationProcessor "android.arch.persistence.room:compiler:1.0.0" 82 | 83 | implementation "io.reactivex.rxjava2:rxjava:2.1.2" 84 | implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' 85 | implementation 'com.zzhoujay.richtext:richtext:2.5.4' 86 | implementation 'com.karumi:dexter:4.1.0' 87 | implementation 'com.daasuu:BubbleLayout:1.2.0' 88 | implementation 'com.github.Jay-Goo:WaveLineView:v1.0.3' 89 | implementation 'com.pddstudio:highlightjs-android:1.5.0' 90 | implementation 'com.google.android.exoplayer:exoplayer-core:2.6.1' 91 | implementation 'com.jakewharton.timber:timber:4.6.1' 92 | } 93 | 94 | 95 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/libs/AIUI.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/libs/AIUI.jar -------------------------------------------------------------------------------- /AIUIChatDemo/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Android\android-sdk-windows/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | 27 | -keep class com.iflytek.**{*;} 28 | -dontwarn ** 29 | -keepattributes Signature 30 | 31 | 32 | ## 极光推送 33 | -dontoptimize 34 | -dontpreverify 35 | 36 | -dontwarn cn.jpush.** 37 | -keep class cn.jpush.** { *; } 38 | -keep class * extends cn.jpush.android.helpers.JPushMessageReceiver { *; } 39 | 40 | -dontwarn cn.jiguang.** 41 | -keep class cn.jiguang.** { *; } 42 | 43 | -dontwarn com.tencent.bugly.** 44 | -keep public class com.tencent.bugly.**{*;} 45 | 46 | -keep class com.sun.mail.** { *; } 47 | -keep class javax.mail.** { *; } 48 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/assets/cfg/aiui_phone.cfg: -------------------------------------------------------------------------------- 1 | /* AIUI Mobile版本参数配置 */ 2 | { 3 | /* 登录参数 */ 4 | "login":{ 5 | "appid":"XXXXXXXX" 6 | }, 7 | /* 交互参数 */ 8 | "interact":{ 9 | "interact_timeout":"60000", 10 | "result_timeout":"5000" 11 | }, 12 | 13 | /* 全局设置 */ 14 | "global":{ 15 | "scene":"main", 16 | "clean_dialog_history":"auto" 17 | }, 18 | 19 | /* 业务相关参数 */ 20 | // 本地vad参数 21 | "vad":{ 22 | "vad_enable":"1", 23 | "engine_type":"meta", 24 | "res_type":"assets", 25 | "res_path":"vad/meta_vad_16k.jet" 26 | }, 27 | 28 | // 识别(音频输入)参数 29 | "iat":{ 30 | "sample_rate":"16000" 31 | }, 32 | 33 | "audioparams":{ 34 | 35 | }, 36 | 37 | /* 业务流程相关参数 */ 38 | // 语音业务流程控制 39 | "speech":{ 40 | "data_source":"sdk", 41 | "interact_mode": "continuous" 42 | }, 43 | /* 日志设置 */ 44 | "log":{ 45 | "debug_log":"0", 46 | "save_datalog":"0", 47 | "datalog_path":"", 48 | "datalog_size":1024, 49 | "raw_audio_path":"" 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/assets/data/001_branch_menu.txt: -------------------------------------------------------------------------------- 1 | 蒸羊羔 2 | 蒸熊掌 3 | 蒸鹿尾 4 | 烧花鸭 5 | 烧雏鸡 6 | 烧子鹅 7 | 卤猪 8 | 卤鸭 9 | 酱鸡 10 | 腊肉 11 | 松花小肚 12 | 晾肉 13 | 香肠 14 | 什锦苏盘 15 | 熏鸡白肚 16 | 清蒸八宝猪 17 | 江米酿鸭子 -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/assets/data/002_branch_menu.txt: -------------------------------------------------------------------------------- 1 | 咸肉丝 2 | 白肉丝 3 | 荸荠一品锅 4 | 素炝春不老 5 | 清焖莲子 6 | 酸黄菜 7 | 烧萝卜 8 | 脂油雪花儿菜 9 | 烩银耳 10 | 炒银枝儿 11 | 八宝榛子酱 12 | 黄鱼锅子 13 | 白菜锅子 14 | 什锦锅子 15 | 汤圆锅子 16 | 菊花锅子 17 | 杂烩锅子 18 | 煮饽饽锅子 19 | 肉丁辣酱 20 | 炒肉丝 21 | 炒肉片 22 | 烩酸菜 23 | 烩白菜 24 | 烩豌豆 25 | 焖扁豆 26 | 氽毛豆 27 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/assets/vad/meta_vad_16k.jet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/assets/vad/meta_vad_16k.jet -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ChatApp.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat; 2 | 3 | import android.app.Activity; 4 | import android.app.Application; 5 | 6 | import com.iflytek.aiui.demo.chat.di.DaggerAppComponent; 7 | import javax.inject.Inject; 8 | 9 | import dagger.android.AndroidInjector; 10 | import dagger.android.DispatchingAndroidInjector; 11 | import dagger.android.HasActivityInjector; 12 | 13 | /** 14 | * Created by PR on 2017/11/9. 15 | */ 16 | 17 | public class ChatApp extends Application implements HasActivityInjector { 18 | @Inject 19 | DispatchingAndroidInjector dispatchingAndroidInjector; 20 | 21 | @Override 22 | public void onCreate() { 23 | super.onCreate(); 24 | 25 | DaggerAppComponent 26 | .builder() 27 | .application(this) 28 | .build() 29 | .inject(this); 30 | } 31 | 32 | @Override 33 | public AndroidInjector activityInjector() { 34 | return dispatchingAndroidInjector; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/common/Constant.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.common; 2 | 3 | /** 4 | * Created by PR on 2017/8/11. 5 | */ 6 | 7 | public class Constant { 8 | public static final String SPEAKABLE = "speakable"; 9 | public static final String DYNAMIC = "dynamic"; 10 | public static final String DYNAMIC_QUERY = "dynamic_query"; 11 | 12 | public static final int STATE_WAITING_WAKEUP = 0; 13 | public static final int STATE_WAKEUP = 1; 14 | public static final int STATE_TEXT = 2; 15 | public static final int STATE_VOICE = 3; 16 | public static final int STATE_VOICE_INPUTTING = 4; 17 | } 18 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/db/Converters.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.db; 2 | 3 | import android.arch.persistence.room.TypeConverter; 4 | 5 | import com.iflytek.aiui.demo.chat.model.Message; 6 | 7 | /** 8 | * Created by PR on 2017/8/3. 9 | */ 10 | 11 | public class Converters { 12 | @TypeConverter 13 | public int msgTypeConvert(Message.MsgType type){ 14 | return type.ordinal(); 15 | } 16 | 17 | @TypeConverter 18 | public Message.MsgType msgTypeConvert(int type){ 19 | return Message.MsgType.values()[type]; 20 | } 21 | 22 | @TypeConverter 23 | public int fromTypeConvert(Message.FromType type){ 24 | return type.ordinal(); 25 | } 26 | 27 | @TypeConverter 28 | public Message.FromType fromTypeConvert(int type){ 29 | return Message.FromType.values()[type]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/db/MessageDB.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.db; 2 | 3 | import android.arch.persistence.room.Database; 4 | import android.arch.persistence.room.RoomDatabase; 5 | import android.arch.persistence.room.TypeConverters; 6 | 7 | import com.iflytek.aiui.demo.chat.model.Message; 8 | 9 | /** 10 | * Created by PR on 2017/8/3. 11 | */ 12 | @Database(entities = {Message.class}, version = 1, exportSchema = false) 13 | @TypeConverters({Converters.class}) 14 | public abstract class MessageDB extends RoomDatabase{ 15 | public abstract MessageDao messageDao(); 16 | } 17 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/db/MessageDao.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.db; 2 | 3 | import android.arch.lifecycle.LiveData; 4 | import android.arch.persistence.room.Dao; 5 | import android.arch.persistence.room.Insert; 6 | import android.arch.persistence.room.Query; 7 | import android.arch.persistence.room.Update; 8 | 9 | import com.iflytek.aiui.demo.chat.model.Message; 10 | 11 | import java.util.List; 12 | 13 | import io.reactivex.Flowable; 14 | 15 | /** 16 | * Created by PR on 2017/8/3. 17 | */ 18 | @Dao 19 | public interface MessageDao { 20 | @Insert 21 | public void addMessage(Message msg); 22 | 23 | @Update 24 | public void updateMessage(Message msg); 25 | 26 | @Query("select * from message") 27 | public LiveData> getAllMessage(); 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/di/ChatActivityModule.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.di; 2 | 3 | import com.iflytek.aiui.demo.chat.ChatActivity; 4 | 5 | import dagger.Module; 6 | import dagger.android.ContributesAndroidInjector; 7 | 8 | /** 9 | * Created by PR on 2017/11/9. 10 | */ 11 | 12 | @Module 13 | public abstract class ChatActivityModule { 14 | @ContributesAndroidInjector(modules = {FragmentBuildersModule.class}) 15 | public abstract ChatActivity contributesChatActivity(); 16 | } 17 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/di/ViewModelKey.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.di; 2 | 3 | import android.arch.lifecycle.ViewModel; 4 | 5 | import java.lang.annotation.Documented; 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | import dagger.MapKey; 12 | 13 | @Documented 14 | @Target({ElementType.METHOD}) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @MapKey 17 | @interface ViewModelKey { 18 | Class value(); 19 | } 20 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/InteractMessage.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model; 2 | 3 | import com.iflytek.aiui.demo.chat.ui.PermissionChecker; 4 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 5 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 6 | 7 | /** 8 | * Created by PR on 2017/11/7. 9 | */ 10 | 11 | public class InteractMessage { 12 | private Message mMsgImpl; 13 | private MessageHandler mHandler; 14 | private ChatViewModel mModel; 15 | 16 | public InteractMessage(Message message, PermissionChecker checker, ChatViewModel viewModel, PlayerViewModel player) { 17 | mModel = viewModel; 18 | mMsgImpl = message; 19 | mHandler = new MessageHandler(viewModel, player, checker, message); 20 | } 21 | 22 | public Message getMessage() { 23 | return mMsgImpl; 24 | } 25 | 26 | public MessageHandler getHandler() { 27 | return mHandler; 28 | } 29 | 30 | public String getDisplayText() { 31 | if(mMsgImpl.cacheContent== null) { 32 | mMsgImpl.cacheContent = mHandler.getFormatMessage(); 33 | mModel.updateMessage(mMsgImpl); 34 | } 35 | 36 | return mMsgImpl.cacheContent; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/Message.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model; 2 | 3 | import android.arch.persistence.room.Entity; 4 | import android.arch.persistence.room.Ignore; 5 | import android.arch.persistence.room.PrimaryKey; 6 | import android.text.TextUtils; 7 | 8 | import java.nio.ByteBuffer; 9 | 10 | /** 11 | * Created by PR on 2017/7/26. 12 | */ 13 | @Entity 14 | public class Message { 15 | public enum MsgType { 16 | TEXT, Voice 17 | } 18 | 19 | public enum FromType { 20 | USER, AIUI 21 | } 22 | 23 | @PrimaryKey 24 | public long timestamp; 25 | public FromType fromType; 26 | public MsgType msgType; 27 | public String cacheContent; 28 | public byte[] msgData; 29 | 30 | public Message(FromType fromType, MsgType msgType, byte[] msgData, String cacheContent 31 | , long timestamp) { 32 | this.fromType = fromType; 33 | this.msgType = msgType; 34 | this.msgData = msgData; 35 | this.timestamp = timestamp; 36 | this.cacheContent = cacheContent; 37 | } 38 | 39 | @Ignore 40 | public Message(FromType fromType, MsgType msgType, byte[] msgData) { 41 | this(fromType, msgType, msgData, null, System.currentTimeMillis()); 42 | } 43 | 44 | public boolean isText() { 45 | return msgType == MsgType.TEXT; 46 | } 47 | 48 | public boolean isEmptyContent() {return TextUtils.isEmpty(cacheContent);} 49 | 50 | public boolean isFromUser() { 51 | return fromType == FromType.USER; 52 | } 53 | 54 | public int getAudioLen() { 55 | if(msgType == MsgType.Voice){ 56 | return Math.round(ByteBuffer.wrap(msgData).getFloat()); 57 | } else { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/Settings.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model; 2 | 3 | /** 4 | * Created by PR on 2017/12/14. 5 | */ 6 | 7 | public class Settings { 8 | public boolean wakeup; 9 | 10 | public int bos; 11 | public int eos; 12 | 13 | public boolean debugLog; 14 | public boolean saveDebugLog; 15 | 16 | public String appid; 17 | public String key; 18 | public String scene; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/data/DynamicEntityData.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.data; 2 | 3 | /** 4 | * Created by PR on 2017/8/7. 5 | */ 6 | 7 | public class DynamicEntityData { 8 | public String resName; 9 | public String idName; 10 | public String idValue; 11 | public String syncData; 12 | 13 | public DynamicEntityData(String resName, String idName, String idValue, String syncData) { 14 | this.resName = resName; 15 | this.idName = idName; 16 | this.idValue = idValue; 17 | this.syncData = syncData; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/data/SemanticResult.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.data; 2 | 3 | import org.json.JSONObject; 4 | 5 | /** 6 | * Created by PR on 2017/8/2. 7 | */ 8 | 9 | public class SemanticResult { 10 | public int rc; 11 | public String service; 12 | public String answer; 13 | public JSONObject data; 14 | public JSONObject semantic; 15 | } 16 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/data/SpeakableSyncData.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.data; 2 | 3 | import android.text.TextUtils; 4 | 5 | /** 6 | * Created by PR on 2017/8/4. 7 | */ 8 | 9 | public class SpeakableSyncData { 10 | public String resName; 11 | public String skillName; 12 | public String masterKey; 13 | public String subKeys; 14 | public String speakableData; 15 | 16 | 17 | public SpeakableSyncData(String resName, String skillName, String speakableData, 18 | String masterKey, String... subKeys){ 19 | this.resName = resName; 20 | this.skillName = skillName; 21 | this.speakableData = speakableData; 22 | this.masterKey = masterKey; 23 | this.subKeys = TextUtils.join(",", subKeys); 24 | } 25 | 26 | public SpeakableSyncData(String resName, String skillName, String speakableData){ 27 | this.resName = resName; 28 | this.skillName = skillName; 29 | this.speakableData = speakableData; 30 | this.masterKey = null; 31 | this.subKeys = null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/handler/DefaultHandler.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.handler; 2 | 3 | import android.text.TextUtils; 4 | 5 | import com.iflytek.aiui.demo.chat.model.data.SemanticResult; 6 | import com.iflytek.aiui.demo.chat.repository.player.AIUIPlayer; 7 | import com.iflytek.aiui.demo.chat.ui.PermissionChecker; 8 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 9 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 10 | 11 | import org.json.JSONArray; 12 | import org.json.JSONObject; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.regex.Pattern; 17 | 18 | /** 19 | * Created by PR on 2017/8/4. 20 | */ 21 | 22 | public class DefaultHandler extends Handler { 23 | private Pattern typePattern = Pattern.compile("\\d"); 24 | 25 | public DefaultHandler(ChatViewModel model, PlayerViewModel player, PermissionChecker checker, SemanticResult result) { 26 | super(model, player, checker, result); 27 | } 28 | 29 | @Override 30 | public String getFormatContent() { 31 | if(result.data != null) { 32 | List songList = new ArrayList<>(); 33 | JSONArray list = result.data.optJSONArray("result"); 34 | if(list != null){ 35 | for(int index = 0; index < list.length(); index++){ 36 | JSONObject item = list.optJSONObject(index); 37 | int contentType = item.optInt("type", -1); 38 | switch (contentType) { 39 | //文本内容 40 | case 0:{ 41 | //显示第一条结果 42 | result.answer += NEWLINE_NO_HTML + NEWLINE_NO_HTML + item.optString("content"); 43 | break; 44 | } 45 | //音频内容(1) 视频内容(2) 46 | case 1: 47 | case 2: { 48 | String audioPath = item.optString("url"); 49 | String songname = item.optString("title"); 50 | if(TextUtils.isEmpty(songname)) { 51 | songname = item.optString("name"); 52 | } 53 | 54 | songList.add(new AIUIPlayer.SongInfo(songname, songname, audioPath)); 55 | break; 56 | } 57 | } 58 | } 59 | } 60 | 61 | if(songList.size() != 0) { 62 | mPlayer.playList(songList); 63 | if(isNeedShowContrlTip()) { 64 | result.answer = result.answer + NEWLINE_NO_HTML + NEWLINE_NO_HTML + CONTROL_TIP; 65 | } 66 | } 67 | } 68 | 69 | return result.answer; 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/handler/DynamicEntityHandler.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.handler; 2 | 3 | import com.iflytek.aiui.demo.chat.model.data.SemanticResult; 4 | import com.iflytek.aiui.demo.chat.ui.PermissionChecker; 5 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 6 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 7 | 8 | import org.json.JSONException; 9 | 10 | import java.util.concurrent.TimeUnit; 11 | 12 | import io.reactivex.Completable; 13 | import io.reactivex.functions.Action; 14 | import io.reactivex.schedulers.Schedulers; 15 | 16 | /** 17 | * Created by PR on 2017/8/7. 18 | */ 19 | 20 | public class DynamicEntityHandler extends Handler { 21 | 22 | 23 | public DynamicEntityHandler(ChatViewModel model, PlayerViewModel player, PermissionChecker checker, SemanticResult result) { 24 | super(model, player, checker, result); 25 | } 26 | 27 | @Override 28 | public String getFormatContent() { 29 | try { 30 | int ret = Integer.valueOf(result.data.getString("ret")); 31 | if(ret != 0){ 32 | return "动态实体数据上传失败"; 33 | }else { 34 | Completable 35 | .complete() 36 | .observeOn(Schedulers.io()) 37 | .delay(1000, TimeUnit.MILLISECONDS) 38 | .subscribe(new Action() { 39 | @Override 40 | public void run() throws Exception { 41 | mMessageViewModel.queryDynamicStatus(result.data.getString("sid")); 42 | } 43 | }); 44 | 45 | return result.answer; 46 | } 47 | } catch (JSONException e) { 48 | e.printStackTrace(); 49 | return "错误 " + e.getMessage(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/handler/Handler.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.handler; 2 | 3 | import com.iflytek.aiui.demo.chat.model.data.SemanticResult; 4 | import com.iflytek.aiui.demo.chat.ui.PermissionChecker; 5 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 6 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 7 | import com.zzhoujay.richtext.callback.OnUrlClickListener; 8 | import com.zzhoujay.richtext.callback.OnUrlLongClickListener; 9 | 10 | /** 11 | * Created by PR on 2017/8/4. 12 | */ 13 | 14 | public abstract class Handler implements OnUrlClickListener, OnUrlLongClickListener { 15 | public static final String NEWLINE = "
"; 16 | public static final String NEWLINE_NO_HTML = "\n"; 17 | public static final String CONTROL_TIP = "你可以通过语音控制暂停,播放,上一首,下一首哦"; 18 | public static int controlTipReqCount = 0; 19 | 20 | protected SemanticResult result; 21 | protected ChatViewModel mMessageViewModel; 22 | protected PlayerViewModel mPlayer; 23 | protected PermissionChecker mPermissionChecker; 24 | public Handler(ChatViewModel model, PlayerViewModel player, PermissionChecker checker, SemanticResult result){ 25 | this.mPlayer = player; 26 | this.mMessageViewModel = model; 27 | this.mPermissionChecker = checker; 28 | this.result = result; 29 | } 30 | 31 | public abstract String getFormatContent(); 32 | 33 | @Override 34 | public boolean urlClicked(String url) { 35 | return true; 36 | } 37 | 38 | @Override 39 | public boolean urlLongClick(String url) { 40 | return true; 41 | } 42 | 43 | public static boolean isNeedShowContrlTip() { 44 | return controlTipReqCount++ % 5 == 0; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/handler/HintHandler.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.handler; 2 | 3 | import android.text.TextUtils; 4 | 5 | import com.iflytek.aiui.demo.chat.model.data.SemanticResult; 6 | import com.iflytek.aiui.demo.chat.ui.PermissionChecker; 7 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 8 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 9 | 10 | /** 11 | * Created by PR on 2017/12/19. 12 | */ 13 | 14 | public class HintHandler extends Handler { 15 | 16 | private final StringBuilder defaultAnswer; 17 | 18 | public HintHandler(ChatViewModel model, PlayerViewModel player, PermissionChecker checker, SemanticResult result) { 19 | super(model, player, checker, result); 20 | defaultAnswer = new StringBuilder(); 21 | defaultAnswer.append("你好,我不懂你的意思"); 22 | defaultAnswer.append(Handler.NEWLINE_NO_HTML); 23 | defaultAnswer.append(Handler.NEWLINE_NO_HTML); 24 | defaultAnswer.append("在后台添加更多技能让我变得更强大吧 :D"); 25 | } 26 | 27 | 28 | // defaultAnswer.append(Handler.NEWLINE); 29 | // defaultAnswer.append(Handler.NEWLINE); 30 | // defaultAnswer.append("你也可以了解我的更多特性"); 31 | 32 | @Override 33 | public String getFormatContent() { 34 | if(TextUtils.isEmpty(result.answer)) { 35 | return defaultAnswer.toString(); 36 | } else { 37 | return result.answer; 38 | } 39 | } 40 | 41 | @Override 42 | public boolean urlClicked(String url) { 43 | if ("more".equals(url)) { 44 | StringBuilder more = new StringBuilder(); 45 | more.append("1. 用户个性化"); 46 | mMessageViewModel.fakeAIUIResult(0, "unknown", more.toString()); 47 | } else if ("individual".equals(url)) { 48 | StringBuilder more = new StringBuilder(); 49 | more.append("1. 电话"); 50 | more.append(NEWLINE); 51 | more.append("通过上传本地的联系人信息,可以让电话技能更准确地理解您的意思"); 52 | more.append(NEWLINE); 53 | more.append(NEWLINE); 54 | more.append("2. 点菜"); 55 | more.append(NEWLINE); 56 | more.append("通过点菜的技能,根据用户选择的不同分店的菜单,提供精准的识别和语义"); 57 | more.append(NEWLINE); 58 | more.append(NEWLINE); 59 | more.append("3. 菜谱"); 60 | more.append(NEWLINE); 61 | more.append("通过菜谱技能,根据信源结果预测下次用户交互的热词,提高识别和语义的精准度"); 62 | mMessageViewModel.fakeAIUIResult(0, "unknown", more.toString()); 63 | } else if ("telephone".equals(url)) { 64 | mMessageViewModel.sendText("打电话给妈妈"); 65 | } else if ("menu".equals(url)) { 66 | mMessageViewModel.sendText("我要点菜"); 67 | } else if ("dish".equals(url)) { 68 | mMessageViewModel.sendText("有哪些川菜"); 69 | } 70 | return super.urlClicked(url); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/handler/JokeHandler.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.handler; 2 | 3 | import com.iflytek.aiui.demo.chat.model.data.SemanticResult; 4 | import com.iflytek.aiui.demo.chat.repository.player.AIUIPlayer; 5 | import com.iflytek.aiui.demo.chat.ui.PermissionChecker; 6 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 7 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 8 | 9 | import org.json.JSONArray; 10 | import org.json.JSONObject; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by PR on 2017/12/21. 17 | */ 18 | 19 | public class JokeHandler extends Handler { 20 | public JokeHandler(ChatViewModel model, PlayerViewModel player, PermissionChecker checker, SemanticResult result) { 21 | super(model, player, checker, result); 22 | } 23 | 24 | @Override 25 | public String getFormatContent() { 26 | if(result.data != null) { 27 | List songList = new ArrayList<>(); 28 | JSONArray list = result.data.optJSONArray("result"); 29 | if(list != null){ 30 | for(int index = 0; index < list.length(); index++){ 31 | JSONObject item = list.optJSONObject(index); 32 | // 音频笑话 33 | if("1".equals(item.optString("type"))) { 34 | String audioPath = item.optString("mp3Url"); 35 | String songname = item.optString("title"); 36 | String author = item.optString("author"); 37 | 38 | songList.add(new AIUIPlayer.SongInfo(author, songname, audioPath)); 39 | } else { 40 | // 文本笑话(显示第一条结果) 41 | result.answer += NEWLINE_NO_HTML + NEWLINE_NO_HTML + item.optString("content"); 42 | break; 43 | } 44 | } 45 | } 46 | 47 | if(songList.size() != 0) { 48 | mPlayer.playList(songList); 49 | if(isNeedShowContrlTip()) { 50 | result.answer = result.answer + NEWLINE_NO_HTML + NEWLINE_NO_HTML + CONTROL_TIP; 51 | } 52 | } 53 | 54 | } 55 | return result.answer; 56 | 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/handler/NotificationHandler.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.handler; 2 | 3 | import com.iflytek.aiui.demo.chat.model.data.SemanticResult; 4 | import com.iflytek.aiui.demo.chat.ui.PermissionChecker; 5 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 6 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 7 | 8 | 9 | /** 10 | * Created by PR on 2018/3/22. 11 | */ 12 | 13 | public class NotificationHandler extends Handler { 14 | public NotificationHandler(ChatViewModel model, PlayerViewModel player, PermissionChecker checker, SemanticResult result) { 15 | super(model, player, checker, result); 16 | } 17 | 18 | @Override 19 | public String getFormatContent() { 20 | StringBuilder answer = new StringBuilder(result.answer); 21 | 22 | if(result.data.has("appid")) { 23 | answer.append(NEWLINE); 24 | answer.append(NEWLINE); 25 | answer.append("马上体验一下"); 26 | 27 | return answer.toString().replaceAll("\n", NEWLINE); 28 | } 29 | 30 | return answer.toString(); 31 | } 32 | 33 | @Override 34 | public boolean urlClicked(String url) { 35 | if("use".equals(url)) { 36 | //每次获取,getFormatContent只会调用一次 37 | String appid = result.data.optString("appid", ""); 38 | String key = result.data.optString("key", ""); 39 | String scene = result.data.optString("scene", "main"); 40 | 41 | mMessageViewModel.useNewAppID(appid, key, scene); 42 | mMessageViewModel.fakeAIUIResult(0, "notification", 43 | "已切换使用新的AppID,赶快开始体验吧\n\n若需要恢复,可在设置中重新配置"); 44 | return true; 45 | } else { 46 | return super.urlClicked(url); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/handler/PlayerHandler.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.handler; 2 | 3 | import com.iflytek.aiui.demo.chat.model.data.SemanticResult; 4 | import com.iflytek.aiui.demo.chat.repository.player.AIUIPlayer; 5 | import com.iflytek.aiui.demo.chat.ui.PermissionChecker; 6 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 7 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 8 | 9 | import org.json.JSONArray; 10 | import org.json.JSONObject; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by PR on 2017/12/21. 17 | */ 18 | 19 | public class PlayerHandler extends Handler { 20 | 21 | 22 | public PlayerHandler(ChatViewModel model, PlayerViewModel player, PermissionChecker checker, SemanticResult result) { 23 | super(model, player, checker, result); 24 | } 25 | 26 | @Override 27 | public String getFormatContent() { 28 | String intent = result.semantic.optString("intent"); 29 | if(intent.equals("INSTRUCTION")) { 30 | JSONArray slots = result.semantic.optJSONArray("slots"); 31 | for(int index=0;index < slots.length(); index++) { 32 | JSONObject slot = slots.optJSONObject(index); 33 | if("insType".equals(slot.optString("name"))){ 34 | String instruction = slot.optString("value"); 35 | if("next".equals(instruction)) { 36 | mPlayer.next(); 37 | } else if("past".equals(instruction)) { 38 | mPlayer.prev(); 39 | } else if("pause".equals(instruction)) { 40 | mPlayer.pause(); 41 | } else if("replay".equals(instruction)) { 42 | mPlayer.play(); 43 | } 44 | } 45 | } 46 | 47 | return "已完成操作"; 48 | } else { 49 | if(result.data != null) { 50 | List songList = new ArrayList<>(); 51 | JSONArray list = result.data.optJSONArray("result"); 52 | if(list != null){ 53 | for(int index = 0; index < list.length(); index++){ 54 | JSONObject audio = list.optJSONObject(index); 55 | String audioPath = audio.optString("audiopath"); 56 | String songname = audio.optString("songname"); 57 | String author = audio.optJSONArray("singernames").optString(0); 58 | 59 | songList.add(new AIUIPlayer.SongInfo(author, songname, audioPath)); 60 | } 61 | 62 | } 63 | 64 | if(songList.size() != 0) { 65 | mPlayer.playList(songList); 66 | if(isNeedShowContrlTip()) { 67 | result.answer = result.answer + NEWLINE_NO_HTML + NEWLINE_NO_HTML + CONTROL_TIP; 68 | } 69 | } 70 | } 71 | return result.answer; 72 | } 73 | 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/handler/RadioDisposer.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.handler; 2 | 3 | import com.iflytek.aiui.demo.chat.model.data.SemanticResult; 4 | import com.iflytek.aiui.demo.chat.repository.player.AIUIPlayer; 5 | import com.iflytek.aiui.demo.chat.ui.PermissionChecker; 6 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 7 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 8 | 9 | import org.json.JSONArray; 10 | import org.json.JSONObject; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by PR on 2017/12/21. 17 | */ 18 | 19 | public class RadioDisposer extends Handler { 20 | public RadioDisposer(ChatViewModel model, PlayerViewModel player, PermissionChecker checker, SemanticResult result) { 21 | super(model, player, checker, result); 22 | } 23 | 24 | @Override 25 | public String getFormatContent() { 26 | if(result.data != null) { 27 | List songList = new ArrayList<>(); 28 | JSONArray list = result.data.optJSONArray("result"); 29 | if(list != null){ 30 | for(int index = 0; index < list.length(); index++){ 31 | JSONObject item = list.optJSONObject(index); 32 | String audioPath = item.optString("url"); 33 | String songname = item.optString("name"); 34 | 35 | songList.add(new AIUIPlayer.SongInfo(songname, songname, audioPath)); 36 | } 37 | } 38 | 39 | if(songList.size() != 0) { 40 | mPlayer.playList(songList); 41 | if(isNeedShowContrlTip()) { 42 | result.answer = result.answer + NEWLINE_NO_HTML + NEWLINE_NO_HTML + CONTROL_TIP; 43 | } 44 | } 45 | 46 | } 47 | return result.answer; 48 | 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/handler/StoryHandler.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.handler; 2 | 3 | import com.iflytek.aiui.demo.chat.model.data.SemanticResult; 4 | import com.iflytek.aiui.demo.chat.repository.player.AIUIPlayer; 5 | import com.iflytek.aiui.demo.chat.ui.PermissionChecker; 6 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 7 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 8 | 9 | import org.json.JSONArray; 10 | import org.json.JSONObject; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by PR on 2017/12/21. 17 | */ 18 | 19 | public class StoryHandler extends Handler { 20 | 21 | public StoryHandler(ChatViewModel model, PlayerViewModel player, PermissionChecker checker, SemanticResult result) { 22 | super(model, player, checker, result); 23 | } 24 | 25 | @Override 26 | public String getFormatContent() { 27 | if(result.data != null) { 28 | List songList = new ArrayList<>(); 29 | JSONArray list = result.data.optJSONArray("result"); 30 | if(list != null){ 31 | for(int index = 0; index < list.length(); index++){ 32 | JSONObject audio = list.optJSONObject(index); 33 | String audioPath = audio.optString("playUrl"); 34 | String songname = audio.optString("name"); 35 | String author = audio.optString("author"); 36 | 37 | songList.add(new AIUIPlayer.SongInfo(author, songname, audioPath)); 38 | } 39 | 40 | } 41 | 42 | if(songList.size() != 0) { 43 | mPlayer.playList(songList); 44 | if(isNeedShowContrlTip()) { 45 | result.answer = result.answer + NEWLINE_NO_HTML + NEWLINE_NO_HTML + CONTROL_TIP; 46 | } 47 | } 48 | } 49 | return result.answer; 50 | 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/model/handler/WeatherHandler.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.model.handler; 2 | 3 | import android.Manifest; 4 | 5 | import com.iflytek.aiui.demo.chat.model.data.SemanticResult; 6 | import com.iflytek.aiui.demo.chat.ui.PermissionChecker; 7 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 8 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 9 | 10 | import org.json.JSONArray; 11 | import org.json.JSONObject; 12 | 13 | /** 14 | * Created by PR on 2018/1/30. 15 | */ 16 | 17 | public class WeatherHandler extends Handler { 18 | private static boolean notified = false; 19 | public WeatherHandler(ChatViewModel model, PlayerViewModel player, PermissionChecker checker, SemanticResult result) { 20 | super(model, player, checker, result); 21 | } 22 | 23 | @Override 24 | public String getFormatContent() { 25 | if(notified) { 26 | return result.answer; 27 | } else { 28 | StringBuilder answer = new StringBuilder(result.answer); 29 | JSONArray slots = result.semantic.optJSONArray("slots"); 30 | for(int index = 0; index < slots.length(); index++) { 31 | JSONObject item = slots.optJSONObject(index); 32 | if(item.optString("name").contains("location")){ 33 | if(item.optString("value").contains("CURRENT_CITY")) { 34 | answer.append(NEWLINE); 35 | answer.append(NEWLINE); 36 | answer.append("使用定位让天气信息更准确"); 37 | notified = true; 38 | break; 39 | } 40 | } 41 | } 42 | return answer.toString(); 43 | } 44 | } 45 | 46 | @Override 47 | public boolean urlClicked(String url) { 48 | if("use_loc".equals(url)){ 49 | mPermissionChecker.checkPermission(Manifest.permission.ACCESS_FINE_LOCATION, new Runnable() { 50 | @Override 51 | public void run() { 52 | mMessageViewModel.useLocationData(); 53 | } 54 | }, null); 55 | } 56 | 57 | return true; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/repository/LocationRepo.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.repository; 2 | 3 | import android.arch.lifecycle.LiveData; 4 | import android.content.Context; 5 | import com.iflytek.aiui.demo.chat.ui.common.SingleLiveEvent; 6 | import com.iflytek.location.LocationListener; 7 | import com.iflytek.location.PosLocator; 8 | import com.iflytek.location.result.GPSLocResult; 9 | import com.iflytek.location.result.LocResult; 10 | import com.iflytek.location.result.NetLocResult; 11 | 12 | import javax.inject.Inject; 13 | import javax.inject.Singleton; 14 | 15 | /** 16 | * Created by PR on 2018/1/30. 17 | */ 18 | 19 | @Singleton 20 | public class LocationRepo { 21 | private Context mContext; 22 | private SingleLiveEvent mNetLocData = new SingleLiveEvent<>(); 23 | private SingleLiveEvent mGPSLocData = new SingleLiveEvent<>(); 24 | 25 | @Inject 26 | public LocationRepo(Context context) { 27 | mContext = context; 28 | } 29 | 30 | public LiveData getNetLoc() { 31 | PosLocator.getInstance(mContext).asyncGetLocation(PosLocator.TYPE_NET_LOCATION, new LocationListener() { 32 | @Override 33 | public void onResult(LocResult locResult) { 34 | mNetLocData.postValue((NetLocResult) locResult); 35 | } 36 | }); 37 | 38 | return mNetLocData; 39 | } 40 | 41 | public LiveData getGPSLoc() { 42 | PosLocator.getInstance(mContext).asyncGetLocation(PosLocator.TYPE_GPS_LOCATION, new LocationListener() { 43 | @Override 44 | public void onResult(LocResult locResult) { 45 | mGPSLocData.postValue((GPSLocResult) locResult); 46 | } 47 | }); 48 | 49 | return mGPSLocData; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/repository/Storage.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.repository; 2 | 3 | import android.content.Context; 4 | 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | 8 | import javax.inject.Inject; 9 | import javax.inject.Singleton; 10 | 11 | /** 12 | * Created by PR on 2017/12/19. 13 | */ 14 | 15 | @Singleton 16 | public class Storage { 17 | private Context mContext; 18 | @Inject 19 | public Storage(Context context) { 20 | mContext = context; 21 | } 22 | 23 | public String readAssetFile(String filename){ 24 | try { 25 | StringBuilder result = new StringBuilder(); 26 | InputStream input = mContext.getAssets().open(filename); 27 | byte[] buffer = new byte[1024]; 28 | int read; 29 | while((read = input.read(buffer)) > 0){ 30 | result.append(new String(buffer, 0, read)); 31 | } 32 | 33 | return result.toString(); 34 | } catch (IOException e) { 35 | e.printStackTrace(); 36 | return null; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/repository/player/PlayState.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.repository.player; 2 | 3 | /** 4 | * Created by PR on 2018/2/1. 5 | */ 6 | public class PlayState { 7 | public PlayState(boolean active, boolean playing, String info) { 8 | this.active = active; 9 | this.playing = playing; 10 | this.info = info; 11 | } 12 | 13 | public boolean active; 14 | public boolean playing; 15 | public String info; 16 | } 17 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/PermissionChecker.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui; 2 | 3 | /** 4 | * Created by PR on 2018/1/4. 5 | */ 6 | 7 | public interface PermissionChecker { 8 | public void checkPermission(String permission, Runnable success, Runnable failed); 9 | } 10 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/ViewModelFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.iflytek.aiui.demo.chat.ui; 18 | 19 | import android.arch.lifecycle.ViewModel; 20 | import android.arch.lifecycle.ViewModelProvider; 21 | 22 | import java.util.Map; 23 | 24 | import javax.inject.Inject; 25 | import javax.inject.Provider; 26 | import javax.inject.Singleton; 27 | 28 | @Singleton 29 | public class ViewModelFactory implements ViewModelProvider.Factory { 30 | private final Map, Provider> creators; 31 | 32 | @Inject 33 | public ViewModelFactory(Map, Provider> creators) { 34 | this.creators = creators; 35 | } 36 | 37 | @SuppressWarnings("unchecked") 38 | @Override 39 | public T create(Class modelClass) { 40 | Provider creator = creators.get(modelClass); 41 | if (creator == null) { 42 | for (Map.Entry, Provider> entry : creators.entrySet()) { 43 | if (modelClass.isAssignableFrom(entry.getKey())) { 44 | creator = entry.getValue(); 45 | break; 46 | } 47 | } 48 | } 49 | if (creator == null) { 50 | throw new IllegalArgumentException("unknown model class " + modelClass); 51 | } 52 | try { 53 | return (T) creator.get(); 54 | } catch (Exception e) { 55 | throw new RuntimeException(e); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/about/AboutFragment.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui.about; 2 | 3 | import android.arch.lifecycle.Observer; 4 | import android.arch.lifecycle.ViewModelProvider; 5 | import android.arch.lifecycle.ViewModelProviders; 6 | import android.content.Context; 7 | import android.os.Bundle; 8 | import android.support.annotation.Nullable; 9 | import android.support.v4.app.Fragment; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.TextView; 14 | 15 | import com.iflytek.aiui.demo.chat.BuildConfig; 16 | import com.iflytek.aiui.demo.chat.R; 17 | 18 | import javax.inject.Inject; 19 | 20 | import dagger.android.support.AndroidSupportInjection; 21 | 22 | 23 | /** 24 | * 关于Fragment 25 | */ 26 | public class AboutFragment extends Fragment { 27 | 28 | @Inject 29 | ViewModelProvider.Factory mViewModelFactory; 30 | AboutViewModel mAboutModel; 31 | 32 | private TextView mUIDTxt; 33 | public AboutFragment() { 34 | 35 | } 36 | 37 | @Override 38 | public void onAttach(Context context) { 39 | super.onAttach(context); 40 | AndroidSupportInjection.inject(this); 41 | } 42 | 43 | 44 | @Override 45 | public void onCreate(Bundle savedInstanceState) { 46 | super.onCreate(savedInstanceState); 47 | } 48 | 49 | 50 | @Override 51 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 52 | Bundle savedInstanceState) { 53 | View view = inflater.inflate(R.layout.about_fragment, container, false); 54 | ((TextView) view.findViewById(R.id.versionCode)).setText("Version: " + BuildConfig.VERSION_NAME); 55 | mUIDTxt = (TextView) view.findViewById(R.id.uid); 56 | return view; 57 | } 58 | 59 | @Override 60 | public void onResume() { 61 | super.onResume(); 62 | } 63 | 64 | @Override 65 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 66 | super.onActivityCreated(savedInstanceState); 67 | mAboutModel = ViewModelProviders.of(getActivity(), mViewModelFactory).get(AboutViewModel.class); 68 | mAboutModel.getUID().observe(this, new Observer() { 69 | @Override 70 | public void onChanged(@Nullable String s) { 71 | mUIDTxt.setText("UID: " + s); 72 | } 73 | }); 74 | } 75 | 76 | @Override 77 | public void onDetach() { 78 | super.onDetach(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/about/AboutViewModel.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui.about; 2 | 3 | import android.arch.lifecycle.LiveData; 4 | import android.arch.lifecycle.ViewModel; 5 | 6 | import com.iflytek.aiui.demo.chat.repository.AIUIRepository; 7 | 8 | import javax.inject.Inject; 9 | 10 | /** 11 | * Created by PR on 2018/1/12. 12 | */ 13 | 14 | public class AboutViewModel extends ViewModel { 15 | private AIUIRepository mAIUI; 16 | 17 | @Inject 18 | public AboutViewModel(AIUIRepository aiuiRepository) { 19 | mAIUI = aiuiRepository; 20 | } 21 | 22 | public LiveData getUID() { 23 | return mAIUI.getUID(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/chat/DataBoundViewHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.iflytek.aiui.demo.chat.ui.chat; 18 | 19 | import android.databinding.ViewDataBinding; 20 | import android.support.v7.widget.RecyclerView; 21 | 22 | /** 23 | * A generic ViewHolder that works with a {@link ViewDataBinding}. 24 | * @param The type of the ViewDataBinding. 25 | */ 26 | public class DataBoundViewHolder extends RecyclerView.ViewHolder { 27 | public final T binding; 28 | DataBoundViewHolder(T binding) { 29 | super(binding.getRoot()); 30 | this.binding = binding; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/chat/ItemListener.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui.chat; 2 | 3 | import com.iflytek.aiui.demo.chat.databinding.ChatItemBinding; 4 | import com.iflytek.aiui.demo.chat.model.InteractMessage; 5 | 6 | /** 7 | * Created by PR on 2017/8/8. 8 | */ 9 | 10 | public interface ItemListener { 11 | public void onMessageClick(InteractMessage msg, ChatItemBinding binding); 12 | } 13 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/chat/MessageListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui.chat; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.text.Spannable; 5 | import android.view.LayoutInflater; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.iflytek.aiui.demo.chat.R; 11 | import com.iflytek.aiui.demo.chat.databinding.ChatItemBinding; 12 | import com.iflytek.aiui.demo.chat.model.InteractMessage; 13 | import com.zzhoujay.richtext.RichText; 14 | import com.zzhoujay.richtext.ext.LongClickableLinkMovementMethod; 15 | 16 | import java.util.Arrays; 17 | 18 | /** 19 | * Created by PR on 2017/7/31. 20 | */ 21 | 22 | public class MessageListAdapter extends DataBoundListAdapter 23 | implements ItemListener { 24 | private ChatFragment mFragment; 25 | public MessageListAdapter(ChatFragment fragment){ 26 | mFragment = fragment; 27 | } 28 | @Override 29 | protected ChatItemBinding createBinding(ViewGroup parent, int viewType) { 30 | return DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), 31 | R.layout.chat_item, parent, false); 32 | 33 | } 34 | 35 | @Override 36 | protected void bind(final ChatItemBinding binding, InteractMessage item) { 37 | binding.setMsg(item); 38 | binding.setBinding(binding); 39 | binding.setHandler(this); 40 | String content = item.getDisplayText(); 41 | if(content.contains("")){ 42 | RichText.from(content) 43 | .urlClick(item.getHandler()) 44 | .into(binding.chatItemContentText); 45 | binding.chatItemContentText.setOnTouchListener(new View.OnTouchListener() { 46 | @Override 47 | public boolean onTouch(View view, MotionEvent motionEvent) { 48 | return new LongClickableLinkMovementMethod() 49 | .onTouchEvent(binding.chatItemContentText, (Spannable) binding.chatItemContentText.getText(), motionEvent); 50 | } 51 | }); 52 | } else { 53 | binding.chatItemContentText.setText(item.getDisplayText()); 54 | } 55 | 56 | } 57 | 58 | @Override 59 | protected boolean areItemsTheSame(InteractMessage oldItem, InteractMessage newItem) { 60 | return oldItem.getMessage().timestamp == newItem.getMessage().timestamp; 61 | } 62 | 63 | @Override 64 | protected boolean areContentsTheSame(InteractMessage oldItem, InteractMessage newItem) { 65 | if(Arrays.equals(oldItem.getMessage().msgData, newItem.getMessage().msgData)) { 66 | String oldContent = oldItem.getMessage().cacheContent; 67 | String newContent = newItem.getMessage().cacheContent; 68 | return oldContent == null? newContent == null : oldContent.equals(newContent); 69 | } else { 70 | return false; 71 | } 72 | 73 | } 74 | 75 | @Override 76 | public void onMessageClick(InteractMessage msg, ChatItemBinding binding) { 77 | // if(msg.getMessage().msgType == Message.MsgType.Voice) { 78 | // AudioHandler.getsInstance().playAudioMessage(msg.getMessage()); 79 | // } 80 | 81 | if(!msg.getMessage().isFromUser()) { 82 | mFragment.switchToDetail(new String(msg.getMessage().msgData)); 83 | } 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/chat/PlayerViewModel.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui.chat; 2 | 3 | import android.arch.lifecycle.LiveData; 4 | import android.arch.lifecycle.ViewModel; 5 | 6 | import com.iflytek.aiui.demo.chat.repository.player.AIUIPlayer; 7 | import com.iflytek.aiui.demo.chat.repository.player.PlayState; 8 | 9 | import java.util.List; 10 | 11 | import javax.inject.Inject; 12 | 13 | /** 14 | * Created by PR on 2018/1/20. 15 | */ 16 | 17 | public class PlayerViewModel extends ViewModel { 18 | private AIUIPlayer mPlayer; 19 | 20 | @Inject 21 | public PlayerViewModel(AIUIPlayer player) { 22 | mPlayer = player; 23 | } 24 | 25 | public LiveData getPlayState() { return mPlayer.getLiveState(); } 26 | 27 | public void playList(List list) { mPlayer.playList(list); } 28 | 29 | public boolean play() { 30 | mPlayer.play(); 31 | return true; 32 | } 33 | 34 | public boolean pause() { 35 | mPlayer.pause(); 36 | return true; 37 | } 38 | 39 | public boolean prev() { 40 | mPlayer.prev(); 41 | return true; 42 | } 43 | 44 | public boolean next() { 45 | mPlayer.next(); 46 | return true; 47 | } 48 | 49 | public boolean stop() { 50 | mPlayer.stop(); 51 | return true; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/chat/ScrollSpeedLinearLayoutManger.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui.chat; 2 | 3 | import android.content.Context; 4 | import android.graphics.PointF; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.LinearSmoothScroller; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.DisplayMetrics; 9 | 10 | public class ScrollSpeedLinearLayoutManger extends LinearLayoutManager { 11 | private float MILLISECONDS_PER_INCH = 0.03f; 12 | private Context contxt; 13 | 14 | public ScrollSpeedLinearLayoutManger(Context context) { 15 | super(context); 16 | this.contxt = context; 17 | } 18 | 19 | @Override 20 | public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { 21 | LinearSmoothScroller linearSmoothScroller = 22 | new LinearSmoothScroller(recyclerView.getContext()) { 23 | @Override 24 | public PointF computeScrollVectorForPosition(int targetPosition) { 25 | return ScrollSpeedLinearLayoutManger.this 26 | .computeScrollVectorForPosition(targetPosition); 27 | } 28 | 29 | //This returns the milliseconds it takes to 30 | //scroll one pixel. 31 | @Override 32 | protected float calculateSpeedPerPixel 33 | (DisplayMetrics displayMetrics) { 34 | return MILLISECONDS_PER_INCH / displayMetrics.density; 35 | //返回滑动一个pixel需要多少毫秒 36 | } 37 | 38 | }; 39 | linearSmoothScroller.setTargetPosition(position); 40 | startSmoothScroll(linearSmoothScroller); 41 | } 42 | 43 | 44 | public void setSpeedSlow() { 45 | //自己在这里用density去乘,希望不同分辨率设备上滑动速度相同 46 | //0.3f是自己估摸的一个值,可以根据不同需求自己修改 47 | MILLISECONDS_PER_INCH = contxt.getResources().getDisplayMetrics().density * 0.3f; 48 | } 49 | 50 | public void setSpeedFast() { 51 | MILLISECONDS_PER_INCH = contxt.getResources().getDisplayMetrics().density * 0.03f; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/common/SingleLiveEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.iflytek.aiui.demo.chat.ui.common; 18 | 19 | import android.arch.lifecycle.LifecycleOwner; 20 | import android.arch.lifecycle.MutableLiveData; 21 | import android.arch.lifecycle.Observer; 22 | import android.support.annotation.MainThread; 23 | import android.support.annotation.Nullable; 24 | import android.util.Log; 25 | 26 | import java.util.concurrent.atomic.AtomicBoolean; 27 | 28 | /** 29 | * A lifecycle-aware observable that sends only new updates after subscription, used for events like 30 | * navigation and Snackbar messages. 31 | *

32 | * This avoids a common problem with events: on configuration change (like rotation) an update 33 | * can be emitted if the observer is active. This LiveData only calls the observable if there's an 34 | * explicit call to setValue() or call(). 35 | *

36 | * Note that only one observer is going to be notified of changes. 37 | */ 38 | public class SingleLiveEvent extends MutableLiveData { 39 | 40 | private static final String TAG = "SingleLiveEvent"; 41 | 42 | private final AtomicBoolean mPending = new AtomicBoolean(false); 43 | 44 | @MainThread 45 | public void observe(LifecycleOwner owner, final Observer observer) { 46 | 47 | if (hasActiveObservers()) { 48 | Log.w(TAG, "Multiple observers registered but only one will be notified of changes."); 49 | } 50 | 51 | // Observe the internal MutableLiveData 52 | super.observe(owner, new Observer() { 53 | @Override 54 | public void onChanged(@Nullable T t) { 55 | if (mPending.compareAndSet(true, false)) { 56 | observer.onChanged(t); 57 | } 58 | } 59 | }); 60 | } 61 | 62 | @MainThread 63 | public void setValue(@Nullable T t) { 64 | mPending.set(true); 65 | super.setValue(t); 66 | } 67 | 68 | /** 69 | * Used for cases where T is Void, to make calls cleaner. 70 | */ 71 | @MainThread 72 | public void call() { 73 | setValue(null); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/common/widget/PopupWindowFactory.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui.common.widget; 2 | 3 | import android.content.Context; 4 | import android.view.KeyEvent; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.PopupWindow; 8 | 9 | 10 | /** 11 | * 作者:Rance on 2016/11/29 10:47 12 | * 邮箱:rance935@163.com 13 | */ 14 | public class PopupWindowFactory { 15 | 16 | private Context mContext; 17 | 18 | private PopupWindow mPop; 19 | 20 | /** 21 | * @param mContext 上下文 22 | * @param view PopupWindow显示的布局文件 23 | */ 24 | public PopupWindowFactory(Context mContext, View view){ 25 | this(mContext,view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 26 | } 27 | 28 | /** 29 | * @param mContext 上下文 30 | * @param view PopupWindow显示的布局文件 31 | * @param width PopupWindow的宽 32 | * @param heigth PopupWindow的高 33 | */ 34 | public PopupWindowFactory(Context mContext, View view, int width, int heigth){ 35 | init(mContext,view,width,heigth); 36 | } 37 | 38 | 39 | private void init(Context mContext, View view, int width, int heigth){ 40 | this.mContext = mContext; 41 | 42 | //下面这两个必须有!! 43 | view.setFocusable(true); 44 | view.setFocusableInTouchMode(true); 45 | 46 | // PopupWindow(布局,宽度,高度) 47 | mPop = new PopupWindow(view,width,heigth,true); 48 | mPop.setOutsideTouchable(false); 49 | mPop.setFocusable(true); 50 | 51 | // 重写onKeyListener,按返回键消失 52 | view.setOnKeyListener(new View.OnKeyListener() { 53 | @Override 54 | public boolean onKey(View v, int keyCode, KeyEvent event) { 55 | if (keyCode == KeyEvent.KEYCODE_BACK) { 56 | mPop.dismiss(); 57 | return true; 58 | } 59 | return false; 60 | } 61 | }); 62 | 63 | //点击其他地方消失 64 | // view.setOnTouchListener(new View.OnTouchListener() { 65 | // @Override 66 | // public boolean onTouch(View v, MotionEvent event) { 67 | // if (mPop != null && mPop.isShowing()) { 68 | // mPop.dismiss(); 69 | // return true; 70 | // } 71 | // return false; 72 | // }}); 73 | 74 | 75 | } 76 | 77 | public PopupWindow getPopupWindow(){ 78 | return mPop; 79 | } 80 | 81 | 82 | /** 83 | * 以触发弹出窗的view为基准,出现在view的内部上面,弹出的pop_view左上角正对view的左上角 84 | * @param parent view 85 | * @param gravity 在view的什么位置 Gravity.CENTER、Gravity.TOP...... 86 | * @param x 与控件的x坐标距离 87 | * @param y 与控件的y坐标距离 88 | */ 89 | public void showAtLocation(View parent, int gravity, int x, int y){ 90 | 91 | if(mPop.isShowing()){ 92 | return ; 93 | } 94 | mPop.showAtLocation(parent, gravity, x, y); 95 | 96 | } 97 | 98 | /** 99 | * 以触发弹出窗的view为基准,出现在view的正下方,弹出的pop_view左上角正对view的左下角 100 | * @param anchor view 101 | */ 102 | public void showAsDropDown(View anchor){ 103 | showAsDropDown(anchor,0,0); 104 | } 105 | 106 | /** 107 | * 以触发弹出窗的view为基准,出现在view的正下方,弹出的pop_view左上角正对view的左下角 108 | * @param anchor view 109 | * @param xoff 与view的x坐标距离 110 | * @param yoff 与view的y坐标距离 111 | */ 112 | public void showAsDropDown(View anchor, int xoff, int yoff){ 113 | if(mPop.isShowing()){ 114 | return ; 115 | } 116 | 117 | mPop.showAsDropDown(anchor, xoff, yoff); 118 | } 119 | 120 | /** 121 | * 隐藏PopupWindow 122 | */ 123 | public void dismiss(){ 124 | if (mPop.isShowing()) { 125 | mPop.dismiss(); 126 | } 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/detail/DetailFragment.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui.detail; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.iflytek.aiui.demo.chat.R; 10 | import com.pddstudio.highlightjs.HighlightJsView; 11 | import com.pddstudio.highlightjs.models.Language; 12 | import com.pddstudio.highlightjs.models.Theme; 13 | 14 | import org.json.JSONException; 15 | import org.json.JSONObject; 16 | 17 | /** 18 | * 关于Fragment 19 | */ 20 | public class DetailFragment extends Fragment { 21 | private static final String DETAIL_KEY = "detail"; 22 | 23 | public static DetailFragment createDetailFragment(String content) { 24 | DetailFragment fragment = new DetailFragment(); 25 | Bundle arguments = new Bundle(); 26 | arguments.putString(DETAIL_KEY, content); 27 | fragment.setArguments(arguments); 28 | 29 | return fragment; 30 | } 31 | 32 | protected HighlightJsView mDetailView; 33 | @Override 34 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 35 | Bundle savedInstanceState) { 36 | View mMainView = inflater.inflate(R.layout.detail_fragment, container, false); 37 | String content = getArguments().getString(DETAIL_KEY); 38 | mDetailView = (HighlightJsView) mMainView.findViewById(R.id.detail_js_view); 39 | mDetailView.setHighlightLanguage(Language.JSON); 40 | mDetailView.setTheme(Theme.ARDUINO_LIGHT); 41 | try { 42 | mDetailView.setSource(new JSONObject(content).toString(2)); 43 | } catch (JSONException e) { 44 | mDetailView.setSource(content); 45 | } 46 | return mMainView; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/settings/SettingViewModel.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui.settings; 2 | 3 | import android.arch.lifecycle.LiveData; 4 | import android.arch.lifecycle.ViewModel; 5 | 6 | import com.iflytek.aiui.demo.chat.repository.SettingsRepo; 7 | 8 | import javax.inject.Inject; 9 | 10 | /** 11 | * Created by PR on 2017/12/14. 12 | */ 13 | 14 | public class SettingViewModel extends ViewModel { 15 | private SettingsRepo mSettingsRepo; 16 | @Inject 17 | public SettingViewModel(SettingsRepo settingsRepo) { 18 | mSettingsRepo = settingsRepo; 19 | } 20 | 21 | public void syncLastSetting() { 22 | mSettingsRepo.updateSettings(); 23 | } 24 | 25 | public LiveData isWakeUpAvailable() { 26 | return mSettingsRepo.getWakeUpEnableState(); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/settings/SettingsFragment.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui.settings; 2 | 3 | import android.arch.lifecycle.Observer; 4 | import android.arch.lifecycle.ViewModelProvider; 5 | import android.arch.lifecycle.ViewModelProviders; 6 | import android.content.Context; 7 | import android.content.SharedPreferences; 8 | import android.os.Bundle; 9 | import android.support.annotation.Nullable; 10 | import android.support.design.widget.Snackbar; 11 | import android.support.v7.preference.EditTextPreference; 12 | import android.support.v7.preference.PreferenceFragmentCompat; 13 | import android.support.v7.preference.SwitchPreferenceCompat; 14 | 15 | import com.iflytek.aiui.demo.chat.R; 16 | 17 | import javax.inject.Inject; 18 | 19 | import dagger.android.support.AndroidSupportInjection; 20 | 21 | /** 22 | * Created by PR on 2017/12/12. 23 | */ 24 | 25 | public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { 26 | public static final String AIUI_EOS = "aiui_eos"; 27 | public static final String AIUI_WAKEUP = "aiui_wakeup"; 28 | @Inject 29 | ViewModelProvider.Factory mViewModelFactory; 30 | private SettingViewModel mSettingModel; 31 | private EditTextPreference eosPreference; 32 | private SwitchPreferenceCompat wakeupPreference; 33 | 34 | @Override 35 | public void onAttach(Context context) { 36 | super.onAttach(context); 37 | AndroidSupportInjection.inject(this); 38 | } 39 | 40 | @Override 41 | public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 42 | addPreferencesFromResource(R.xml.pref_settings); 43 | eosPreference = (EditTextPreference) (getPreferenceManager().findPreference(AIUI_EOS)); 44 | eosPreference.setSummary(String.format("%sms", getPreferenceManager().getSharedPreferences().getString(AIUI_EOS, "1000"))); 45 | wakeupPreference = (SwitchPreferenceCompat) getPreferenceManager().findPreference(AIUI_WAKEUP); 46 | } 47 | 48 | @Override 49 | public void onActivityCreated(Bundle savedInstanceState) { 50 | super.onActivityCreated(savedInstanceState); 51 | mSettingModel = ViewModelProviders.of(this, mViewModelFactory).get(SettingViewModel.class); 52 | 53 | mSettingModel.isWakeUpAvailable().observe(this, new Observer() { 54 | @Override 55 | public void onChanged(@Nullable Boolean enable) { 56 | wakeupPreference.setEnabled(enable); 57 | } 58 | }); 59 | } 60 | 61 | @Override 62 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { 63 | if(AIUI_EOS.equals(s)){ 64 | String eos = sharedPreferences.getString(s, "1000"); 65 | if(!isNumeric(eos)) { 66 | eosPreference.setText("1000"); 67 | Snackbar.make(getView(), R.string.eos_invalid_tip , Snackbar.LENGTH_LONG).show(); 68 | } else { 69 | eosPreference.setSummary(String.format("%sms", eos)); 70 | } 71 | } 72 | } 73 | 74 | 75 | private boolean isNumeric(String str) { 76 | try { 77 | Integer.valueOf(str); 78 | return true; 79 | } catch (Exception e) { 80 | return false; 81 | } 82 | } 83 | 84 | 85 | 86 | @Override 87 | public void onResume() { 88 | super.onResume(); 89 | getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); 90 | } 91 | 92 | @Override 93 | public void onPause() { 94 | super.onPause(); 95 | getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); 96 | } 97 | 98 | @Override 99 | public void onStop() { 100 | super.onStop(); 101 | 102 | mSettingModel.syncLastSetting(); 103 | } 104 | 105 | 106 | } 107 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/java/com/iflytek/aiui/demo/chat/ui/view/ChatBubbleLayout.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.ui.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import com.daasuu.bl.ArrowDirection; 7 | import com.daasuu.bl.BubbleLayout; 8 | 9 | /** 10 | * Created by pangxiezhou on 2018/1/6. 11 | */ 12 | 13 | public class ChatBubbleLayout extends BubbleLayout { 14 | public ChatBubbleLayout(Context context) { 15 | super(context); 16 | } 17 | 18 | public ChatBubbleLayout(Context context, AttributeSet attrs) { 19 | super(context, attrs); 20 | } 21 | 22 | public ChatBubbleLayout(Context context, AttributeSet attrs, int defStyleAttr) { 23 | super(context, attrs, defStyleAttr); 24 | } 25 | 26 | public void setChatBubbleColor(int color){ 27 | setBubbleColor(color); 28 | } 29 | 30 | public void setChatArrowDirection(ArrowDirection direction) { 31 | setArrowDirection(direction); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/jniLibs/armeabi/libaiui.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/jniLibs/armeabi/libaiui.so -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/anim/anim_wave.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 15 | 20 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/anim/slide_left_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/anim/slide_left_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/anim/slide_right_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/anim/slide_right_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable-v21/ic_menu_manage.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable-xhdpi/icon_chat_voice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/drawable-xhdpi/icon_chat_voice.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable-xhdpi/icon_keyboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/drawable-xhdpi/icon_keyboard.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable-xhdpi/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/drawable-xhdpi/logo.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable-xxhdpi/aiui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/drawable-xxhdpi/aiui.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable-xxhdpi/insight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/drawable-xxhdpi/insight.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable-xxhdpi/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/drawable-xxhdpi/user.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/corners_edit.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/corners_edit_white.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/ic_feedback_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/ic_info_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/ic_pause_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/ic_play_arrow_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/ic_report_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/ic_settings_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/ic_skip_next_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/ic_skip_previous_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/record_microphone.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/record_microphone_bj.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 11 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/send_btn_back.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/drawable/side_nav_bar.xml: -------------------------------------------------------------------------------- 1 | 3 | 9 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/layout/about_fragment.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 23 | 24 | 36 | 37 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 19 | 20 | 26 | 27 | 28 | 33 | 34 | 35 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/layout/appid_key_preference.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 22 | 23 | 24 | 25 | 28 | 29 | 37 | 38 | 39 | 40 | 43 | 44 | 52 | 53 | 54 | 55 | 61 | 62 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/layout/detail_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/layout/layout_microphone.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 20 | 21 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/layout/nav_header_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 24 | 25 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/menu/drawer.xml: -------------------------------------------------------------------------------- 1 | 2 |

3 | 4 | 5 | 9 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_chat_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_chat_add.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_chat_expression.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_chat_expression.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_chat_photo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_chat_photo.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_chat_photograph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_chat_photograph.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_chat_voice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_chat_voice.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_keyboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_keyboard.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_left1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_left1.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_left2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_left2.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_left3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_left3.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_right1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_right1.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_right2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_right2.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_right3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/icon_voice_right3.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/record_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/record_bottom.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/mipmap-xhdpi/record_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/app/src/main/res/mipmap-xhdpi/record_top.png -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/values-zh-rCN/values-zh-rCN.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | AIUI 4 | 5 | Open navigation drawer 6 | Close navigation drawer 7 | 快说\"小飞小飞\"唤醒我吧 8 | 9 | 按住说话 10 | 松开结束 11 | 12 | 反馈 13 | 设置 14 | 关于 15 | 16 | 交互 17 | 唤醒 18 | 通过唤醒+命令进行交互 19 | 前端点 20 | 语音后端点时间 21 | 后端点有效值应为数字 22 | 23 | 调试 24 | 输出调试日志 25 | 在Logcat中打印运行日志 26 | 保存交互音频 27 | 在SD卡中保存交互的音频与结果日志 28 | 高级 29 | AppID设置 30 | 使用新的AppID和Key 31 | AppID 32 | Key 33 | 清空AppID及Key可恢复默认 34 | Scene 35 | 36 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | #000000 5 | #9E9E9E 6 | 7 | #FFFFFF 8 | #000000 9 | #69d3fe 10 | #FFFFFF 11 | #818181 12 | #1990ff 13 | 14 | 15 | 16 | #f5f5f5 17 | #d9d9d9 18 | 19 | 20 | #1b1b1b 21 | #3084a7 22 | #455A64 23 | #818181 24 | #919191 25 | #c7c7c7 26 | #404040 27 | #F000 28 | 29 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 16dp 6 | 160dp 7 | 16dp 8 | 9 | 10dp 10 | 10dp 11 | 64dp 12 | 6dp 13 | 1dp 14 | 5dp 15 | 10dp 16 | 40dp 17 | 18 | 19sp 19 | 17sp 20 | 15sp 21 | 13sp 22 | 1dp 23 | 6dp 24 | 25 | 8dp 26 | 27 | 28 | 29 | 2dp 30 | 4dp 31 | 8dp 32 | 16dp 33 | 32dp 34 | 35 | 36 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/values/drawables.xml: -------------------------------------------------------------------------------- 1 | 2 | @android:drawable/ic_menu_camera 3 | @android:drawable/ic_menu_gallery 4 | @android:drawable/ic_menu_slideshow 5 | @android:drawable/ic_menu_manage 6 | @android:drawable/ic_menu_share 7 | @android:drawable/ic_menu_send 8 | @android:drawable/ic_menu_info_details 9 | 10 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 200 3 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AIUI 3 | 4 | Open navigation drawer 5 | Close navigation drawer 6 | 快说\"小飞小飞\"唤醒我吧 7 | 8 | 按住说话 9 | 松开结束 10 | 11 | 反馈 12 | 设置 13 | 关于 14 | 15 | 交互 16 | 唤醒 17 | 通过唤醒+命令进行交互 18 | 前端点 19 | 语音后端点时间 20 | 后端点有效值应为数字 21 | 22 | 调试 23 | 输出调试日志 24 | 在Logcat中打印运行日志 25 | 保存交互音频 26 | 在SD卡中保存交互的音频与结果日志 27 | 高级 28 | AppID设置 29 | 使用新的AppID和Key 30 | AppID 31 | Key 32 | 清空AppID及Key可恢复默认 33 | Scene 34 | 35 | 36 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 17 | 18 | 24 | 25 | 27 | 28 | 31 | 32 | 38 | 39 | 45 | 46 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/xml/filepaths.xml: -------------------------------------------------------------------------------- 1 | 22 | 23 | 25 | 28 | 29 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/main/res/xml/pref_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 12 | 13 | 19 | 20 | 21 | 23 | 24 | 29 | 30 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/sample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/sample/java/com/iflytek/aiui/demo/chat/di/AppComponent.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.di; 2 | 3 | import android.app.Application; 4 | 5 | import com.iflytek.aiui.demo.chat.ChatApp; 6 | 7 | import javax.inject.Singleton; 8 | 9 | import dagger.BindsInstance; 10 | import dagger.Component; 11 | import dagger.android.AndroidInjectionModule; 12 | 13 | /** 14 | * Created by PR on 2017/11/6. 15 | */ 16 | 17 | @Singleton 18 | @Component(modules = { 19 | AndroidInjectionModule.class, 20 | AppModule.class, 21 | ChatActivityModule.class 22 | }) 23 | 24 | public interface AppComponent { 25 | @Component.Builder 26 | interface Builder { 27 | @BindsInstance 28 | Builder application(Application application); 29 | AppComponent build(); 30 | } 31 | void inject(ChatApp application); 32 | } 33 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/sample/java/com/iflytek/aiui/demo/chat/di/FragmentBuildersModule.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.di; 2 | 3 | import com.iflytek.aiui.demo.chat.ui.about.AboutFragment; 4 | import com.iflytek.aiui.demo.chat.ui.chat.ChatFragment; 5 | import com.iflytek.aiui.demo.chat.ui.detail.DetailFragment; 6 | import com.iflytek.aiui.demo.chat.ui.settings.SettingsFragment; 7 | 8 | import dagger.Module; 9 | import dagger.android.ContributesAndroidInjector; 10 | 11 | /** 12 | * Created by PR on 2018/1/22. 13 | */ 14 | 15 | @Module 16 | public abstract class FragmentBuildersModule { 17 | @ContributesAndroidInjector 18 | abstract ChatFragment contributesChatFragment( ); 19 | 20 | @ContributesAndroidInjector 21 | abstract DetailFragment contributeDetailFragment( ); 22 | 23 | @ContributesAndroidInjector 24 | abstract AboutFragment contributeAboutFragment(); 25 | 26 | @ContributesAndroidInjector 27 | abstract SettingsFragment contributeSettingFragment( ); 28 | } 29 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/sample/java/com/iflytek/aiui/demo/chat/di/ViewModelModule.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.di; 2 | 3 | import android.arch.lifecycle.ViewModel; 4 | import android.arch.lifecycle.ViewModelProvider; 5 | 6 | import com.iflytek.aiui.demo.chat.ui.about.AboutViewModel; 7 | import com.iflytek.aiui.demo.chat.ui.chat.ChatViewModel; 8 | import com.iflytek.aiui.demo.chat.ui.chat.PlayerViewModel; 9 | import com.iflytek.aiui.demo.chat.ui.settings.SettingViewModel; 10 | import com.iflytek.aiui.demo.chat.ui.ViewModelFactory; 11 | 12 | import dagger.Binds; 13 | import dagger.Module; 14 | import dagger.multibindings.IntoMap; 15 | 16 | @Module 17 | public abstract class ViewModelModule { 18 | @Binds 19 | @IntoMap 20 | @ViewModelKey(ChatViewModel.class) 21 | abstract ViewModel buildChatViewModel(ChatViewModel messagesViewModel); 22 | 23 | @Binds 24 | @IntoMap 25 | @ViewModelKey(PlayerViewModel.class) 26 | abstract ViewModel buildPlayerViewModel(PlayerViewModel playerViewModel); 27 | 28 | @Binds 29 | @IntoMap 30 | @ViewModelKey(SettingViewModel.class) 31 | abstract ViewModel buildSettingsViewModel(SettingViewModel settingViewModel); 32 | 33 | @Binds 34 | @IntoMap 35 | @ViewModelKey(AboutViewModel.class) 36 | abstract ViewModel buildAboutViewModel(AboutViewModel aboutViewModel); 37 | 38 | @Binds 39 | abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory); 40 | } 41 | -------------------------------------------------------------------------------- /AIUIChatDemo/app/src/sample/java/com/iflytek/aiui/demo/chat/util/FucUtil.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.demo.chat.util; 2 | 3 | import android.content.Context; 4 | 5 | 6 | 7 | import java.io.InputStream; 8 | 9 | /** 10 | * 功能性函数扩展类 11 | */ 12 | public class FucUtil { 13 | /** 14 | * 读取asset目录下文件。 15 | * @return content 16 | */ 17 | public static String readFile(Context mContext, String file, String code) 18 | { 19 | int len = 0; 20 | byte []buf = null; 21 | String result = ""; 22 | try { 23 | InputStream in = mContext.getAssets().open(file); 24 | len = in.available(); 25 | buf = new byte[len]; 26 | in.read(buf, 0, len); 27 | 28 | result = new String(buf,code); 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | return result; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /AIUIChatDemo/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.0.1' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | maven { url 'https://dl.google.com/dl/android/maven2/' } 20 | maven { 21 | url 'http://maven.aliyun.com/nexus/content/repositories/releases/' 22 | } 23 | maven { url 'https://jitpack.io' } 24 | } 25 | } 26 | 27 | task prepareSample { 28 | doLast { 29 | copy { 30 | from project.projectDir 31 | into 'output/sample' 32 | 33 | // 忽略签名文件 34 | exclude 'iflytekSigneKey' 35 | exclude 'local.properties' 36 | exclude 'gradle.properties' 37 | //去除full的配置 38 | exclude '**/full.gradle' 39 | exclude '**/full/' 40 | exclude '**/smtp_mail_library/' 41 | // 忽略AIUI生成目录 42 | exclude '**/output/' 43 | // 忽略gradle生成目录 44 | exclude '**/*.apk', '**/*.ap_', '**/*.dex', '**/*.class' 45 | exclude '**/bin/', '**/gen/', '**/out/', '**/build/', '**/proguard/' 46 | exclude '**/*.iml', '**/.gradle/', '**/.idea/', '**/.externalNativeBuild/', '**/.navigation/' 47 | } 48 | 49 | File settingsFile = file('output/sample/settings.gradle') 50 | settingsFile.text = "include ':app'" 51 | 52 | File sampleBuildFile = file('output/sample/app/build.gradle') 53 | sampleBuildFile.text = sampleBuildFile.text.replace("apply from: 'full.gradle'", "") 54 | 55 | File config = file('output/sample/app/src/main/assets/cfg/aiui_phone.cfg') 56 | String configContent = config.text 57 | configContent = configContent.replace('56ac196f', 'XXXXXXXX') 58 | configContent = configContent.replace('nlp31', 'main') 59 | configContent = configContent.replace('"dwa": "wpgs"', '') 60 | config.write(configContent, 'utf-8') 61 | 62 | } 63 | } 64 | 65 | task clean(type: Delete) { 66 | delete rootProject.buildDir 67 | } 68 | -------------------------------------------------------------------------------- /AIUIChatDemo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /AIUIChatDemo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jan 04 11:06:15 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /AIUIChatDemo/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /AIUIChatDemo/screenshots/call_upload.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/screenshots/call_upload.jpg -------------------------------------------------------------------------------- /AIUIChatDemo/screenshots/call_use.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/screenshots/call_use.jpg -------------------------------------------------------------------------------- /AIUIChatDemo/screenshots/menu_item.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/screenshots/menu_item.png -------------------------------------------------------------------------------- /AIUIChatDemo/screenshots/menu_skill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/screenshots/menu_skill.png -------------------------------------------------------------------------------- /AIUIChatDemo/screenshots/menu_upload.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/screenshots/menu_upload.jpg -------------------------------------------------------------------------------- /AIUIChatDemo/screenshots/menu_use.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/AIUIChatDemo/screenshots/menu_use.jpg -------------------------------------------------------------------------------- /AIUIChatDemo/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DemoCode 2 | AIUI demo code 3 | 4 | 国内用户可从 https://gitee.com/xiaosumay/DemoCode 镜像处下载 5 | -------------------------------------------------------------------------------- /aiui/c-sharp/.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | *.cache -------------------------------------------------------------------------------- /aiui/c-sharp/README.txt: -------------------------------------------------------------------------------- 1 | 1. 将平台下载的 aiui 库(aiui.dll)放在 aiui_csharp_demo 目录下,建议x64,且重新命名为 2 | 2. 修改 AIUI/cfg/aiui.cfg 下的 appid 和 key 3 | 3. 将 【调试】 -> 【aiui_csharp_demo 属性】 -> 【调试】 -> 【工作目录】 设置为 ..\..\.. 4 | 4. 即可运行调试 -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "aiui_csharp_demo", "aiui_csharp_demo\aiui_csharp_demo.csproj", "{878279F9-9616-4547-A589-D1C993086DF8}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|x64 = Debug|x64 12 | Debug|x86 = Debug|x86 13 | Release|Any CPU = Release|Any CPU 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {878279F9-9616-4547-A589-D1C993086DF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {878279F9-9616-4547-A589-D1C993086DF8}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {878279F9-9616-4547-A589-D1C993086DF8}.Debug|x64.ActiveCfg = Debug|x64 21 | {878279F9-9616-4547-A589-D1C993086DF8}.Debug|x64.Build.0 = Debug|x64 22 | {878279F9-9616-4547-A589-D1C993086DF8}.Debug|x86.ActiveCfg = Debug|x86 23 | {878279F9-9616-4547-A589-D1C993086DF8}.Debug|x86.Build.0 = Debug|x86 24 | {878279F9-9616-4547-A589-D1C993086DF8}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {878279F9-9616-4547-A589-D1C993086DF8}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {878279F9-9616-4547-A589-D1C993086DF8}.Release|x64.ActiveCfg = Release|x64 27 | {878279F9-9616-4547-A589-D1C993086DF8}.Release|x64.Build.0 = Release|x64 28 | {878279F9-9616-4547-A589-D1C993086DF8}.Release|x86.ActiveCfg = Release|x86 29 | {878279F9-9616-4547-A589-D1C993086DF8}.Release|x86.Build.0 = Release|x86 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {8A116986-897B-4D3D-9E14-F424818D5450} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/.gitignore: -------------------------------------------------------------------------------- 1 | /*.user 2 | /obj 3 | /bin 4 | aiui.dll 5 | *.suo -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/AIUI/audio/test.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/aiui_csharp_demo/AIUI/audio/test.pcm -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/AIUI/cfg/aiui.cfg: -------------------------------------------------------------------------------- 1 | /* AIUI参数配置 */ 2 | { 3 | /* 交互参数 */ 4 | "interact": { 5 | "interact_timeout": "-1", 6 | "result_timeout": "5000" 7 | }, 8 | 9 | /* 全局设置 */ 10 | "global": { 11 | "scene": "main_box" 12 | }, 13 | 14 | "login": { 15 | "appid": "xxxxxxx", 16 | "key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 17 | }, 18 | 19 | /* 业务相关参数 */ 20 | // 本地vad参数 21 | "vad": { 22 | "engine_type": "meta" 23 | }, 24 | 25 | /* 业务流程相关参数 */ 26 | // 语音业务流程 27 | "speech": { 28 | "data_source": "sdk", 29 | "wakeup_mode": "off", 30 | "interact_mode": "continuous", // continuous 31 | "intent_engine_type": "cloud", 32 | "audio_captor": "system" 33 | }, 34 | 35 | /* 日志设置 */ 36 | "log": { 37 | "debug_log": "0", 38 | "save_datalog": "0", 39 | "datalog_path": "", 40 | "datalog_size": 1024, 41 | "raw_audio_path": "" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/IAIUIAgent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace aiui 5 | { 6 | class IAIUIAgent 7 | { 8 | public delegate void AIUIMessageCallback(IAIUIEvent ev); 9 | 10 | private IntPtr mAgent = IntPtr.Zero; 11 | 12 | private AIUIMessageCallback messageCallback = null; 13 | private AIUIMessageCallback_ onEvent_ = null; 14 | 15 | private void OnEvent(IntPtr ev_, IntPtr data) 16 | { 17 | IAIUIEvent ev = new IAIUIEvent(ev_); 18 | messageCallback?.Invoke(ev); 19 | ev = null; 20 | } 21 | 22 | private IAIUIAgent(string param, AIUIMessageCallback cb) 23 | { 24 | if (IntPtr.Zero == mAgent) 25 | { 26 | messageCallback = cb; 27 | onEvent_ = new AIUIMessageCallback_(OnEvent); 28 | mAgent = aiui_agent_create(Marshal.StringToHGlobalAnsi(param), onEvent_, IntPtr.Zero); 29 | } 30 | } 31 | 32 | public static IAIUIAgent Create(string param, AIUIMessageCallback cb) 33 | { 34 | return new IAIUIAgent(param, cb); 35 | } 36 | 37 | public void SendMessage(IAIUIMessage msg) 38 | { 39 | if (IntPtr.Zero != mAgent) 40 | aiui_agent_send_message(mAgent, msg.Ptr); 41 | } 42 | 43 | ~IAIUIAgent() 44 | { 45 | Destroy(); 46 | } 47 | 48 | public void Destroy() 49 | { 50 | if (IntPtr.Zero != mAgent) 51 | { 52 | aiui_agent_destroy(mAgent); 53 | mAgent = IntPtr.Zero; 54 | } 55 | 56 | messageCallback = null; 57 | onEvent_ = null; 58 | } 59 | 60 | public static string Version() 61 | { 62 | IntPtr temp = aiui_get_version(); 63 | string res = Marshal.PtrToStringAnsi(temp).ToString(); 64 | temp = IntPtr.Zero; 65 | 66 | return res; 67 | } 68 | 69 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 70 | private delegate void AIUIMessageCallback_(IntPtr ev, IntPtr data); 71 | 72 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 73 | private extern static IntPtr aiui_agent_create(IntPtr param, AIUIMessageCallback_ cb, IntPtr data); 74 | 75 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 76 | private extern static void aiui_agent_send_message(IntPtr agent, IntPtr msg); 77 | 78 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 79 | private extern static void aiui_agent_destroy(IntPtr agent); 80 | 81 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 82 | private extern static IntPtr aiui_get_version(); 83 | } 84 | } -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/IAIUIBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace aiui 5 | { 6 | class IBuffer 7 | { 8 | public IntPtr mData; 9 | 10 | private IBuffer(IntPtr data) 11 | { 12 | mData = data; 13 | } 14 | 15 | public static readonly IBuffer Zero = new IBuffer(IntPtr.Zero); 16 | 17 | public static IBuffer FromData(byte[] data, int len) 18 | { 19 | IntPtr tmp = aiui_create_buffer_from_data(ref data[0], len); 20 | return new IBuffer(tmp); 21 | } 22 | 23 | ~IBuffer() 24 | { 25 | mData = IntPtr.Zero; 26 | } 27 | 28 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 29 | private static extern IntPtr aiui_create_buffer_from_data(ref byte data, int len); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/IAIUIEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace aiui 5 | { 6 | class IAIUIEvent 7 | { 8 | private IntPtr mEvent; 9 | private IDataBundle mBundle; 10 | 11 | public IAIUIEvent(IntPtr ev) 12 | { 13 | mEvent = ev; 14 | mBundle = new IDataBundle(aiui_event_databundle(mEvent)); 15 | } 16 | 17 | public int GetEventType() 18 | { 19 | return aiui_event_type(mEvent); 20 | } 21 | 22 | public int GetArg1() 23 | { 24 | return aiui_event_arg1(mEvent); 25 | } 26 | 27 | public int GetArg2() 28 | { 29 | return aiui_event_arg2(mEvent); 30 | } 31 | 32 | public string GetInfo() 33 | { 34 | IntPtr temp = aiui_event_info(mEvent); 35 | string info = Marshal.PtrToStringAnsi(temp).ToString(); 36 | temp = IntPtr.Zero; 37 | 38 | return info; 39 | } 40 | 41 | ~IAIUIEvent() 42 | { 43 | mEvent = IntPtr.Zero; 44 | mBundle = null; 45 | } 46 | 47 | public IDataBundle GetData() 48 | { 49 | return mBundle; 50 | } 51 | 52 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 53 | private static extern int aiui_event_type(IntPtr ev); 54 | 55 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 56 | private static extern int aiui_event_arg1(IntPtr ev); 57 | 58 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 59 | private static extern int aiui_event_arg2(IntPtr ev); 60 | 61 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 62 | private static extern IntPtr aiui_event_info(IntPtr ev); 63 | 64 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 65 | private static extern IntPtr aiui_event_databundle(IntPtr ev); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/IAIUIMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace aiui 5 | { 6 | class IAIUIMessage 7 | { 8 | public IntPtr Ptr; 9 | 10 | private IAIUIMessage(IntPtr ptr) 11 | { 12 | Ptr = ptr; 13 | } 14 | 15 | public static IAIUIMessage Create(int msgType, int arg1, int arg2, string param, IBuffer data) 16 | { 17 | IntPtr tmp = aiui_msg_create(msgType, arg1, arg2, Marshal.StringToHGlobalAnsi(param), data.mData); 18 | return new IAIUIMessage(tmp); 19 | } 20 | 21 | ~IAIUIMessage() 22 | { 23 | Destroy(); 24 | } 25 | 26 | public void Destroy() 27 | { 28 | if (Ptr != IntPtr.Zero) 29 | { 30 | aiui_msg_destroy(Ptr); 31 | Ptr = IntPtr.Zero; 32 | } 33 | } 34 | 35 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 36 | private static extern IntPtr aiui_msg_create(int msgType, int arg1, int arg2, IntPtr param, IntPtr data); 37 | 38 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 39 | private static extern void aiui_msg_destroy(IntPtr msg); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/IDataBundle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace aiui 5 | { 6 | class IDataBundle 7 | { 8 | public IntPtr mDataBundle; 9 | 10 | public IDataBundle(IntPtr db) 11 | { 12 | mDataBundle = db; 13 | } 14 | 15 | public int GetInt(string key, int defVal) 16 | { 17 | return aiui_db_int(mDataBundle, Marshal.StringToHGlobalAnsi(key), defVal); 18 | } 19 | 20 | public string GetString(string key, string defVal) 21 | { 22 | IntPtr tmp = aiui_db_string(mDataBundle, Marshal.StringToHGlobalAnsi(key), Marshal.StringToHGlobalAnsi(defVal)); 23 | 24 | return Marshal.PtrToStringAnsi(tmp); 25 | } 26 | 27 | public byte[] GetBinary(string key, ref int len) 28 | { 29 | IntPtr tmp = aiui_db_binary(mDataBundle, Marshal.StringToHGlobalAnsi(key), ref len); 30 | 31 | byte[] managedArray = new byte[len]; 32 | Marshal.Copy(tmp, managedArray, 0, len); 33 | 34 | return managedArray; 35 | } 36 | 37 | ~IDataBundle() 38 | { 39 | mDataBundle = IntPtr.Zero; 40 | } 41 | 42 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 43 | private static extern int aiui_db_int(IntPtr db, IntPtr key, int defVal); 44 | 45 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 46 | private static extern IntPtr aiui_db_string(IntPtr db, IntPtr key, IntPtr defVal); 47 | 48 | [DllImport("aiui", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 49 | private static extern IntPtr aiui_db_binary(IntPtr db, IntPtr key, ref int len); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("aiui_csharp_demo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("aiui_csharp_demo")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("878279f9-9616-4547-a589-d1c993086df8")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/aiui_csharp_demo.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ..\..\..\ 5 | 6 | 7 | publish\ 8 | 9 | 10 | 11 | 12 | 13 | en-US 14 | false 15 | ShowAllFiles 16 | 17 | 18 | ..\..\..\ 19 | 20 | 21 | ..\..\..\ 22 | 23 | -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /aiui/c-sharp/aiui_csharp_demo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /aiui/c-sharp/packages/NAudio.1.9.0/.signature.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/NAudio.1.9.0/.signature.p7s -------------------------------------------------------------------------------- /aiui/c-sharp/packages/NAudio.1.9.0/NAudio.1.9.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/NAudio.1.9.0/NAudio.1.9.0.nupkg -------------------------------------------------------------------------------- /aiui/c-sharp/packages/NAudio.1.9.0/lib/net35/NAudio.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/NAudio.1.9.0/lib/net35/NAudio.dll -------------------------------------------------------------------------------- /aiui/c-sharp/packages/NAudio.1.9.0/lib/netstandard2.0/NAudio.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/NAudio.1.9.0/lib/netstandard2.0/NAudio.dll -------------------------------------------------------------------------------- /aiui/c-sharp/packages/NAudio.1.9.0/lib/uap10.0.10240/NAudio.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/NAudio.1.9.0/lib/uap10.0.10240/NAudio.dll -------------------------------------------------------------------------------- /aiui/c-sharp/packages/NAudio.1.9.0/lib/uap10.0.10240/NAudio.pri: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/NAudio.1.9.0/lib/uap10.0.10240/NAudio.pri -------------------------------------------------------------------------------- /aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/.signature.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/.signature.p7s -------------------------------------------------------------------------------- /aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2007 James Newton-King 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/Newtonsoft.Json.13.0.1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/Newtonsoft.Json.13.0.1.nupkg -------------------------------------------------------------------------------- /aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/net20/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/net20/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/net35/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/net35/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/net40/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/net40/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/net45/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/net45/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/netstandard1.0/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/netstandard1.0/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/netstandard1.3/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/netstandard1.3/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/netstandard2.0/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/lib/netstandard2.0/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/packageIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c-sharp/packages/Newtonsoft.Json.13.0.1/packageIcon.png -------------------------------------------------------------------------------- /aiui/c/AIUI/audio/weather.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/c/AIUI/audio/weather.pcm -------------------------------------------------------------------------------- /aiui/c/AIUI/cfg/aiui.cfg: -------------------------------------------------------------------------------- 1 | /* AIUI参数配置 */ 2 | { 3 | /* 交互参数 */ 4 | "interact": { 5 | "interact_timeout": "-1", 6 | "result_timeout": "5000" 7 | }, 8 | /* 全局设置 */ 9 | "global": { 10 | "scene": "main_box" 11 | }, 12 | 13 | "login": { 14 | "appid": "xxxxxxxx" 15 | }, 16 | 17 | /* 业务相关参数 */ 18 | // 本地vad参数 19 | "vad": { 20 | "engine_type": "meta" 21 | }, 22 | // 识别(音频输入)参数 23 | "iat": { 24 | "sample_rate": "16000" 25 | }, 26 | /* 业务流程相关参数 */ 27 | // 语音业务流程 28 | "speech": { 29 | "data_source": "sdk", 30 | "wakeup_mode": "off", 31 | "interact_mode": "continuous", 32 | "intent_engine_type": "cloud" 33 | }, 34 | 35 | /* 日志设置 */ 36 | "log": { 37 | "debug_log": "1", 38 | "save_datalog": "0", 39 | "datalog_path": ".", 40 | "datalog_size": 1024, 41 | "raw_audio_path": "" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /aiui/c/README.txt: -------------------------------------------------------------------------------- 1 | 1. 将在平台下载的aiui库放在此目录下 2 | 2. gcc main.c -o main -L. -Iinclude -laiui -Wl,-rpath,'$ORIGIN' -Werror 3 | 3. 修改 AIUI/cfg/aiui.cfg 下的 appid -------------------------------------------------------------------------------- /aiui/c/include/aiui/AIUICommon.h: -------------------------------------------------------------------------------- 1 | #ifndef AIUI_COMMON_HDR_X2342Y3 2 | #define AIUI_COMMON_HDR_X2342Y3 3 | 4 | #if defined(WIN32) 5 | # ifndef AIUI_WINDOWS 6 | # define AIUI_WINDOWS 7 | # endif 8 | #endif 9 | 10 | #if defined(AIUI_WINDOWS) 11 | # if !defined(__MINGW32__) 12 | typedef long ssize_t; 13 | typedef unsigned long pid_t; 14 | # endif 15 | 16 | # undef AIUIEXPORT 17 | # if defined(AIUI_LIB_COMPILING) 18 | # define AIUI_DEPRECATED __declspec(deprecated) 19 | # define AIUIEXPORT __declspec(dllexport) 20 | # define AIUIHIDDEN 21 | # define AIUIAPI __stdcall 22 | # else 23 | # define AIUI_DEPRECATED __declspec(deprecated) 24 | # define AIUIEXPORT 25 | # define AIUIHIDDEN 26 | # define AIUIAPI __stdcall 27 | # endif 28 | #else 29 | # undef AIUIEXPORT 30 | # define AIUI_DEPRECATED __attribute__((deprecated)) 31 | # define AIUIEXPORT __attribute__((visibility("default"))) 32 | # define AIUIHIDDEN __attribute__((visibility("hidden"))) 33 | # undef AIUIAPI 34 | # define AIUIAPI 35 | #endif 36 | 37 | #ifndef __cplusplus 38 | # define __AIUI_PRFIX__(x) AIUI_##x 39 | # define AIUI_PRFIX(x) __AIUI_PRFIX__(x) 40 | #else 41 | # define AIUI_PRFIX(x) x 42 | #endif 43 | #endif 44 | -------------------------------------------------------------------------------- /aiui/java/README.txt: -------------------------------------------------------------------------------- 1 | 1. 将平台下载的 aiui 库放在此目录下 2 | 2. 将平台下载中 Sample 目录下的 AIUI 拷贝至此 3 | -------------------------------------------------------------------------------- /aiui/java/aiui-1.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/java/aiui-1.0.0.jar -------------------------------------------------------------------------------- /aiui/python/AIUI/audio/test.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/aiui/python/AIUI/audio/test.pcm -------------------------------------------------------------------------------- /aiui/python/AIUI/cfg/aiui.cfg: -------------------------------------------------------------------------------- 1 | /* AIUI参数配置 */ 2 | { 3 | /* 交互参数 */ 4 | "interact": { 5 | "interact_timeout": "-1", 6 | "result_timeout": "5000" 7 | }, 8 | 9 | /* 全局设置 */ 10 | "global": { 11 | "scene": "main_box" 12 | }, 13 | 14 | /* 请登录 https://aiui.xfyun.cn 查看应用 */ 15 | "login": { 16 | "appid": "xxxxxxxx", 17 | "key": "xxxxxxxxxxxxxxxxx" 18 | }, 19 | 20 | /* 业务相关参数 */ 21 | // 本地vad参数 22 | "vad": { 23 | "engine_type": "meta" 24 | }, 25 | 26 | // 识别(音频输入)参数 27 | "iat": { 28 | "sample_rate": "16000" 29 | }, 30 | 31 | /* 业务流程相关参数 */ 32 | // 语音业务流程 33 | "speech": { 34 | "data_source": "sdk", 35 | "interact_mode": "continous", 36 | "intent_engine_type": "cloud" 37 | }, 38 | 39 | /* 日志设置 */ 40 | "log": { 41 | "debug_log": "0", 42 | "save_datalog": "0", 43 | "datalog_path": "", 44 | "datalog_size": 1024, 45 | "raw_audio_path": "" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /aiui/python/README.txt: -------------------------------------------------------------------------------- 1 | 1. 将平台下载的 aiui 库放在此目录下且重新命名为 aiui.dll 2 | 2. 修改 AIUI/cfg/aiui.cfg 下的 appid 和 key 3 | 3. 执行 python3 main.py 4 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | .vscode -------------------------------------------------------------------------------- /docs/_static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/docs/_static/.gitkeep -------------------------------------------------------------------------------- /docs/_static/aiui.css: -------------------------------------------------------------------------------- 1 | .wy-nav-content { 2 | max-width: 1000px; 3 | } -------------------------------------------------------------------------------- /docs/_static/screenshot_1519613427018.4507411a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/docs/_static/screenshot_1519613427018.4507411a.png -------------------------------------------------------------------------------- /docs/_templates/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/docs/_templates/.gitkeep -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. _head_link: 2 | 3 | ############################# 4 | AIUI语音SDK集成文档 5 | ############################# 6 | 7 | 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | :glob: 12 | 13 | src/* 14 | -------------------------------------------------------------------------------- /postprocess-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | com.iflytek.aiint 12 | postprocess-demo 13 | 0.0.1 14 | PostprocessDemo 15 | Demo project for Postprocess 16 | 17 | 1.8 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-test 28 | test 29 | 30 | 31 | 32 | 33 | com.alibaba 34 | fastjson 35 | 1.2.83 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /postprocess-demo/src/main/java/com/iflytek/aiint/demo/PostprocessDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiint.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class PostprocessDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(PostprocessDemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /postprocess-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/postprocess-demo/src/main/resources/application.properties -------------------------------------------------------------------------------- /postprocess-demo/src/test/java/com/iflytek/aiint/demo/PostprocessDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiint.demo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class PostprocessDemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /webapi/doc/apikey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/webapi/doc/apikey.png -------------------------------------------------------------------------------- /webapi/doc/createApp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/webapi/doc/createApp.png -------------------------------------------------------------------------------- /webapi/doc/ip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/webapi/doc/ip.png -------------------------------------------------------------------------------- /webapi/doc/skill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/webapi/doc/skill.png -------------------------------------------------------------------------------- /webapi/doc/webapi接口接入文档.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/webapi/doc/webapi接口接入文档.docx -------------------------------------------------------------------------------- /webapi/nodejs/iat.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var fs = require('fs'); 3 | var http=require('http'); 4 | const crypto = require('crypto'); 5 | const hash = crypto.createHash('md5'); 6 | 7 | var webiat = function(){ 8 | //讯飞开放平台注册申请应用的应用ID(APPID) 9 | var xAppid = "xxxxxxxx"; 10 | console.log('X-Appid:'+xAppid); 11 | var timestamp = Date.parse(new Date()); 12 | var curTime = timestamp / 1000; 13 | console.log('X-CurTime:'+curTime); 14 | var xParam = {"auf": "16k", "aue": "raw", "scene": "main"} 15 | xParam = JSON.stringify(xParam); 16 | var xParamBase64 = new Buffer(xParam).toString('base64'); 17 | console.log('X-Param:'+xParamBase64); 18 | //音频文件 19 | var fileData = fs.readFileSync('16k.pcm'); 20 | var fileBase64 = new Buffer(fileData).toString('base64'); 21 | var bodyData = "data="+fileBase64; 22 | //ApiKey创建应用时自动生成 23 | var apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 24 | var token = apiKey + curTime+ xParamBase64 + bodyData; 25 | hash.update(token); 26 | var xCheckSum = hash.digest('hex'); 27 | console.log('X-CheckSum:'+xCheckSum); 28 | var options={ 29 | hostname:'api.xfyun.cn', 30 | port:80, 31 | path:'/v1/aiui/v1/iat', 32 | method:'POST', 33 | headers:{ 34 | "X-Appid": xAppid, 35 | "X-CurTime": curTime, 36 | "X-Param":xParamBase64, 37 | "X-CheckSum":xCheckSum, 38 | 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8' 39 | } 40 | }; 41 | var req = http.request(options, function(res) { 42 | res.setEncoding('utf-8'); 43 | res.on('data',function(rersult){ 44 | console.info('result body :'+rersult); 45 | }); 46 | res.on('end',function(){ 47 | console.log('No more data in response.'); 48 | }); 49 | }); 50 | req.on('error',function(err){ 51 | console.error(err); 52 | }); 53 | req.write(bodyData); 54 | req.end(); 55 | }; 56 | 57 | webiat(); 58 | 59 | module.exports = webiat; -------------------------------------------------------------------------------- /webapi/python/iat.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | import base64 3 | import sys 4 | import time 5 | import json 6 | import hashlib 7 | from urllib import request,parse 8 | 9 | def webiat(): 10 | print("python version : .{}".format(sys.version)) 11 | requrl = "https://api.xfyun.cn/v1/aiui/v1/iat" 12 | print('requrl:{}'.format(requrl)) 13 | #讯飞开放平台注册申请应用的应用ID(APPID) 14 | x_appid = "xxxxxxxx"; 15 | print('X-Appid:{}'.format(x_appid)) 16 | cur_time = int(time.time()) 17 | print('X-CurTime:{}'.format(cur_time)) 18 | x_param = {"auf":"16k","aue":"raw","scene":"main"} 19 | x_param = json.dumps(x_param) 20 | xparam_base64 = base64.b64encode(x_param.encode(encoding="utf-8")).decode().strip('\n') 21 | print('X-Param:{}'.format(xparam_base64)) 22 | #音频文件 23 | file_data = open('16k.pcm', 'rb') 24 | file_base64 = base64.b64encode(file_data.read()) 25 | file_data.close() 26 | body_data = "data="+file_base64.decode("utf-8") 27 | #ApiKey创建应用时自动生成 28 | api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 29 | token = api_key + str(cur_time)+ xparam_base64 + body_data 30 | m = hashlib.md5() 31 | m.update(token.encode(encoding='utf-8')) 32 | x_check_sum = m.hexdigest() 33 | print('X-CheckSum:{}'.format(x_check_sum)) 34 | headers = {"X-Appid": x_appid,"X-CurTime": cur_time,"X-Param":xparam_base64,"X-CheckSum":x_check_sum,"Content-Type":"application/x-www-form-urlencoded"} 35 | print("headers : {}".format(headers)) 36 | req = request.Request(requrl, data=body_data.encode('utf-8'), headers=headers, method="POST") 37 | with request.urlopen(req) as f: 38 | body = f.read().decode('utf-8') 39 | print("result body : {}".format(body)) 40 | 41 | webiat() -------------------------------------------------------------------------------- /webapi_v2/c-sharp/WebaiuiDemo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/webapi_v2/c-sharp/WebaiuiDemo.cs -------------------------------------------------------------------------------- /webapi_v2/doc/接口概述.md: -------------------------------------------------------------------------------- 1 | - [API说明](##1) 2 | - [授权认证](##2) 3 | - [IP白名单](##3) 4 | 5 | 6 | ## API说明 7 | 1. 授权认证,调用接口需要将 Appid,CurTime, Param 和 CheckSum 信息放在 HTTP 请求头中; 8 | 2. 接口统一为 UTF-8 编码; 9 | 3. 接口支持 http 和 https; 10 | 4. 请求方式为POST。 11 | 12 | 13 | ## 授权认证 14 | 在调用所有业务接口时,都需要在 Http Request Header 中配置以下参数用于授权认证: 15 | 16 | |参数|格式|说明|必须| 17 | |:-------|:---------|:--------|:---------| 18 | |X-Appid|string|讯飞开放平台注册申请应用的应用ID(appid)|是| 19 | |X-CurTime|string|当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数|是| 20 | |X-Param|string|相关参数JSON串经Base64编码后的字符串,见各接口详细说明|是| 21 | |X-CheckSum|string|令牌,计算方法:MD5(apiKey + curTime + param),三个值拼接的字符串,进行MD5哈希计算(32位小写),其中apiKey由讯飞提供,调用方管理。 |是| 22 | 23 | *注:* 24 | * apiKey:接口密钥,由讯飞开放平台提供,调用方注意保管,如泄露,可联系讯飞技术人员重置; 25 | * checkSum 有效期:出于安全性考虑,每个 checkSum 的有效期为 5 分钟(用 curTime 计算),同时 curTime 要与标准时间同步,否则,时间相差太大,服务端会直接认为 curTime 无效; 26 | * BASE64 编码采用 MIME 格式,字符包括大小写字母各26个,加上10个数字,和加号 + ,斜杠 / ,一共64个字符。 27 | 28 | *checkSum *生成示例: 29 | ~~~ 30 | String apiKey="abcd1234"; 31 | String curTime="1502607694"; 32 | String param="eyAiYXVmIjogImF1ZGlvL0wxNjtyYXR..."; 33 | String checkSum=MD5(apiKey+curTime+param); 34 | ~~~ 35 | 36 | 37 | ## IP白名单 38 | 在调用所有业务接口时,授权认证通过后,检查调用方 ip 是否在讯飞开放平台配置的 ip白名单 中。存在通过,否则拒绝提供服务。 39 | *注:* 40 | * IP白名单 可联系讯飞技术人员设置; 41 | * 拒绝提供服务返回值: 42 | 43 | ~~~ 44 | { 45 | "code":"10105", 46 | "desc":"illegal access|illegal client_ip", 47 | "data":"", 48 | "sid":"xxxxxx" 49 | } 50 | ~~~ -------------------------------------------------------------------------------- /webapi_v2/doc/简介.md: -------------------------------------------------------------------------------- 1 | 本文档是集成科大讯飞 REST API 的用户指南,介绍各 能力接口的基本使用。在集成过程有疑问,可登录语音云开发者论坛,查找答案或与其他开发者交流:[http://bbs.xfyun.cn ](http://bbs.xfyun.cn )。 2 | 3 | 注意: 4 | 此文章的代码,仅为用于示例调用和参数设置的代码片段,很可能有参数被引用,却未曾声明等情况,请开发者不必过于考究其中的细节。 -------------------------------------------------------------------------------- /webapi_v2/doc/错误码.md: -------------------------------------------------------------------------------- 1 | | 错误码 |描述|说明|处理方式| 2 | |:-------------|:-------------|:-------------|:-------------| 3 | |0|success|成功|| 4 | |10105|illegal access|没有权限|检查apiKey,ip,checkSum等授权参数是否正确| 5 | |10106|invalid parameter|无效参数或参数值为空|上传必要的参数, 检查参数格式以及编码| 6 | |10107|illegal parameter|非法参数值|检查参数值是否超过范围或不符合要求| 7 | |10109|illegal data length|数据长度非法|检查上传数据长度是否超过限制| 8 | |10110|no license|无授权许可|提供请求的 appid、 auth_id 向服务商反馈| 9 | |10114|time out|超时|检测网络连接或联系服务商| 10 | |10700|engine error|引擎错误|提供接口返回值,向服务商反馈| 11 | |11004|server up error|服务请求上线错误|提供接口返回值,向服务商反馈| 12 | |10202|websocket connect error|套接字连接异常|提供接口返回值,向服务商反馈| 13 | |10204|websocket write error|网络数据包发送异常|提供接口返回值,向服务商反馈| 14 | |10205|websocket read error|网络数据包接收异常|提供接口返回值,向服务商反馈| 15 | |11201|appid authorize number not enough|每秒交互次数超过上限|确认接口每秒交互次数是否超过限制(默认为20)| -------------------------------------------------------------------------------- /webapi_v2/java/commons-codec-1.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/webapi_v2/java/commons-codec-1.6.jar -------------------------------------------------------------------------------- /webapi_v2/nodejs/WebaiuiDemo.js: -------------------------------------------------------------------------------- 1 | const crypto = require('crypto'); 2 | const fs = require('fs'); 3 | const path = require('path'); 4 | 5 | var http=require('http'); 6 | var querystring=require('querystring'); 7 | 8 | var APPID = ""; 9 | var API_KEY = ""; 10 | var AUTH_ID = "2894c985bf8b1111c6728db79d3479ae"; 11 | var AUE = "raw"; 12 | var CLIENT_IP = "127.0.0.1"; 13 | var SAMPLE_RATE = "16000"; 14 | var DATA_TYPE = "audio"; 15 | var SCENE = "main"; 16 | var LAT = "39.938838"; 17 | var LNG = "116.368624"; 18 | var RESULT_LEVEL = "complete"; 19 | var FILE_PATH = "" 20 | // 个性化参数,需转义 21 | var PERS_PARAM = "{\\\"auth_id\\\":\\\"2894c985bf8b1111c6728db79d3479ae\\\"}"; 22 | 23 | var X_CurTime = Math.floor(Date.now()/1000); 24 | var param = "{\"result_level\":\""+RESULT_LEVEL+"\",\"aue\":\""+AUE+"\",\"scene\":\""+SCENE+"\",\"auth_id\":\""+AUTH_ID+"\",\"data_type\":\""+DATA_TYPE+"\",\"sample_rate\":\""+SAMPLE_RATE+"\",\"lat\":\""+LAT+"\",\"lng\":\""+LNG+"\"}"; 25 | //使用个性化参数时参数格式如下: 26 | // var param = "{\"result_level\":\""+RESULT_LEVEL+"\",\"aue\":\""+AUE+"\",\"scene\":\""+SCENE+"\",\"auth_id\":\""+AUTH_ID+"\",\"data_type\":\""+DATA_TYPE+"\",\"sample_rate\":\""+SAMPLE_RATE+"\",\"lat\":\""+LAT+"\",\"lng\":\""+LNG+"\",\"pers_param\":\""+PERS_PARAM+"\"}"; 27 | var X_Param = new Buffer(param).toString('base64'); 28 | var X_CheckSum = md5(API_KEY+X_CurTime+X_Param); 29 | 30 | var options={ 31 | hostname:'openapi.xfyun.cn', 32 | port:80, 33 | path:'/v2/aiui', 34 | method:'POST', 35 | headers:{ 36 | 'X-Param': X_Param, 37 | 'X-CurTime': X_CurTime, 38 | 'X-CheckSum': X_CheckSum, 39 | 'X-Appid': APPID 40 | } 41 | } 42 | 43 | var data = fs.readFileSync(path.resolve(FILE_PATH)); 44 | 45 | var req=http.request(options, function(res) { 46 | console.log('Status:',res.statusCode); 47 | res.setEncoding('utf-8'); 48 | res.on('data',function(chun){ 49 | console.log('response:\r\n'); 50 | console.info(chun); 51 | }); 52 | res.on('end',function(){ 53 | console.log('end'); 54 | }); 55 | }); 56 | 57 | req.on('error',function(err){ 58 | console.error(err); 59 | }); 60 | 61 | req.write(data); 62 | req.end(); 63 | 64 | function md5 (text) { 65 | return crypto.createHash('md5').update(text).digest('hex'); 66 | }; -------------------------------------------------------------------------------- /webapi_v2/php/WebaiuiDemo.php: -------------------------------------------------------------------------------- 1 | $RESULT_LEVEL, 21 | "aue"=>$AUE, 22 | "scene"=>$SCENE, 23 | "auth_id"=>$AUTH_ID, 24 | "data_type"=>$DATA_TYPE, 25 | "sample_rate"=>$SAMPLE_RATE, 26 | "lat"=>$LAT, 27 | "lng"=>$LNG, 28 | //如需使用个性化参数: 29 | //"pers_param"=>$PERS_PARAM, 30 | ); 31 | 32 | $curTime = time(); 33 | $paramBase64 = base64_encode(json_encode($Param)); 34 | $checkSum = md5($API_KEY.$curTime.$paramBase64); 35 | 36 | $headers = array(); 37 | $headers[] = 'X-CurTime:'.$curTime; 38 | $headers[] = 'X-Param:'.$paramBase64; 39 | $headers[] = 'X-CheckSum:'.$checkSum; 40 | $headers[] = 'X-Appid:'.$APPID; 41 | 42 | $fp = fopen($FILE_PATH, "rb"); 43 | $dataArray = fread($fp,filesize($FILE_PATH)); 44 | 45 | echo $this->https_request($URL, $dataArray, $headers); 46 | echo "\n"; 47 | } 48 | 49 | function https_request($url, $post_data, $headers) { 50 | $options = array( 51 | 'http' => array( 52 | 'method' => 'POST', 53 | 'header' => $headers, 54 | 'content' => $post_data, 55 | 'timeout' => 10 56 | ) 57 | ); 58 | $context = stream_context_create($options); 59 | $result = file_get_contents($url, false, $context); 60 | 61 | echo $result; 62 | } 63 | } 64 | $demo = new Demo(); 65 | $demo->testWebaiui(); 66 | ?> -------------------------------------------------------------------------------- /webapi_v2/python/WebaiuiDemo.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | import requests 3 | import time 4 | import hashlib 5 | import base64 6 | 7 | URL = "http://openapi.xfyun.cn/v2/aiui" 8 | APPID = "" 9 | API_KEY = "" 10 | AUE = "raw" 11 | AUTH_ID = "2894c985bf8b1111c6728db79d3479ae" 12 | DATA_TYPE = "audio" 13 | SAMPLE_RATE = "16000" 14 | SCENE = "main" 15 | RESULT_LEVEL = "complete" 16 | LAT = "39.938838" 17 | LNG = "116.368624" 18 | #个性化参数,需转义 19 | PERS_PARAM = "{\\\"auth_id\\\":\\\"2894c985bf8b1111c6728db79d3479ae\\\"}" 20 | FILE_PATH = "" 21 | 22 | 23 | def buildHeader(): 24 | curTime = str(int(time.time())) 25 | param = "{\"result_level\":\""+RESULT_LEVEL+"\",\"auth_id\":\""+AUTH_ID+"\",\"data_type\":\""+DATA_TYPE+"\",\"sample_rate\":\""+SAMPLE_RATE+"\",\"scene\":\""+SCENE+"\",\"lat\":\""+LAT+"\",\"lng\":\""+LNG+"\"}" 26 | #使用个性化参数时参数格式如下: 27 | #param = "{\"result_level\":\""+RESULT_LEVEL+"\",\"auth_id\":\""+AUTH_ID+"\",\"data_type\":\""+DATA_TYPE+"\",\"sample_rate\":\""+SAMPLE_RATE+"\",\"scene\":\""+SCENE+"\",\"lat\":\""+LAT+"\",\"lng\":\""+LNG+"\",\"pers_param\":\""+PERS_PARAM+"\"}" 28 | paramBase64 = base64.b64encode(param) 29 | 30 | m2 = hashlib.md5() 31 | m2.update(API_KEY + curTime + paramBase64) 32 | checkSum = m2.hexdigest() 33 | 34 | header = { 35 | 'X-CurTime': curTime, 36 | 'X-Param': paramBase64, 37 | 'X-Appid': APPID, 38 | 'X-CheckSum': checkSum, 39 | } 40 | return header 41 | 42 | def readFile(filePath): 43 | binfile = open(filePath, 'rb') 44 | data = binfile.read() 45 | return data 46 | 47 | r = requests.post(URL, headers=buildHeader(), data=readFile(FILE_PATH)) 48 | print(r.content) -------------------------------------------------------------------------------- /webapi_v2/resource/bj_weather.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/webapi_v2/resource/bj_weather.wav -------------------------------------------------------------------------------- /webapi_v2_entity/doc/动态实体webapi.md: -------------------------------------------------------------------------------- 1 | # API说明 2 | 3 | * 授权认证,调用接口需要将nameSpace,nonce,curtime和checkSum信息放在HTTP请求头中。 4 | * 所有接口统一为UTF-8编码。 5 | * 所有接口支持http和https。 6 | 7 | # 授权认证 8 | 9 | 在调用所有业务接口时,都需要在Http Request Header中加入以下参数作为授权验证 10 | 11 | |参数名|说明|是否必须| 12 | | ------|----------------------|--------| 13 | | X-NameSpace | aiui开放平台个人中心的命名空间 |是| 14 | | X-Nonce |随机数(最大长度128个字符)|是| 15 | | X-CurTime |当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数(String)|是| 16 | | X-CheckSum |MD5(accountKey + Nonce + CurTime),三个参数拼接的字符串,进行MD5哈希计算|是| 17 | 18 | 注: 19 | 20 | * CheckSum有效期:出于安全性考虑,每个CheckSum的有效期为5分钟(用curTime计算),同时CurTime要与标准时间同步,否则,时间相差太大,服务端会直接认为CurTime无效。 21 | 22 | * checkSum生成示例,例如: 23 | 24 | accountKey是abcd1234, Nonce是12, CurTime是1502607694。那么CheckSum为MD5(abcd1234121502607694) 25 | 最终MD5为32位小写 bf5aa1f53bd173cf7413bf370ad4bddc 26 | 27 | # IP 白名单 28 | 29 | IP 白名单具备打开和关闭两种状态。 30 | 31 | * 当 IP 白名单打开时,用户在调用所有业务接口时,在授权认证通过后,检查调用方ip是否在aiui开放平台配置的ip白名单中。若在,则向用户提供服务,否则拒绝提供服务。 32 | 33 | * 当 IP 白名单关闭时,任意终端均可访问 AIUI 服务器,开发者需要自行保证 nameSpace 和 key 值安全。 34 | 35 | 注:拒绝提供服务返回值:{"code":"20004","desc":"ip非法","data":null,"sid":"rwabb52e660@dx6c9b0e56f81d3ef000"} 36 | 37 | # 通用请求地址 38 | 39 | base_url:openapi.xfyun.cn 40 | 41 | # AIUI接口 42 | 43 | 通用返回参数 44 | 45 | |参数名|说明|是否必须| 46 | | ------|----------------------|--------| 47 | |code |结果码 |是| 48 | |data |返回结果 |是| 49 | |desc |描述 |是| 50 | |sid |本次webapi服务唯一标识 |是| 51 | 52 | ## 动态实体 53 | ### 上传资源 54 | 55 | * 接口描述 56 | 57 | 本接口提供动态实体上传资源功能,用于动态更新实体资源。 58 | 59 | * 接口地址 60 | 61 | POST /v2/aiui/entity/upload-resource HTTP/1.1 62 | 63 | Content-Type:application/x-www-form-urlencoded; charset=utf-8 64 | 65 | * 参数说明 66 | 67 | |参数|类型|必须|说明|
示例
| 68 | | ------|-------|-------|--------|--------| 69 | |appid|string|是|应用id|5adde3cf| 70 | |res_name|String|是|资源名,XXX为用户的命名空间|XXX.music| 71 | |pers_param|String|是|个性化参数(json)|{"appid":"xxxxxx"}| 72 | |data|String|是|Base64编码的资源|示例1| 73 | 74 | 其中,pers_param为个性化参数。示例如下: 75 | 76 | |维度|示例|说明| 77 | | ------|-------|-------| 78 | |应用级|{"appid":"xxxxxx"}|| 79 | |用户级|{"auth_id":"d3b6d50a9f8194b623b5e2d4e298c9d6"}|auth_id为用户唯一ID(32位字符串,包括英文小写字母与数字,开发者需保证该值与终端用户一一对应)| 80 | |自定义级|{"xxxxxx":"xxxxxx"}|| 81 | 82 | data为web页面定义的主子段、从字段给的json格式对应的base64。例如,主子段为song、从字段singer,上传资源的格式为: 83 | 84 | {"song":"给我一首歌的时间","singer":"周杰伦"} 85 | {"song":"忘情水","singer":"刘德华"} 86 | {"song":"暗香","singer":"刘德华"} 87 | {"song":"逆光","singer":"梁静茹"} 88 | 89 | 注:每条数据之间用换行符隔开。 90 | 91 | Base64编码为 92 | 93 | 示例1: 94 | 95 | eyJzb25nIjoi57uZ5oiR5LiA6aaW5q2M55qE5pe26Ze0Iiwic2luZ2VyIjoi5ZGo5p2w5LymIn0NCnsic29uZyI6IuW/mOaDheawtCIsInNpbmdlciI6IuWImOW+t+WNjiJ9DQp7InNvbmciOiLmmpfpppkiLCJzaW5nZXIiOiLliJjlvrfljY4ifQ0KeyJzb25nIjoi6YCG5YWJIiwic2luZ2VyIjoi5qKB6Z2Z6Iy5In0= 96 | 97 | * 返回说明 98 | 99 | |参数 |类型 |必须 |说明 |示例| 100 | | ------|-------|-------|--------|--------| 101 | |sid |String |是 |本次上传sid,可用于查看上传资源是否成功|psn003478f3@ch00070e3a78e06f2601| 102 | |csid |String |是 |本次服务唯一标识|rwa84b7a73b@ch372d0e3a78e0116200| 103 | 104 | ### 查看上传资源是否成功 105 | 106 | * 接口描述 107 | 108 | 本接口提供检查动态实体上传资源是否成功。 109 | 110 | 注:上传资源数据后至少间隔3秒后再进行查看上传资源是否成功 111 | 112 | * 接口地址 113 | 114 | POST /v2/aiui/entity/check-resource HTTP/1.1 115 | 116 | Content-Type:application/x-www-form-urlencoded; charset=utf-8 117 | 118 | * 参数说明 119 | 120 | |参数|类型|必须|说明|示例| 121 | | ------|-------|-------|--------|--------| 122 | |sid|string|是|sid|psn开头的sid| 123 | 124 | * 返回说明 125 | 126 | |参数 |类型 |必须 |说明 | 127 | | ------|-------|-------|--------| 128 | |sid |String |是 |上传sid| 129 | |csid |String |是 |上传sid| 130 | |reply |String |是 |查看上传资源是否成功描述| 131 | |error |int |是 |查看上传资源是否成功错误码| -------------------------------------------------------------------------------- /webapi_v2_entity/python/WebEntityDemo.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | import base64 3 | import sys 4 | import time 5 | import json 6 | import hashlib 7 | import urllib.parse 8 | from urllib import request,parse 9 | 10 | UPLOAD_URL = "https://openapi.xfyun.cn/v2/aiui/entity/upload-resource"; 11 | CHECK_URL = "https://openapi.xfyun.cn/v2/aiui/entity/check-resource"; 12 | X_NONCE = "12"; 13 | APPID = ""; 14 | X_NAMESPACE = ""; 15 | ACCOUNTKEY = ""; 16 | 17 | def buildHeader(): 18 | curTime = str(int(time.time())) 19 | m = hashlib.md5() 20 | m.update((ACCOUNTKEY + X_NONCE + curTime).encode(encoding='utf-8')) 21 | checkSum = m.hexdigest() 22 | 23 | header = { 24 | 'X-NameSpace': X_NAMESPACE, 25 | 'X-Nonce': X_NONCE, 26 | 'X-CurTime': curTime, 27 | 'X-CheckSum': checkSum, 28 | } 29 | return header 30 | 31 | def buildUploadBody(): 32 | #每条数据之间用换行符隔开 33 | param = "{\"name\":\"张三\",\"phoneNumber\":\"13888888888\"}" + "\r\n" + "{\"name\":\"李四\",\"phoneNumber\":\"13666666666\"}" 34 | paramBase64 = base64.b64encode(param.encode(encoding="utf-8")).decode().strip('\n') 35 | body = { 36 | 'appid': APPID, 37 | 'res_name': 'IFLYTEK.telephone_contact', 38 | 'pers_param': '{\"auth_id\":\"d3b6d50a9f8194b623b5e2d4e298c9d6\"}', 39 | 'data': paramBase64, 40 | } 41 | return body 42 | 43 | def buildCheckBody(sid): 44 | body = { 45 | 'sid': sid 46 | } 47 | return body 48 | 49 | def webEntityDemo(): 50 | body_data = buildUploadBody() 51 | body_data = urllib.parse.urlencode(body_data).encode('utf-8') 52 | req = request.Request(UPLOAD_URL, data=body_data, headers=buildHeader(), method="POST") 53 | f = request.urlopen(req) 54 | result = f.read().decode('utf-8') 55 | print("result body : {}".format(result)) 56 | upload_jo = json.loads(result) 57 | code = upload_jo['code'] 58 | if(code == '00000'): 59 | #上传资源数据后至少间隔3秒后再进行查看上传资源是否成功 60 | time.sleep(3) 61 | sid = upload_jo['data']['sid'] 62 | check_body_data = buildCheckBody(sid) 63 | check_body_data = urllib.parse.urlencode(check_body_data).encode('utf-8') 64 | check_req = request.Request(CHECK_URL, data=check_body_data, headers=buildHeader(), method="POST") 65 | cf = request.urlopen(check_req) 66 | check_result = cf.read().decode('utf-8') 67 | print("check result body : {}".format(check_result)) 68 | 69 | print("python version : .{}".format(sys.version)) 70 | webEntityDemo() -------------------------------------------------------------------------------- /websocket/c-sharp/aiui_ws_csharp_demo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.1267 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "aiui_ws_csharp_demo", "aiui_ws_csharp_demo\aiui_ws_csharp_demo.csproj", "{E12F36D1-D9CE-433E-8A08-A5AE6AAAC11C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E12F36D1-D9CE-433E-8A08-A5AE6AAAC11C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E12F36D1-D9CE-433E-8A08-A5AE6AAAC11C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E12F36D1-D9CE-433E-8A08-A5AE6AAAC11C}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E12F36D1-D9CE-433E-8A08-A5AE6AAAC11C}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {80F352A9-D501-4A5E-B83A-ECA7434442EF} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /websocket/c-sharp/aiui_ws_csharp_demo/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj -------------------------------------------------------------------------------- /websocket/c-sharp/aiui_ws_csharp_demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("aiui_ws_csharp_demo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("aiui_ws_csharp_demo")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e12f36d1-d9ce-433e-8a08-a5ae6aaac11c")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /websocket/c-sharp/aiui_ws_csharp_demo/aiui_ws_csharp_demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {E12F36D1-D9CE-433E-8A08-A5AE6AAAC11C} 8 | Exe 9 | ConsoleApp1 10 | ConsoleApp1 11 | v4.0 12 | 512 13 | true 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | ..\packages\WebSocketSharp-netstandard.1.0.1\lib\net35\websocket-sharp.dll 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /websocket/c-sharp/aiui_ws_csharp_demo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /websocket/c-sharp/aiui_ws_csharp_demo/test.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/websocket/c-sharp/aiui_ws_csharp_demo/test.pcm -------------------------------------------------------------------------------- /websocket/c-sharp/packages/WebSocketSharp-netstandard.1.0.1/.signature.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/websocket/c-sharp/packages/WebSocketSharp-netstandard.1.0.1/.signature.p7s -------------------------------------------------------------------------------- /websocket/c-sharp/packages/WebSocketSharp-netstandard.1.0.1/WebSocketSharp-netstandard.1.0.1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/websocket/c-sharp/packages/WebSocketSharp-netstandard.1.0.1/WebSocketSharp-netstandard.1.0.1.nupkg -------------------------------------------------------------------------------- /websocket/c-sharp/packages/WebSocketSharp-netstandard.1.0.1/lib/net35/websocket-sharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/websocket/c-sharp/packages/WebSocketSharp-netstandard.1.0.1/lib/net35/websocket-sharp.dll -------------------------------------------------------------------------------- /websocket/c-sharp/packages/WebSocketSharp-netstandard.1.0.1/lib/net45/websocket-sharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/websocket/c-sharp/packages/WebSocketSharp-netstandard.1.0.1/lib/net45/websocket-sharp.dll -------------------------------------------------------------------------------- /websocket/c-sharp/packages/WebSocketSharp-netstandard.1.0.1/lib/netstandard2.0/websocket-sharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/websocket/c-sharp/packages/WebSocketSharp-netstandard.1.0.1/lib/netstandard2.0/websocket-sharp.dll -------------------------------------------------------------------------------- /websocket/c/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | !src 4 | !CMakeLists.txt -------------------------------------------------------------------------------- /websocket/c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(aiui_demo) 3 | 4 | set(CMAKE_C_FLAGS "-w ${CMAKE_C_FLAGS} -O0 -g3 -DCJSON_HIDE_SYMBOLS") 5 | 6 | include_directories(src) 7 | link_libraries(-lpthread -lm -ldl) 8 | 9 | FILE(GLOB_RECURSE SRC_LIST 10 | "${CMAKE_CURRENT_LIST_DIR}/src/*.c" 11 | "${CMAKE_CURRENT_LIST_DIR}/src/*.h") 12 | 13 | macro(source_group_by_dir abs_cur_dir source_files) 14 | if (MSVC) 15 | set(sgbd_cur_dir ${${abs_cur_dir}}) 16 | foreach(sgbd_file ${${source_files}}) 17 | string(REGEX REPLACE ${sgbd_cur_dir}/\(.*\) \\1 sgbd_fpath ${sgbd_file}) 18 | string(REGEX REPLACE "\(.*\)/.*" \\1 sgbd_group_name ${sgbd_fpath}) 19 | string(COMPARE EQUAL ${sgbd_fpath} ${sgbd_group_name} sgbd_nogroup) 20 | string(REPLACE "/" "\\" sgbd_group_name ${sgbd_group_name}) 21 | if(sgbd_nogroup) 22 | set(sgbd_group_name "\\") 23 | endif(sgbd_nogroup) 24 | source_group(${sgbd_group_name} FILES ${sgbd_file}) 25 | endforeach(sgbd_file) 26 | endif (MSVC) 27 | endmacro(source_group_by_dir) 28 | 29 | source_group_by_dir(CMAKE_CURRENT_LIST_DIR SRC_LIST) 30 | 31 | add_definitions(-DSINGLE_MAIN) 32 | 33 | SET(EXECUTABLE_OUTPUT_PATH ../bin) 34 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) 35 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) 36 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) 37 | 38 | add_executable(aiui_demo ${SRC_LIST}) 39 | -------------------------------------------------------------------------------- /websocket/c/README.txt: -------------------------------------------------------------------------------- 1 | 1. 仅适配 Linux 平台 2 | 2. 确保平台已开通语义功能且关闭白名单 3 | 3. 修改代码中的 appid 和 key -------------------------------------------------------------------------------- /websocket/c/bin/test.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/websocket/c/bin/test.pcm -------------------------------------------------------------------------------- /websocket/c/src/aiui/aiui_base64.h: -------------------------------------------------------------------------------- 1 | #ifndef BASE64__H 2 | #define BASE64__H 3 | 4 | /** 5 | * encode an array of bytes using Base64 (RFC 3548) 6 | * 7 | * @param source the source buffer 8 | * @param sourcelen the length of the source buffer 9 | * @param target the target buffer 10 | * @param targetlen the length of the target buffer 11 | * @return 1 on success, 0 otherwise 12 | */ 13 | int aiui_base64_encode(unsigned char *source, size_t sourcelen, char *target, size_t targetlen); 14 | 15 | /** 16 | * decode base64 encoded data 17 | * 18 | * @param source the encoded data (zero terminated) 19 | * @param target pointer to the target buffer 20 | * @param targetlen length of the target buffer 21 | * @return length of converted data on success, -1 otherwise 22 | */ 23 | size_t aiui_base64_decode(char *source, unsigned char *target, size_t targetlen); 24 | 25 | #endif -------------------------------------------------------------------------------- /websocket/c/src/aiui/aiui_platform_util.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file platform_util.h 3 | * 4 | * \brief Common and shared functions used by multiple modules in the Mbed TLS 5 | * library. 6 | */ 7 | /* 8 | * Copyright (C) 2018, Arm Limited, All Rights Reserved 9 | * SPDX-License-Identifier: Apache-2.0 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 12 | * not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | * This file is part of Mbed TLS (https://tls.mbed.org) 24 | */ 25 | #ifndef AIUI_MBEDTLS_PLATFORM_UTIL_H 26 | #define AIUI_MBEDTLS_PLATFORM_UTIL_H 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * \brief Securely zeroize a buffer 36 | * 37 | * The function is meant to wipe the data contained in a buffer so 38 | * that it can no longer be recovered even if the program memory 39 | * is later compromised. Call this function on sensitive data 40 | * stored on the stack before returning from a function, and on 41 | * sensitive data stored on the heap before freeing the heap 42 | * object. 43 | * 44 | * It is extremely difficult to guarantee that calls to 45 | * mbedtls_platform_zeroize() are not removed by aggressive 46 | * compiler optimizations in a portable way. For this reason, Mbed 47 | * TLS provides the configuration option 48 | * MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure 49 | * mbedtls_platform_zeroize() to use a suitable implementation for 50 | * their platform and needs 51 | * 52 | * \param buf Buffer to be zeroized 53 | * \param len Length of the buffer in bytes 54 | * 55 | */ 56 | void mbedtls_platform_zeroize( void *buf, size_t len ); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* AIUI_MBEDTLS_PLATFORM_UTIL_H */ 63 | -------------------------------------------------------------------------------- /websocket/c/src/aiui_extern.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | aiui_init_pthread_attr(pthread_attr_t *attr, int size) 4 | { 5 | pthread_attr_init(attr); 6 | pthread_attr_setstacksize(attr, size); 7 | } 8 | 9 | void aiui_destroy_pthread_attr(pthread_attr_t *attr) 10 | { 11 | pthread_attr_destroy(attr); 12 | } -------------------------------------------------------------------------------- /websocket/c/src/aiui_platform_util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Common and shared functions used by multiple modules in the Mbed TLS 3 | * library. 4 | * 5 | * Copyright (C) 2018, Arm Limited, All Rights Reserved 6 | * SPDX-License-Identifier: Apache-2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 9 | * not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 16 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is part of Mbed TLS (https://tls.mbed.org) 21 | */ 22 | 23 | #if !defined(AIUI_MBEDTLS_CONFIG_FILE) 24 | #include "aiui/aiui_config.h" 25 | #else 26 | #include AIUI_MBEDTLS_CONFIG_FILE 27 | #endif 28 | 29 | #include "aiui/aiui_platform_util.h" 30 | 31 | #include 32 | #include 33 | 34 | #if !defined(AIUI_MBEDTLS_PLATFORM_ZEROIZE_ALT) 35 | /* 36 | * This implementation should never be optimized out by the compiler 37 | * 38 | * This implementation for mbedtls_platform_zeroize() was inspired from Colin 39 | * Percival's blog article at: 40 | * 41 | * http://www.daemonology.net/blog/2014-09-04-how-to-zero-a-buffer.html 42 | * 43 | * It uses a volatile function pointer to the standard memset(). Because the 44 | * pointer is volatile the compiler expects it to change at 45 | * any time and will not optimize out the call that could potentially perform 46 | * other operations on the input buffer instead of just setting it to 0. 47 | * Nevertheless, as pointed out by davidtgoldblatt on Hacker News 48 | * (refer to http://www.daemonology.net/blog/2014-09-05-erratum.html for 49 | * details), optimizations of the following form are still possible: 50 | * 51 | * if( memset_func != memset ) 52 | * memset_func( buf, 0, len ); 53 | * 54 | * Note that it is extremely difficult to guarantee that 55 | * mbedtls_platform_zeroize() will not be optimized out by aggressive compilers 56 | * in a portable way. For this reason, Mbed TLS also provides the configuration 57 | * option AIUI_MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure 58 | * mbedtls_platform_zeroize() to use a suitable implementation for their 59 | * platform and needs. 60 | */ 61 | static void * (* const volatile memset_func)( void *, int, size_t ) = memset; 62 | 63 | void mbedtls_platform_zeroize( void *buf, size_t len ) 64 | { 65 | memset_func( buf, 0, len ); 66 | } 67 | #endif /* AIUI_MBEDTLS_PLATFORM_ZEROIZE_ALT */ 68 | -------------------------------------------------------------------------------- /websocket/go/aiui_websocket_demo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "golang.org/x/net/websocket" 6 | "io/ioutil" 7 | "strconv" 8 | "time" 9 | "net/http" 10 | "encoding/base64" 11 | "crypto/md5" 12 | ) 13 | 14 | // 数据结束发送标记 15 | const BREAK_FLAG = "--end--" 16 | // 每帧数据大小,单位:字节 17 | const SLICE_SIZE = 1280 18 | // AIUI websocket服务地址 19 | const WS_URL = "ws://wsapi.xfyun.cn/v1/aiui" 20 | const ORIGIN = "http://wsapi.xfyun.cn" 21 | // 应用ID,在AIUI开放平台创建并设置 22 | const APPID = "" 23 | // 接口密钥,在AIUI开放平台查看 24 | const API_KEY = "" 25 | // 发送的数据文件位置 26 | const FILE_PATH = "date.pcm" 27 | 28 | // 调用方式:运行 main(),控制台输出云端返回结果 29 | func main() { 30 | curtime := strconv.Itoa(int(time.Now().Unix())) 31 | param := `{"auth_id":"2894c985bf8b1111c6728db79d3479ae","data_type":"audio","aue":"raw","scene":"main","sample_rate":"16000"}` 32 | paramBase64 := base64.URLEncoding.EncodeToString([]byte(param)) 33 | checksum := Md5Encode(API_KEY + curtime + paramBase64) 34 | // websocket 握手 35 | url := WS_URL + "?appid=" + APPID + "&checksum=" + checksum + "&curtime=" + curtime + "¶m=" + paramBase64 36 | config, _ := websocket.NewConfig(url, ORIGIN) 37 | config.Protocol = []string{"13"} 38 | header := make(map[string][] string) 39 | header["X-Real-Ip"] = []string{"114.116.69.134"} 40 | config.Header = http.Header(header) 41 | conn, err := websocket.DialConfig(config) 42 | if err != nil { 43 | fmt.Errorf("websocket dial err: %v", err) 44 | return 45 | } 46 | defer conn.Close() 47 | 48 | sendChan := make(chan int, 1) 49 | receiveChan := make(chan int, 1) 50 | defer close(sendChan) 51 | defer close(receiveChan) 52 | // 发送数据 53 | go send(conn, sendChan) 54 | // 接收数据 55 | go receive(conn, receiveChan) 56 | <-sendChan 57 | <-receiveChan 58 | return 59 | } 60 | 61 | // 发送数据 62 | func send(conn *websocket.Conn, sendChan chan int) { 63 | // 分帧发送音频数据 64 | audio1, _ := ioutil.ReadFile(FILE_PATH) 65 | if err := sendBySlice(conn, audio1); err != nil { 66 | fmt.Errorf("send data err: %v", err) 67 | sendChan <- 1 68 | return 69 | } 70 | // 发送结束符 71 | if err := websocket.Message.Send(conn, BREAK_FLAG); err != nil { 72 | fmt.Errorf("send break flag err: %v", err) 73 | sendChan <- 1 74 | return 75 | } 76 | 77 | sendChan <- 1 78 | return 79 | } 80 | 81 | // 分片发送数据 82 | func sendBySlice(conn *websocket.Conn, data []byte) (err error) { 83 | sliceNum := getSliceNum(len(data), SLICE_SIZE) 84 | for i := 0; i < sliceNum; i++ { 85 | var sliceData []byte 86 | if (i+1)*SLICE_SIZE < len(data) { 87 | sliceData = data[i*SLICE_SIZE : (i+1)*SLICE_SIZE] 88 | } else { 89 | sliceData = data[i*SLICE_SIZE:] 90 | } 91 | if err = websocket.Message.Send(conn, sliceData); err != nil { 92 | fmt.Errorf("send msg err: %v", err) 93 | return err 94 | } 95 | time.Sleep(time.Duration(40 * time.Millisecond)) 96 | } 97 | return nil 98 | } 99 | 100 | // 接收结果 101 | func receive(conn *websocket.Conn, readChan chan int) { 102 | for { 103 | var msg string 104 | if err := websocket.Message.Receive(conn, &msg); err != nil { 105 | if err.Error() == "EOF" { 106 | fmt.Println("receive msg end") 107 | }else{ 108 | fmt.Errorf("receive msg error: %v", msg) 109 | } 110 | readChan <- 1 111 | return 112 | } 113 | fmt.Println("receive msg: %v", msg) 114 | } 115 | readChan <- 1 116 | } 117 | 118 | // 计算数据帧数 119 | func getSliceNum(dataSize, sliceSize int) int { 120 | if dataSize%sliceSize == 0 { 121 | return dataSize / sliceSize 122 | } else { 123 | return dataSize/sliceSize + 1 124 | } 125 | } 126 | 127 | // 计算字符串MD5值 128 | func Md5Encode(str string) (strMd5 string) { 129 | strByte := []byte(str) 130 | strMd5Byte := md5.Sum(strByte) 131 | strMd5 = fmt.Sprintf("%x", strMd5Byte) 132 | return strMd5 133 | } -------------------------------------------------------------------------------- /websocket/java/lib/Java-WebSocket-1.3.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/websocket/java/lib/Java-WebSocket-1.3.7.jar -------------------------------------------------------------------------------- /websocket/java/lib/commons-codec-1.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/websocket/java/lib/commons-codec-1.6.jar -------------------------------------------------------------------------------- /websocket/java/src/com/iflytek/aiui/websocketdemo/DraftWithOrigin.java: -------------------------------------------------------------------------------- 1 | package com.iflytek.aiui.websocketdemo; 2 | 3 | import org.java_websocket.drafts.Draft; 4 | import org.java_websocket.drafts.Draft_6455; 5 | import org.java_websocket.handshake.ClientHandshakeBuilder; 6 | 7 | public class DraftWithOrigin extends Draft_6455 { 8 | 9 | private String originUrl; 10 | 11 | public DraftWithOrigin(String originUrl) { 12 | this.originUrl = originUrl; 13 | } 14 | 15 | @Override 16 | public Draft copyInstance() { 17 | System.out.println(originUrl); 18 | return new DraftWithOrigin(originUrl); 19 | } 20 | 21 | @Override 22 | public ClientHandshakeBuilder postProcessHandshakeRequestAsClient( ClientHandshakeBuilder request) { 23 | super.postProcessHandshakeRequestAsClient(request); 24 | request.put("Origin", originUrl); 25 | return request; 26 | } 27 | } -------------------------------------------------------------------------------- /websocket/js/aiui-websocket-demo.js: -------------------------------------------------------------------------------- 1 | var crypto = require('crypto'); 2 | var WebSocketClient = require('websocket').client; 3 | var fs = require('fs'); 4 | 5 | // AIUI websocket服务地址 6 | var BASE_URL = "wss://wsapi.xfyun.cn/v1/aiui"; 7 | var ORIGIN = "http://wsapi.xfyun.cn"; 8 | // 应用ID,在AIUI开放平台创建并设置 9 | var APPID = "xxxx"; 10 | // 接口密钥,在AIUI开放平台查看 11 | var APIKEY = "xxxx"; 12 | // 业务参数 13 | var PARAM = "{\"auth_id\":\"f8948af1d2d6547eaf09bc2f20ebfcc6\",\"data_type\":\"audio\",\"scene\":\"main_box\",\"sample_rate\":\"16000\",\"aue\":\"raw\",\"result_level\":\"plain\",\"context\":\"{\\\"sdk_support\\\":[\\\"tts\\\"]}\"}"; 14 | 15 | // 计算握手参数 16 | function getHandshakeParams(){ 17 | var paramBase64 = new Buffer(PARAM).toString('base64'); 18 | var curtime = Math.floor(Date.now()/1000); 19 | var originStr = APIKEY + curtime + paramBase64; 20 | var checksum = crypto.createHash('md5').update(originStr).digest("hex"); 21 | var handshakeParams = "?appid="+APPID+"&checksum="+checksum+"&curtime="+curtime+"¶m="+paramBase64; 22 | console.log(handshakeParams); 23 | return handshakeParams; 24 | } 25 | 26 | // 定义websocket client 27 | var client = new WebSocketClient(); 28 | 29 | client.on('connectFailed', function(error) { 30 | console.log('Connect Error: ' + error.toString()); 31 | }); 32 | 33 | client.on('connect', function(connection) { 34 | console.log('WebSocket client connected'); 35 | connection.on('error', function(error) { 36 | console.log("Connection Error: " + error.toString()); 37 | }); 38 | connection.on('close', function() { 39 | console.log('echo-protocol Connection Closed'); 40 | }); 41 | connection.on('message', function(message) { 42 | if (message.type === 'utf8') { 43 | console.log("Received: '" + message.utf8Data + "'"); 44 | } 45 | }); 46 | 47 | function sendMsg() { 48 | if (connection.connected) { 49 | 50 | let audioFile = fs.createReadStream('./weather.pcm'); 51 | let idx = 0; 52 | 53 | audioFile.on("data", function(data) { 54 | console.log("发送音频块 ", idx++); 55 | 56 | connection.sendBytes(data); 57 | }); 58 | 59 | audioFile.on("close", function() { 60 | connection.sendUTF("--end--"); 61 | }); 62 | } 63 | } 64 | // 发送数据 65 | sendMsg(); 66 | }); 67 | 68 | // 建立连接 69 | client.connect(BASE_URL+getHandshakeParams(), "", ORIGIN); -------------------------------------------------------------------------------- /websocket/js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "websocket": "^1.0.34" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /websocket/js/weather.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/websocket/js/weather.pcm -------------------------------------------------------------------------------- /websocket/python/weather.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IflytekAIUI/DemoCode/414da5f64b7834cfc27e803b185be62fb7db1100/websocket/python/weather.pcm --------------------------------------------------------------------------------