diff --git a/lib/core/translations/language/en_us.dart b/lib/core/translations/language/en_us.dart index 1ea125f22..a5b86bc55 100644 --- a/lib/core/translations/language/en_us.dart +++ b/lib/core/translations/language/en_us.dart @@ -305,8 +305,20 @@ const Map enUS = { "loadFailedClickRetry": "Load failed, click to retry", "swipeUpForMore": "Swipe up for more", - // Agent Controller - 'welcomeMessage': 'Hello! I\'m **XiaoYan**, I can help you:\n\n' + // Preset prompts + "presetMusic": "Play some music", // Play some music + "presetNavigation": "Navigation to", // Navigation + "presetWeather": "Today's weather", // Weather + "presetNews": "Today's news", // News + "presetFood": "Nearby food", // Food + "playSomeMusic": "Play some popular music", // 播放一些流行音乐 + "navigationTo": "Please help me navigate to", // 导航到 + "todayWeather": "How's the weather today?", // 今日天气 + "todayNews": "What's the news today?", // 今日新闻 + "nearbyFood": "What delicious food is nearby?", // 美食 + + // Agent controller + 'welcomeMessage': 'Hello! I\'m **Xiaoyan**, I can help you:\n\n' '• Answer questions and provide information\n\n' '• Real-time voice translation\n\n' '• Recommend music and podcasts\n\n' diff --git a/lib/core/translations/language/zh_cn.dart b/lib/core/translations/language/zh_cn.dart index f52ebd4ab..2dc75a89b 100644 --- a/lib/core/translations/language/zh_cn.dart +++ b/lib/core/translations/language/zh_cn.dart @@ -295,6 +295,18 @@ const Map zhCN = { "loadFailedClickRetry": "加载失败,点击重试", "swipeUpForMore": "向上滑动查看更多", + // 预设提示词 + "presetMusic": "来点音乐", // 来点音乐 + "presetNavigation": "导航到", // 导航 + "presetWeather": "今日天气", // 今日天气 + "presetNews": "今日新闻", // 今日新闻 + "presetFood": "附近美食", // 美食 + "playSomeMusic": "播放一些流行音乐", // 播放一些流行音乐 + "navigationTo": "请帮我导航到", // 导航到 + "todayWeather": "今天天气如何?", // 今日天气 + "todayNews": "今天有哪些新闻?", // 今日新闻 + "nearbyFood": "附近有哪些美食?", // 美食 + // Agent controller 'welcomeMessage': '你好!我是**小言**,我能帮你:\n\n' '• 答问题和提供信息\n\n' diff --git a/lib/modules/agent/controllers/agent_controller.dart b/lib/modules/agent/controllers/agent_controller.dart index e786100ac..f8e64bd27 100644 --- a/lib/modules/agent/controllers/agent_controller.dart +++ b/lib/modules/agent/controllers/agent_controller.dart @@ -1287,6 +1287,41 @@ class AgentController extends GetxController { useImagePrompt('请翻译这张图片中的文字'); } + // 预设提示词处理(文本输入模式) + void preSetPromptAction(String presetType) { + // 确保在文本输入模式下 + if (!isTextInputMode.value) { + // 如果不在文本模式,先切换到文本模式 + isTextInputMode.value = true; + } + + switch (presetType) { + case 'Music': + textController.text = 'playSomeMusic'.tr; + break; + case 'Navigation': + textController.text = 'navigationTo'.tr; + break; + case 'Weather': + textController.text = 'todayWeather'.tr; + break; + case 'News': + textController.text = 'todayNews'.tr; + break; + case 'Food': + textController.text = 'nearbyFood'.tr; + break; + default: + textController.text = presetType; + break; + } + + // 自动发送消息 + if (presetType != 'Navigation') { + sendMessage(); + } + } + // 模式历史记录 VoiceInputMode? _previousInputMode; diff --git a/lib/modules/agent/views/agent_view.dart b/lib/modules/agent/views/agent_view.dart index da7e2bff0..dc39fe3c8 100644 --- a/lib/modules/agent/views/agent_view.dart +++ b/lib/modules/agent/views/agent_view.dart @@ -341,80 +341,127 @@ class _AgentViewState extends State with WidgetsBindingObserver { child: Column( children: [ // 图片预览区域 - 仅在图片输入模式下显示 - Obx(() { - if (controller.isImageInputActive.value && - controller.selectedImagePath.value != null) { - return Column( - children: [ - // 图片预览和关闭按钮 - Stack( - children: [ - ClipRRect( - borderRadius: BorderRadius.circular(12.w), - child: Image.file( - File(controller.selectedImagePath.value!), - height: 150.h, - width: double.infinity, - fit: BoxFit.cover, + Obx( + () { + if (controller.isImageInputActive.value && + controller.selectedImagePath.value != null) { + return Column( + children: [ + // 图片预览和关闭按钮 + Stack( + children: [ + ClipRRect( + borderRadius: BorderRadius.circular(12.w), + child: Image.file( + File(controller.selectedImagePath.value!), + height: 150.h, + width: double.infinity, + fit: BoxFit.cover, + ), ), - ), - Positioned( - top: 8.h, - right: 8.w, - child: GestureDetector( - onTap: () => controller.clearImageInput(), - child: Container( - padding: EdgeInsets.all(4.w), - decoration: BoxDecoration( - color: Colors.black.withOpacity(0.6), - shape: BoxShape.circle, - ), - child: Icon( - Icons.close, - color: Colors.white, - size: 16.sp, + Positioned( + top: 8.h, + right: 8.w, + child: GestureDetector( + onTap: () => controller.clearImageInput(), + child: Container( + padding: EdgeInsets.all(4.w), + decoration: BoxDecoration( + color: Colors.black.withOpacity(0.6), + shape: BoxShape.circle, + ), + child: Icon( + Icons.close, + color: Colors.white, + size: 16.sp, + ), ), ), ), - ), - ], - ), - - // 预设提示选项 - SizedBox(height: 12.h), - SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Row( - children: [ - _buildPromptChip( - context: context, - label: 'summarizeImageContent'.tr, //总结图片内容 - onTap: () => controller.summarizeImage(), - ), - SizedBox(width: 8.w), - _buildPromptChip( - context: context, - label: 'extractImageText'.tr, //抽取图像文字 - onTap: () => - controller.extractTextFromImage(), - ), - SizedBox(width: 8.w), - _buildPromptChip( - context: context, - label: 'translateImageText'.tr, //翻译图像文字 - onTap: () => - controller.translateImageText(), - ), ], ), - ), - SizedBox(height: 12.h), - ], - ); - } else { - return const SizedBox.shrink(); - } - }), + + // 预设提示选项 + SizedBox(height: 12.h), + SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + children: [ + _buildPromptChip( + context: context, + label: + 'summarizeImageContent'.tr, //总结图片内容 + onTap: () => controller.summarizeImage(), + ), + SizedBox(width: 8.w), + _buildPromptChip( + context: context, + label: 'extractImageText'.tr, //抽取图像文字 + onTap: () => + controller.extractTextFromImage(), + ), + SizedBox(width: 8.w), + _buildPromptChip( + context: context, + label: 'translateImageText'.tr, //翻译图像文字 + onTap: () => + controller.translateImageText(), + ), + ], + ), + ), + SizedBox(height: 12.h), + ], + ); + } else if (controller.isTextInputMode.value && + !controller.hasTextInput.value) { + // 文本输入模式下,且输入框为空 + return Column( + children: [ + SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + children: [ + _buildPromptChip( + context: context, + label: 'presetMusic'.tr, // 来点音乐 + onTap: () => controller + .preSetPromptAction('Music')), + SizedBox(width: 8.w), + _buildPromptChip( + context: context, + label: 'presetNavigation'.tr, // 导航 + onTap: () => + controller.preSetPromptAction( + 'Navigation')), + SizedBox(width: 8.w), + _buildPromptChip( + context: context, + label: 'presetWeather'.tr, // 天气 + onTap: () => controller + .preSetPromptAction('Weather')), + SizedBox(width: 8.w), + _buildPromptChip( + context: context, + label: 'presetNews'.tr, // 新闻 + onTap: () => controller + .preSetPromptAction('News')), + SizedBox(width: 8.w), + _buildPromptChip( + context: context, + label: 'presetFood'.tr, // 美食 + onTap: () => controller + .preSetPromptAction('Food')), + ], + )), + SizedBox(height: 12.h), + ], + ); + } else { + return const SizedBox.shrink(); + } + }, + ), // 输入控件区域 - 包含输入行和展开的选项 Column( diff --git a/lib/modules/settings/views/settings_view.dart b/lib/modules/settings/views/settings_view.dart index 24aff0513..47d859ba3 100644 --- a/lib/modules/settings/views/settings_view.dart +++ b/lib/modules/settings/views/settings_view.dart @@ -515,22 +515,22 @@ class SettingsView extends GetView { // ? Colors.white.withOpacity(0.1) // : Colors.grey[200]), //BLE测试 - _buildSimpleNavigationSetting( - title: 'opus解码测试', - subtitle: '测试opus解码', - icon: Icons.bluetooth_searching, - iconBgColor: isDarkMode - ? Colors.green[900]!.withOpacity(0.3) - : Colors.green[100]!, - iconColor: - isDarkMode ? Colors.green[300]! : Colors.green[600]!, - titleColor: isDarkMode ? Colors.white : null, - subtitleColor: isDarkMode ? Colors.white70 : null, - onTap: () { - Get.toNamed(Routes.opusTest); - }, - isDarkMode: isDarkMode, - ), + // _buildSimpleNavigationSetting( + // title: 'opus解码测试', + // subtitle: '测试opus解码', + // icon: Icons.bluetooth_searching, + // iconBgColor: isDarkMode + // ? Colors.green[900]!.withOpacity(0.3) + // : Colors.green[100]!, + // iconColor: + // isDarkMode ? Colors.green[300]! : Colors.green[600]!, + // titleColor: isDarkMode ? Colors.white : null, + // subtitleColor: isDarkMode ? Colors.white70 : null, + // onTap: () { + // Get.toNamed(Routes.opusTest); + // }, + // isDarkMode: isDarkMode, + // ), // Divider( // height: 1, // color: isDarkMode diff --git a/lib/modules/translation/views/translation_view.dart b/lib/modules/translation/views/translation_view.dart index a5d4fbde3..bf11fd7bd 100644 --- a/lib/modules/translation/views/translation_view.dart +++ b/lib/modules/translation/views/translation_view.dart @@ -523,63 +523,63 @@ class TranslationView extends GetView { ), // 添加间距 - SizedBox(height: 16.h), + //SizedBox(height: 16.h), // 语音识别结果显示框 - Container( - width: double.infinity, - padding: EdgeInsets.all(12.w), - decoration: BoxDecoration( - color: isDarkMode ? Colors.grey[800] : Colors.grey[100], - borderRadius: BorderRadius.circular(8.r), - border: Border.all( - color: isDarkMode ? Colors.grey[600]! : Colors.grey[300]!, - width: 1, - ), - ), - child: Obx(() { - // 显示最新的语音识别结果 - final recognitionText = controller.latestRecognitionText.value; - final detectedLanguage = controller.detectedLanguageCode1.value; + // Container( + // width: double.infinity, + // padding: EdgeInsets.all(12.w), + // decoration: BoxDecoration( + // color: isDarkMode ? Colors.grey[800] : Colors.grey[100], + // borderRadius: BorderRadius.circular(8.r), + // border: Border.all( + // color: isDarkMode ? Colors.grey[600]! : Colors.grey[300]!, + // width: 1, + // ), + // ), + // child: Obx(() { + // // 显示最新的语音识别结果 + // final recognitionText = controller.latestRecognitionText.value; + // final detectedLanguage = controller.detectedLanguageCode1.value; - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // 标题 - Text( - '麦头语音识别结果', - style: TextStyle( - fontSize: 12.sp, - color: isDarkMode ? Colors.grey[400] : Colors.grey[600], - fontWeight: FontWeight.w500, - ), - ), - SizedBox(height: 4.h), - // 识别文本 - 这里显示 finalResult1 的内容 - Text( - recognitionText.isEmpty ? '等待语音输入...' : recognitionText, - style: TextStyle( - fontSize: 14.sp, - color: isDarkMode ? Colors.white : Colors.black87, - height: 1.3, - ), - ), - // 检测到的语言(如果有) - if (detectedLanguage.isNotEmpty) ...[ - SizedBox(height: 4.h), - Text( - '检测语言: $detectedLanguage', - style: TextStyle( - fontSize: 10.sp, - color: - isDarkMode ? Colors.grey[500] : Colors.grey[500], - ), - ), - ], - ], - ); - }), - ), + // return Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // // 标题 + // Text( + // '麦头语音识别结果', + // style: TextStyle( + // fontSize: 12.sp, + // color: isDarkMode ? Colors.grey[400] : Colors.grey[600], + // fontWeight: FontWeight.w500, + // ), + // ), + // SizedBox(height: 4.h), + // // 识别文本 - 这里显示 finalResult1 的内容 + // Text( + // recognitionText.isEmpty ? '等待语音输入...' : recognitionText, + // style: TextStyle( + // fontSize: 14.sp, + // color: isDarkMode ? Colors.white : Colors.black87, + // height: 1.3, + // ), + // ), + // // 检测到的语言(如果有) + // if (detectedLanguage.isNotEmpty) ...[ + // SizedBox(height: 4.h), + // Text( + // '检测语言: $detectedLanguage', + // style: TextStyle( + // fontSize: 10.sp, + // color: + // isDarkMode ? Colors.grey[500] : Colors.grey[500], + // ), + // ), + // ], + // ], + // ); + // }), + // ), ], ); }),