Browse Source

feat(agent): 添加预设提示词功能支持音乐、导航等快捷操作

在文本输入模式下添加预设提示词功能,支持快速输入音乐、导航、天气、新闻和美食等常用指令。同时更新了中英文翻译文件并优化了界面显示逻辑。
weicu
lxm 1 year ago
parent
commit
fe975f4a2f
  1. 16
      lib/core/translations/language/en_us.dart
  2. 12
      lib/core/translations/language/zh_cn.dart
  3. 35
      lib/modules/agent/controllers/agent_controller.dart
  4. 53
      lib/modules/agent/views/agent_view.dart
  5. 32
      lib/modules/settings/views/settings_view.dart
  6. 108
      lib/modules/translation/views/translation_view.dart

16
lib/core/translations/language/en_us.dart

@ -305,8 +305,20 @@ const Map<String, String> 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'

12
lib/core/translations/language/zh_cn.dart

@ -295,6 +295,18 @@ const Map<String, String> zhCN = {
"loadFailedClickRetry": "加载失败,点击重试",
"swipeUpForMore": "向上滑动查看更多",
// 预设提示词
"presetMusic": "来点音乐", // 来点音乐
"presetNavigation": "导航到", // 导航
"presetWeather": "今日天气", // 今日天气
"presetNews": "今日新闻", // 今日新闻
"presetFood": "附近美食", // 美食
"playSomeMusic": "播放一些流行音乐", // 播放一些流行音乐
"navigationTo": "请帮我导航到", // 导航到
"todayWeather": "今天天气如何?", // 今日天气
"todayNews": "今天有哪些新闻?", // 今日新闻
"nearbyFood": "附近有哪些美食?", // 美食
// Agent controller
'welcomeMessage': '你好!我是**小言**,我能帮你:\n\n'
'• 答问题和提供信息\n\n'

35
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;

53
lib/modules/agent/views/agent_view.dart

@ -341,7 +341,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
child: Column(
children: [
// 图片预览区域 - 仅在图片输入模式下显示
Obx(() {
Obx(
() {
if (controller.isImageInputActive.value &&
controller.selectedImagePath.value != null) {
return Column(
@ -388,7 +389,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
children: [
_buildPromptChip(
context: context,
label: 'summarizeImageContent'.tr, //总结图片内容
label:
'summarizeImageContent'.tr, //总结图片内容
onTap: () => controller.summarizeImage(),
),
SizedBox(width: 8.w),
@ -411,10 +413,55 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
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(

32
lib/modules/settings/views/settings_view.dart

@ -515,22 +515,22 @@ class SettingsView extends GetView<SettingsController> {
// ? 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

108
lib/modules/translation/views/translation_view.dart

@ -523,63 +523,63 @@ class TranslationView extends GetView<TranslationController> {
),
// 添加间距
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],
// ),
// ),
// ],
// ],
// );
// }),
// ),
],
);
}),

Loading…
Cancel
Save