AI 九天大模型代码合并,待测试
authorluozheng <1732036298@qq.com>
Thu, 22 May 2025 02:14:46 +0000 (10:14 +0800)
committerluozheng <1732036298@qq.com>
Thu, 22 May 2025 02:14:46 +0000 (10:14 +0800)
13 files changed:
code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/ui_resource_string.h
code/sdk/application/wearable/fd230/nativeapp/nativeui/aivoice/include/AiVoicePresenter.h
code/sdk/application/wearable/fd230/nativeapp/nativeui/aivoice/include/AiVoiceView.h
code/sdk/application/wearable/fd230/nativeapp/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/aivoice/src/AiVoiceModel.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/aivoice/src/AiVoiceView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp
code/sdk/files/fd230/fs/user/res/AIVoice/aimodels/aimodels_lingxi.bin [new file with mode: 0644]
code/sdk/files/fd230/fs/user/res/AIVoice/aimodels/aimodes_deepseek.bin [new file with mode: 0644]
code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp
code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.h

index 7127be4..58639fb 100644 (file)
@@ -1,15 +1,15 @@
-/*
-* Copyright (c) xxxxxxxx Technologies Co., Ltd. 2021-2021. All rights reserved.
-* Description: language
-* Author: Graphic develop team
-* Create: 2021-07-06
-*/
-
-#ifndef UI_RESOURCE_STRING_H
-#define UI_RESOURCE_STRING_H
-#include <cstdint>
-namespace OHOS {
-enum UIResourceTextId : uint16_t {
+/*\r
+* Copyright (c) xxxxxxxx Technologies Co., Ltd. 2021-2021. All rights reserved.\r
+* Description: language\r
+* Author: Graphic develop team\r
+* Create: 2021-07-06\r
+*/\r
+\r
+#ifndef UI_RESOURCE_STRING_H\r
+#define UI_RESOURCE_STRING_H\r
+#include <cstdint>\r
+namespace OHOS {\r
+enum UIResourceTextId : uint16_t {\r
     STR_EXERCISE_OUTDOORWALKING = 0,\r
     STR_EXERCISE_OUTDOORRUNNING = 1,\r
     STR_EXERCISE_OUTDOORBIKING = 2,\r
@@ -652,10 +652,11 @@ enum UIResourceTextId : uint16_t {
     STR_RECORD_MAX = 639,\r
     STR_CLEAR_ALL_RECORDS = 640,\r
     STR_DEEPSEEK = 641,\r
-    STR_MAX_ID = 642,\r
+    STR_AIMODES_LINGXI = 642,\r
+    STR_MAX_ID = 643,\r
 }; // UIResourceTextId\r
-
-enum FontLanguageId : uint8_t {
+\r
+enum FontLanguageId : uint8_t {\r
     LANGUAGE_ID_AR,\r
     LANGUAGE_ID_AZ,\r
     LANGUAGE_ID_CS,\r
index ede8f78..2b162ea 100644 (file)
@@ -32,7 +32,7 @@ namespace OHOS
             AIMODES_KIMI,            /*KIMI*/
             AIMODES_DOUBAO,          /*豆包*/
             AIMODES_TONGYI_QIANWEN,  /*通义千问->DeepSeek*/
-            AIMODES_IFLYTEK_SPARK,   /*讯飞星火*/
+            AIMODES_IFLYTEK_SPARK,   /*讯飞星火->lingxi*/
             AIMODES_CHATGPT,         /*chatgpt*/
             AIMODES_MAX_NUM,
         } aimodels;
index 9961640..fc65f55 100644 (file)
@@ -39,6 +39,7 @@ namespace OHOS
     static constexpr const char *AIMODEL_TONGYI_QIANWEN_PATH = "/user/res/AIVoice/aimodels/aimodes_tongyi_qianwen.bin"; /*通义千问*/
     static constexpr const char *AIMODEL_IFLYTEK_SPARK_PATH = "/user/res/AIVoice/aimodels/aimodes_iflytek_spark.bin";   /*讯飞星火*/
     static constexpr const char *AIMODEL_DEEPSEEK_PATH = "/user/res/AIVoice/aimodels/aimodes_deepseek.bin";             /*deepseek*/
+    static constexpr const char *AIMODEL_LINGXI_PATH = "/user/res/AIVoice/aimodels/aimodels_lingxi.bin";                /*lingxi*/
 
     /*组件ID*/
     static constexpr const char *AIVOICE_START_CHAT_BUTTON_VIEW_ID = "aivoice_start_chat_button_view_id"; // 开始对话
@@ -69,7 +70,8 @@ namespace OHOS
         {STR_AIMODELS_DOUBAO, AIMODEL_DOUBAO_PATH},
         // {STR_TONGYI_QIANWEN, AIMODEL_TONGYI_QIANWEN_PATH},
         {STR_DEEPSEEK, AIMODEL_DEEPSEEK_PATH},
-        {STR_IFLYTEK_SPARK, AIMODEL_IFLYTEK_SPARK_PATH},
+        // {STR_IFLYTEK_SPARK, AIMODEL_IFLYTEK_SPARK_PATH},
+        {STR_AIMODES_LINGXI, AIMODEL_LINGXI_PATH},
         {STR_AIMODES_CHATGPT, AIMODEL_CHATGPT_ON_PATH},
     };
 
index 42f9829..37c2407 100644 (file)
@@ -11,6 +11,7 @@
 #include "wearable_log.h"
 #include "ui_resource_string.h"
 #include <UiConfig.h>
+#include "ConfigModel.h"
 namespace OHOS
 {
 
@@ -92,8 +93,19 @@ namespace OHOS
         //TOOD: 待优化
         if(labelconfig.textId == STR_DEEPSEEK) {
             label->SetText("DeepSeek");
-        } else
+        }else if(labelconfig.textId == STR_AIMODES_LINGXI) {
+            int language = ConfigModel::GetInstance()->GetLanguage();
+            if (language == 0) // 如果当前系统为中文
+            {
+                label->SetText("九天大模型");
+            }
+            else
+            {
+                label->SetText("jiutian");
+            }
+        } else{
             label->SetTextId(labelconfig.textId);
+        }
         label->SetLineBreakMode(labelconfig.lineBreakMode);
         label->SetRollSpeed(23);
         label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
@@ -278,15 +290,23 @@ namespace OHOS
     {
         if (title)
         {
-            if(textId == STR_DEEPSEEK) 
-            {
+            if(textId == STR_DEEPSEEK) {
                 title->SetText("DeepSeek");
-            } 
-            else 
-            {
-            title->SetTextId(textId);
-            title->ForceResetText();
+             }else if(textId == STR_AIMODES_LINGXI) {
+                int language = ConfigModel::GetInstance()->GetLanguage();
+                if (language == 0) // 如果当前系统为中文
+                {
+                    title->SetText("九天大模型");
+                }
+                else
+                {
+                    title->SetText("jiutian");
+                }
+            } else{
+                title->SetTextId(textId);
             }
+
+            title->ForceResetText();
         }
     }
 
index 2da9b74..8bcb8ae 100644 (file)
@@ -179,7 +179,8 @@ namespace OHOS
     }
 
     // 获取当前正在使用的AI模型
-    uint8_t AiVoiceModel::GetCurUsingAiModelType(void){
+    uint8_t AiVoiceModel::GetCurUsingAiModelType(void)
+    {
     
         auto it = selectAiModelToTextId.find(GetSelectAiModel());
         if (it != selectAiModelToTextId.end())
@@ -193,9 +194,7 @@ namespace OHOS
     void AiVoiceModel::CancelCurAIChat(void)
     {
         // cancel_AI_cur_chat(); //线程发送取消当前对话
-        #ifdef SUPPORT_BLE_SERVICE
         cancel_AI_cur_chat_();// 直接发送取消当前对话
-        #endif
     }
 
     int AiVoiceModel::GetAIResponseType(void)
@@ -499,7 +498,7 @@ namespace OHOS
         if (!entryTextViewState)
         {
             #ifdef SUPPORT_BLE_SERVICE
-            //SendMsgToUIService(UI_AI_JUMP_TO_RESULT_VIEW, 0, nullptr, 0);
+            SendMsgToUIService(UI_AI_JUMP_TO_RESULT_VIEW, 0, nullptr, 0);
             #endif
             entryTextViewState = true; // 进入返回结果界面的标志  避免重复发消息
             usleep(50000);             // 延时等待创建完成,0.05秒
@@ -510,7 +509,7 @@ namespace OHOS
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "拼接的问题:%s",userQuestionStr.c_str());
         /* -------------------------------------------------------------------------- */
         #ifdef SUPPORT_BLE_SERVICE
-        //SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0);
+        SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0);
         #endif
     }
 
@@ -526,7 +525,9 @@ namespace OHOS
     void AiVoiceModel::SetAiAnswerStrStr(std::string str)
     {
         aiAnswerStr += str;
-        //SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
+        #ifdef SUPPORT_BLE_SERVICE
+        SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
+        #endif
     }
 
     void AiVoiceModel::SetAiAnswerStrStr(std::string str, uint8_t type)
@@ -538,7 +539,9 @@ namespace OHOS
         if (AIResponseType == AiVoiceModel::AI_RECORDING_PARSING_ERROR || AIResponseType == AiVoiceModel::AI_RESPONSE_ERROR 
             || AIResponseType == AiVoiceModel::AI_BLE_ERROR)
         {
-            //SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)errnote.c_str(), errnote.length());
+            #ifdef SUPPORT_BLE_SERVICE
+            SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)errnote.c_str(), errnote.length());
+            #endif
             return;
         }
         else if (AiVoiceModel::AI_RESPONSE_END) // 如果是AI 回应结束
@@ -548,7 +551,9 @@ namespace OHOS
                 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::GetErrnote is empty!!");
                 AiVoiceModel::GetInstance().SetErrnote("响应内容为空");
                 std::string str = AiVoiceModel::GetInstance().GetErrnote();
-                //SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
+                #ifdef SUPPORT_BLE_SERVICE
+                SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
+                #endif
                 return;
             }
         }
@@ -561,7 +566,9 @@ namespace OHOS
                 { 
                     aiAnswerStr += str;
                     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
-                    //SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
+                    #ifdef SUPPORT_BLE_SERVICE
+                    SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
+                    #endif
                 }
             }
         }
@@ -609,8 +616,7 @@ namespace OHOS
             int type = GetCurUsingAiModelType();
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "type = %d", type);
             #ifdef SUPPORT_BLE_SERVICE
-            // streamingRecordAndSend_AI(type);//实时发送录音数据
-            #endif
+            streamingRecordAndSend_AI(type);//实时发送录音数据
 #else
             std::string audioPath = AiVoiceModel::GetInstance().GetAIAudioPath();
             if (uapi_delete_files(audioPath.c_str())) // 先删除文件
@@ -630,6 +636,7 @@ namespace OHOS
 #endif
             uapi_save_runtime_log(RUNTIME_LOG_RECORD_START_AI);//TOOD*
             AudioCaptureSample(6, (const char **)defaultArgs);            
+#endif
 #endif
         }
         return;
@@ -736,7 +743,9 @@ namespace OHOS
             AiVoiceModel::GetInstance().AIVoice_StopTimer();
             AiVoiceModel::GetInstance().SetErrnote("连接超时,请重新开始对话");
             std::string str = AiVoiceModel::GetInstance().GetErrnote();
-            //SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
+            #ifdef SUPPORT_BLE_SERVICE
+            SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
+            #endif
         }
         else
         {
@@ -747,7 +756,9 @@ namespace OHOS
             {
                 AiVoiceModel::GetInstance().SetErrnote("手机蓝牙已断开");
                 std::string str = AiVoiceModel::GetInstance().GetErrnote();
-                // SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
+                #ifdef SUPPORT_BLE_SERVICE
+                SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
+                #endif
             }
             #endif
         }
@@ -1107,7 +1118,8 @@ namespace OHOS
                 {2, {STR_AIMODELS_DOUBAO, 3}},
                 // {3, {STR_TONGYI_QIANWEN, 4}},
                 {3, {STR_DEEPSEEK, 4}},
-                {4, {STR_IFLYTEK_SPARK, 5}},
+                // {4, {STR_IFLYTEK_SPARK, 5}},
+                {4, {STR_AIMODES_LINGXI, 5}},
                 {5, {STR_AIMODES_CHATGPT, 1}},
             };
             textId = STR_AIMODES_WENXINYIYAN;
@@ -1121,7 +1133,8 @@ namespace OHOS
                 {3, {STR_AIMODELS_DOUBAO, 3}},
                 // {4, {STR_TONGYI_QIANWEN, 4}},
                 {4, {STR_DEEPSEEK, 4}},
-                {5, {STR_IFLYTEK_SPARK, 5}},
+                // {5, {STR_IFLYTEK_SPARK, 5}},
+                {5, {STR_AIMODES_LINGXI, 5}},
             };
             textId = STR_AIMODES_CHATGPT;
         }
@@ -1134,7 +1147,8 @@ namespace OHOS
             {2, {STR_AIMODELS_DOUBAO, 3}},
             {3, {STR_AIMODES_WENXINYIYAN, 0}},
             {4, {STR_AIMODES_KIMI, 2}},
-            {5, {STR_IFLYTEK_SPARK, 5}},
+            // {5, {STR_IFLYTEK_SPARK, 5}},
+            {5, {STR_AIMODES_LINGXI, 5}},
         };
         textId = STR_DEEPSEEK;
 
index 92f05db..e5922c9 100644 (file)
@@ -157,8 +157,19 @@ namespace OHOS
         //TOOD: 待优化
         if(labelconfig.textId == STR_DEEPSEEK) {
             label->SetText("DeepSeek");
-        } else
+        }else if(labelconfig.textId == STR_AIMODES_LINGXI) {
+            int language = ConfigModel::GetInstance()->GetLanguage();
+            if (language == 0) // 如果当前系统为中文
+            {
+                label->SetText("九天大模型");
+            }
+            else
+            {
+                label->SetText("jiutian");
+            }
+        } else{
             label->SetTextId(labelconfig.textId);
+        }
         label->SetLineBreakMode(labelconfig.lineBreakMode);
         label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         label->SetRollSpeed(23);
@@ -409,9 +420,11 @@ namespace OHOS
             aiModelPicker->SetRotateFactor(1.0);
             aiModelPicker->RequestFocus();
             aiModelPicker->RegisterSelectedListener(presenter_);
-            aiModelPicker->SetTextColor(Color::GetColorFromRGBA(0x00, 0x00, 0x00, 0xff), Color::GetColorFromRGBA(0xff, 0x00, 0x00, 0xff));
+            // 设置文本颜色为透明
+            aiModelPicker->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x00), Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x00));
             const char *uiPicker1Data[] = {"0", "1", "2", "3", "4", "5"};
             aiModelPicker->SetValues(uiPicker1Data, sizeof(uiPicker1Data) / sizeof(uiPicker1Data[0]));
+            // aiModelPicker->SetVisible(false);//屏蔽picker组件
         }
 
         return true;
@@ -902,15 +915,23 @@ namespace OHOS
         int textId = AiVoiceModel::GetInstance().GetAiModelTextId();
         if (title)
         {
-            if(textId == STR_DEEPSEEK) 
-            {
+            if(textId == STR_DEEPSEEK) {
                 title->SetText("DeepSeek");
-            } 
-            else 
-            {
-            title->SetTextId(textId);
-            title->ForceResetText();
+             }else if(textId == STR_AIMODES_LINGXI) {
+                int language = ConfigModel::GetInstance()->GetLanguage();
+                if (language == 0) // 如果当前系统为中文
+                {
+                    title->SetText("九天大模型");
+                }
+                else
+                {
+                    title->SetText("jiutian");
+                }
+            } else{
+                title->SetTextId(textId);
             }
+
+            title->ForceResetText();
         }
         if (aiModelImage)
         {
index babb779..517752f 100644 (file)
@@ -11,6 +11,7 @@
 #include "wearable_log.h"
 #include "ui_resource_string.h"
 #include <UiConfig.h>
+#include "ConfigModel.h"
 namespace OHOS
 {
     static constexpr const int16_t LABEL_ROLL_SPEED = 70;
@@ -84,8 +85,19 @@ namespace OHOS
         //TOOD: 待优化
         if(labelconfig.textId == STR_DEEPSEEK) {
             label->SetText("DeepSeek");
-        } else
+         }else if(labelconfig.textId == STR_AIMODES_LINGXI) {
+            int language = ConfigModel::GetInstance()->GetLanguage();
+            if (language == 0) // 如果当前系统为中文
+            {
+                label->SetText("九天大模型");
+            }
+            else
+            {
+                label->SetText("jiutian");
+            }
+        } else{
             label->SetTextId(labelconfig.textId);
+        }
         label->SetLineBreakMode(labelconfig.lineBreakMode);
         label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize);
@@ -269,15 +281,23 @@ namespace OHOS
     {
         if (title)
         {
-            if(textId == STR_DEEPSEEK) 
-            {
+            if(textId == STR_DEEPSEEK) {
                 title->SetText("DeepSeek");
-            } 
-            else 
-            {
-            title->SetTextId(textId);
-            title->ForceResetText();
+             }else if(textId == STR_AIMODES_LINGXI) {
+                int language = ConfigModel::GetInstance()->GetLanguage();
+                if (language == 0) // 如果当前系统为中文
+                {
+                    title->SetText("九天大模型");
+                }
+                else
+                {
+                    title->SetText("jiutian");
+                }
+            } else{
+                title->SetTextId(textId);
             }
+
+            title->ForceResetText();
         }
     }
 
index 554cab8..4f96464 100644 (file)
@@ -11,6 +11,7 @@
 #include "wearable_log.h"
 #include "ui_resource_string.h"
 #include <UiConfig.h>
+#include "ConfigModel.h"
 namespace OHOS
 {
 
@@ -89,11 +90,22 @@ namespace OHOS
         label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height);
         label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize);
         label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh);
-        //TOOD: 待优化
-        if(labelconfig.textId == STR_DEEPSEEK) {
+         //TOOD: 待优化
+         if(labelconfig.textId == STR_DEEPSEEK) {
             label->SetText("DeepSeek");
-        } else
+        }else if(labelconfig.textId == STR_AIMODES_LINGXI) {
+            int language = ConfigModel::GetInstance()->GetLanguage();
+            if (language == 0) // 如果当前系统为中文
+            {
+                label->SetText("九天大模型");
+            }
+            else
+            {
+                label->SetText("jiutian");
+            }
+        } else{
             label->SetTextId(labelconfig.textId);
+        }
         label->SetLineBreakMode(labelconfig.lineBreakMode);
         label->SetRollSpeed(23);
         label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
@@ -279,15 +291,23 @@ namespace OHOS
     {
         if (title)
         {
-            if(textId == STR_DEEPSEEK) 
-            {
+            if(textId == STR_DEEPSEEK) {
                 title->SetText("DeepSeek");
-            } 
-            else 
-            {
-            title->SetTextId(textId);
-            title->ForceResetText();
+             }else if(textId == STR_AIMODES_LINGXI) {
+                int language = ConfigModel::GetInstance()->GetLanguage();
+                if (language == 0) // 如果当前系统为中文
+                {
+                    title->SetText("九天大模型");
+                }
+                else
+                {
+                    title->SetText("jiutian");
+                }
+            } else{
+                title->SetTextId(textId);
             }
+
+            title->ForceResetText();
         }
     }
 }
\ No newline at end of file
index 0d5611b..1e0b85d 100644 (file)
@@ -13,7 +13,7 @@
 #include <UiConfig.h>
 #include <iostream>
 #include "string"
-
+#include "ConfigModel.h"
 namespace OHOS
 {
 
@@ -129,8 +129,19 @@ namespace OHOS
         //TOOD: 待优化
         if(labelconfig.textId == STR_DEEPSEEK) {
             label->SetText("DeepSeek");
-        } else
+        }else if(labelconfig.textId == STR_AIMODES_LINGXI) {
+            int language = ConfigModel::GetInstance()->GetLanguage();
+            if (language == 0) // 如果当前系统为中文
+            {
+                label->SetText("九天大模型");
+            }
+            else
+            {
+                label->SetText("jiutian");
+            }
+        } else{
             label->SetTextId(labelconfig.textId);
+        }
         label->SetLineBreakMode(labelconfig.lineBreakMode);
         label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize);
@@ -353,15 +364,23 @@ namespace OHOS
     {
         if (title)
         {
-            if(textId == STR_DEEPSEEK) 
-            {
+            if(textId == STR_DEEPSEEK) {
                 title->SetText("DeepSeek");
-            } 
-            else 
-            {
-            title->SetTextId(textId);
-            title->ForceResetText();
+             }else if(textId == STR_AIMODES_LINGXI) {
+                int language = ConfigModel::GetInstance()->GetLanguage();
+                if (language == 0) // 如果当前系统为中文
+                {
+                    title->SetText("九天大模型");
+                }
+                else
+                {
+                    title->SetText("jiutian");
+                }
+            } else{
+                title->SetTextId(textId);
             }
+
+            title->ForceResetText();
         }
     }
 
diff --git a/code/sdk/files/fd230/fs/user/res/AIVoice/aimodels/aimodels_lingxi.bin b/code/sdk/files/fd230/fs/user/res/AIVoice/aimodels/aimodels_lingxi.bin
new file mode 100644 (file)
index 0000000..a1cbcf3
Binary files /dev/null and b/code/sdk/files/fd230/fs/user/res/AIVoice/aimodels/aimodels_lingxi.bin differ
diff --git a/code/sdk/files/fd230/fs/user/res/AIVoice/aimodels/aimodes_deepseek.bin b/code/sdk/files/fd230/fs/user/res/AIVoice/aimodels/aimodes_deepseek.bin
new file mode 100644 (file)
index 0000000..0c32be3
Binary files /dev/null and b/code/sdk/files/fd230/fs/user/res/AIVoice/aimodels/aimodes_deepseek.bin differ
index a7b90b2..791048a 100644 (file)
@@ -9,7 +9,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <climits>
-#include <cstdlib>
+#include <stdlib.h>
 #include <unistd.h>
 #include <sys/select.h>
 #include <sys/time.h>
@@ -41,7 +41,8 @@ using Audio::AudioInterrupt;
 using Audio::AudioManager;
 #define PLAYER_CONTROL_CMD_LEN  20
 #define READ_RETRY_TIME_US 10000
-#define READ_COUNT_MAX 1000
+// #define READ_COUNT_MAX 1000 //原
+#define READ_COUNT_MAX 17000*2 //改过的 20分钟
 #define GET_AUDIO_TIME_INTERVAL_TIMES 100
 #define MAX_ARGC 5
 
@@ -99,7 +100,8 @@ static NameAudioFormat g_audioCodecFormat[] = {
     {"g711a", G711A},
     {"aaceld", AAC_ELD},
     {"silk", SILK},
-    {"pcm", PCM}
+    {"pcm", PCM},
+    {"sbc",SBC}
 };
 
 class CaptureInterruptListener : public InterruptListener {
@@ -189,7 +191,7 @@ static void* AudioCaptureProcess(void* arg)
     fclose(pfd);
     AudioCaptureStop();
     MEDIA_INFO_LOG("AudioCaptureProcess end");
-    return nullptr;
+    return NULL;
 }
 
 static void AudioCaptureGetFormat(const char **argv, AudioCodecFormat &audioFormat)
@@ -291,6 +293,7 @@ static int32_t AudioCaptureSetInfo(SampleAudioCapturerInfo audioCapturerInfo)
 {
     AudioCapturerInfo info = {};
     ConvertCaptureInfo(info, audioCapturerInfo);
+    printf("info.audioFormat = %d\n",info.audioFormat);
     if (g_audioCap->SetCapturerInfo(info) != 0) {
         MEDIA_ERR_LOG("Can't SetCapturerInfo");
         return -1;
@@ -341,7 +344,6 @@ static int32_t ActivateAudioInterrupt(AudioSession &sessionId)
 
 static int32_t CheckInputParam(int32_t argc, const char **argv)
 {
-    MEDIA_UNUSED(argv);
     if (argc != 0x6) { // must be 6 parameters
         MEDIA_ERR_LOG("argc:%d is invalid, record start must be 6 parameters", argc);
         return -1;
@@ -414,6 +416,145 @@ EXIT:
     return -1;
 }
 
+/* ------------------------------- AI录音数据上传接口 ------------------------------- */
+#define AI_RECORD_TEST 0 //若需要调试可以打开该宏
+#include "bleService.h"
+static uint32_t AI_audio_size=0;
+static uint8_t Cur_AI_Model= 0;
+static void* AudioCaptureProcess_AI(void* arg)
+{
+    #if AI_RECORD_TEST
+    FILE *pfd = (FILE *)arg;
+    #endif 
+    int32_t readCnt = 0;
+    Timestamp timeStamp;
+    g_audioSourceProcessInput.bThreadRun = true;
+    uint8_t start_data[19]={0};
+    
+    AI_data_assembly(1,start_data, Cur_AI_Model);
+    send_msg_data_into_Ai_msg_queue((void *)start_data,19,1);
+    AI_audio_size=0;
+
+    while (!g_sample.needStop && !g_interruptHintStop) {
+        int32_t ret = g_audioCap->Read(g_audioSourceProcessInput.buffer, g_audioSourceProcessInput.framesize, false);
+        if (ret == -1) {
+            MEDIA_ERR_LOG("audioCap Read failed:0x%x", ret);
+            continue;
+        }
+        if (ret == ERR_RETRY_READ) {
+            usleep(READ_RETRY_TIME_US);
+            continue;
+        }
+        #if AI_RECORD_TEST
+        int32_t writeLen = fwrite(g_audioSourceProcessInput.buffer, 1, ret, pfd);
+        if (writeLen != ret) {
+            MEDIA_ERR_LOG("errno:%d, errmsg:%s", errno, strerror(errno));
+            break;
+        }
+        #endif
+        AI_audio_size+=ret;
+
+
+        // 蓝牙接口发送实时录音数据
+        send_msg_data_into_Ai_msg_queue((void *)g_audioSourceProcessInput.buffer,(uint16_t)ret,0);
+
+        if (readCnt++ > READ_COUNT_MAX) {
+            break;
+        }
+        #if AI_RECORD_TEST
+        if (readCnt % GET_AUDIO_TIME_INTERVAL_TIMES == 0) {
+            if (g_audioCap->GetAudioTime(timeStamp, Timestamp::Timebase::MONOTONIC)) {
+                MEDIA_INFO_LOG("read %d frames timestamp seconds:%ld, nanoseconds:%ld",
+                    readCnt, timeStamp.time.tv_sec, timeStamp.time.tv_nsec);
+            }
+        }
+        MEDIA_INFO_LOG("audioCap Read readCnt = %d, size = %d", readCnt, ret);
+        #endif
+    }
+    #if AI_RECORD_TEST
+    fclose(pfd);
+    #endif
+    MEDIA_ERR_LOG("AI_audio_size %d",AI_audio_size);
+    
+    AI_data_assembly(0,start_data,Cur_AI_Model);
+    send_msg_data_into_Ai_msg_queue((void *)start_data,19,2);
+
+
+    AudioCaptureStop();
+    MEDIA_INFO_LOG("AudioCaptureProcess end");
+    return NULL;
+}
+
+int32_t streamingRecordAndSend_AI(int type)
+{
+    const char *argv[] = {"01", "sbc", "16000", "1", "16", "/user/aiRecord.sbc"};
+    int32_t argc = 6;
+    Cur_AI_Model = type;
+    if (g_audioSourceProcessInput.bThreadRun) {
+        return HandleAudioCaptureCmd(argc, argv);
+    }
+    std::string filePath = "";
+    g_sample.needStop = false;
+    g_interruptHintStop = false;
+    g_sample.mutex = MediaMutexCreate(nullptr);
+    if (g_sample.mutex == nullptr) {
+        MEDIA_ERR_LOG("create mutex failed");
+        g_audioSourceProcessInput.bThreadRun = false;
+        return -1;
+    }
+    SampleAudioCapturerInfo audioCapturerInfo = {};
+    AudioSession sessionId = AUDIO_SESSION_ID_NONE;
+    FILE *pfd = nullptr;
+    MediaThreadattr attr = { "AudioCaptureTask", 0x2000, THREAD_SCHED_INVALID, 0, true };
+    int32_t ret = CheckInputParam(argc, argv);
+    if (ret != 0) {
+        goto EXIT;
+    }
+    ret = AudioCaptureGetInfo(argv, audioCapturerInfo, filePath);
+    if (ret != 0) {
+        goto EXIT;
+    }
+    ret = ActivateAudioInterrupt(sessionId);
+    if (ret != 0) {
+        goto EXIT;
+    }
+    g_audioCap = std::make_shared<AudioCapturer>();
+    if (g_audioCap == nullptr || g_audioCap.get() == nullptr) {
+        MEDIA_ERR_LOG("audio capture is nullptr");
+        (void)g_amInstance.DeactivateAudioInterrupt(g_sample.interrupt);
+        goto EXIT;
+    }
+    #if AI_RECORD_TEST
+    pfd = fopen(filePath.c_str(), "w+");
+    if (pfd == NULL) {
+        MEDIA_ERR_LOG("open file failed");
+        g_audioCap.reset();
+        (void)g_amInstance.DeactivateAudioInterrupt(g_sample.interrupt);
+        goto EXIT;
+    }
+    #endif
+    audioCapturerInfo.sessionID = sessionId;
+    audioCapturerInfo.inputSource = AUDIO_MIC;
+    audioCapturerInfo.streamType = AUDIO_STREAM_VOICE_RECORD;
+    ret = AudioCaptureSetInfo(audioCapturerInfo);
+    if (ret != 0) {
+        #if AI_RECORD_TEST
+        fclose(pfd);
+        #endif
+        g_audioCap.reset();
+        (void)g_amInstance.DeactivateAudioInterrupt(g_sample.interrupt);
+        goto EXIT;
+    }
+    g_sample.audioCaptureProcess = MediaThreadCreate(AudioCaptureProcess_AI, pfd, &attr);
+    if (g_sample.audioCaptureProcess == nullptr) {
+        MEDIA_ERR_LOG("thread create failed");
+        goto EXIT;
+    }
+    return 0;
+EXIT:
+    g_audioSourceProcessInput.bThreadRun = false;
+    return -1;
+}
 #ifdef __cplusplus
 };
 #endif