#575,解决,Al 安卓 文心一言 手表端不输出结果,手机输出结果bug,原因为文件路径不存在问题 992/4 992/head
authorluozheng <1732036298@qq.com>
Sat, 21 Sep 2024 03:23:00 +0000 (11:23 +0800)
committerluozheng <1732036298@qq.com>
Sat, 21 Sep 2024 03:23:00 +0000 (11:23 +0800)
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp

index ded12eb..d5110ac 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:14:43
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-09-07 11:14:50
+ * @LastEditTime: 2024-09-21 11:07:14
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
  */
 #ifndef AI_VOICE_MODEL_H
@@ -102,6 +102,8 @@ namespace OHOS
         int GetSelectAiModel(void);
         int GetAiModelTextId(void);
 
+        bool CreateDirectory(const char* path);
+
     private:
         AiVoiceModel();
         ~AiVoiceModel();
index cd0f1fd..d2ce77f 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:14:50
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-09-07 17:08:17
+ * @LastEditTime: 2024-09-21 11:13:21
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
  */
 #include "aivoice/include/AiVoiceModel.h"
@@ -24,6 +24,8 @@
 #include <unistd.h>
 #include "ConfigModel.h"
 #include "settings/include/SettingModel.h"
+#include <unistd.h>
+#include <sys/stat.h>
 namespace OHOS
 {
     // 声明定时器变量
@@ -32,7 +34,10 @@ namespace OHOS
     static int Time = THIRTY_TIME;
     static int AiModelConnectTimeout = 5;
 
-    AiVoiceModel::AiVoiceModel() {}
+    AiVoiceModel::AiVoiceModel() 
+    {
+        CreateDirectory("/user/userdata/AiRecording/");
+    }
 
     AiVoiceModel::~AiVoiceModel() {}
 
@@ -42,6 +47,20 @@ namespace OHOS
         return instance;
     }
 
+    bool AiVoiceModel::CreateDirectory(const char* path)
+    {
+        if (access(path, F_OK) == -1) {  // 如果路径不存在
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Directory %s not exist, creating directory\n", path);
+            if (mkdir(path, 0777)!= 0) {  // 尝试创建目录,如果创建失败
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Create directory %s failed\n", path);
+                return false;
+            }
+        } else {  // 如果路径存在
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Directory %s already exists\n", path);
+        }
+        return true;
+    }
+
     // 跳转到返回结果界面
     bool AiVoiceModel::ChangeToReturnResultTextView(void)
     {