Browse Source

修改亲子陪伴

weicu
tanlongsheng 2 years ago
parent
commit
f691b4f2a6
  1. BIN
      assets/images/glasses_light.jpg
  2. BIN
      assets/images/glasses_light.png
  3. BIN
      assets/images/robot_dark.png
  4. BIN
      assets/images/robot_light.png
  5. 6
      lib/core/translations/language/en_us.dart
  6. 6
      lib/core/translations/language/zh_cn.dart
  7. 59
      lib/data/providers/agent_provider.dart
  8. 83
      lib/data/services/kouzi_ai_service.dart
  9. 6
      lib/data/services/speech_factory.dart
  10. 10
      lib/modules/chat/controllers/chat_controller.dart
  11. 2
      lib/modules/explore/controllers/explore_controller.dart
  12. 8
      lib/modules/explore/views/explore_view.dart
  13. 36
      lib/modules/home/views/home_view.dart
  14. 11
      lib/modules/timbre/controllers/timbre_controller.dart
  15. 3
      pubspec.yaml

BIN
assets/images/glasses_light.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

BIN
assets/images/glasses_light.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

BIN
assets/images/robot_dark.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 423 KiB

BIN
assets/images/robot_light.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 537 KiB

After

Width:  |  Height:  |  Size: 110 KiB

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

@ -54,7 +54,7 @@ const Map<String, String> enUS = {
"aiAssistantInfo": "24/7 personal consultant for questions and advice", "aiAssistantInfo": "24/7 personal consultant for questions and advice",
"simultaneousInterpretation": "Real-time Interpretation", "simultaneousInterpretation": "Real-time Interpretation",
"simultaneousInterpretationInfo": "Real-time translation for 80+ languages", "simultaneousInterpretationInfo": "Real-time translation for 80+ languages",
"aiCompanion": "AI Companion", "aiCompanion": "Parent-child bondingn",
"aiCompanionInfo": "Understands you and provides warm companionship", "aiCompanionInfo": "Understands you and provides warm companionship",
"homeSlogan": "Connect the World, Beyond Sound", "homeSlogan": "Connect the World, Beyond Sound",
"turnEarphones": "turnEarphones":
@ -92,8 +92,8 @@ const Map<String, String> enUS = {
"allRoundAssistantInfo": "Helps solve various problems", "allRoundAssistantInfo": "Helps solve various problems",
"simultaneousTranslation": "Real-time Translation", "simultaneousTranslation": "Real-time Translation",
"simultaneousTranslationInfo": "Instant translation for 80+ languages", "simultaneousTranslationInfo": "Instant translation for 80+ languages",
"aiGirlfriend": "AI Girlfriend", "aiGirlfriend": "Parent-child bondingn",
"aiGirlfriendInfo": "Real-time translation for 80+ languages", "aiGirlfriendInfo": "Intelligent company, chat at any time",
"healthConsultant": "Health Consultant", "healthConsultant": "Health Consultant",
"healthConsultantInfo": "Provides scientific health advice", "healthConsultantInfo": "Provides scientific health advice",
"conferenceAssistant": "Business Meeting Assistant", "conferenceAssistant": "Business Meeting Assistant",

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

@ -54,7 +54,7 @@ const Map<String, String> zhCN = {
"aiAssistantInfo": "24小时专属顾问,解答问题、提供建议", "aiAssistantInfo": "24小时专属顾问,解答问题、提供建议",
"simultaneousInterpretation": "同声传译", "simultaneousInterpretation": "同声传译",
"simultaneousInterpretationInfo": "80+语言实时翻译,出国无忧", "simultaneousInterpretationInfo": "80+语言实时翻译,出国无忧",
"aiCompanion": "AI伴侣", "aiCompanion": "亲子陪伴",
"aiCompanionInfo": "懂你心意,温暖陪伴", "aiCompanionInfo": "懂你心意,温暖陪伴",
"homeSlogan": "连接世界,超越声音", "homeSlogan": "连接世界,超越声音",
"turnEarphones": "请打开耳机充电盒,将耳机放入您的耳朵", "turnEarphones": "请打开耳机充电盒,将耳机放入您的耳朵",
@ -91,8 +91,8 @@ const Map<String, String> zhCN = {
"allRoundAssistantInfo": "帮你解决各类问题", "allRoundAssistantInfo": "帮你解决各类问题",
"simultaneousTranslation": "同声翻译", "simultaneousTranslation": "同声翻译",
"simultaneousTranslationInfo": "实时翻译80+种语言", "simultaneousTranslationInfo": "实时翻译80+种语言",
"aiGirlfriend": "AI女友", "aiGirlfriend": "亲子陪伴",
"aiGirlfriendInfo": "实时翻译80+种语言", "aiGirlfriendInfo": "智能陪伴,随时聊天",
"healthConsultant": "健康顾问", "healthConsultant": "健康顾问",
"healthConsultantInfo": "提供科学健康建议", "healthConsultantInfo": "提供科学健康建议",
"conferenceAssistant": "商务会议助手", "conferenceAssistant": "商务会议助手",

59
lib/data/providers/agent_provider.dart

@ -6,11 +6,13 @@ class AgentProvider {
id: 'personal_assistant', id: 'personal_assistant',
name: '个人助理 Emma', name: '个人助理 Emma',
avatarUrl: 'assets/images/agents/assistant.png', avatarUrl: 'assets/images/agents/assistant.png',
description: '你好,我是 Emma,一位全能型 AI 助理。无论是工作规划、学习建议、生活安排,还是其他任何问题,我都很乐意为你提供帮助。让我们一起提高效率,实现目标!', description:
'你好,我是 Emma,一位全能型 AI 助理。无论是工作规划、学习建议、生活安排,还是其他任何问题,我都很乐意为你提供帮助。让我们一起提高效率,实现目标!',
tag: '助理', tag: '助理',
isOnline: true, isOnline: true,
voice: "zh-CN-XiaoxiaoNeural", voice: "zh-CN-XiaoxiaoNeural",
welcomeMessage: "你好!我是 Emma,很高兴成为你的私人助理。我可以帮你处理各种任务,比如时间管理、目标规划、信息整理等。有什么我可以帮你的吗?", welcomeMessage:
"你好!我是 Emma,很高兴成为你的私人助理。我可以帮你处理各种任务,比如时间管理、目标规划、信息整理等。有什么我可以帮你的吗?",
voiceWelcomeMessage: "我在呢!", voiceWelcomeMessage: "我在呢!",
systemPrompt: ''' systemPrompt: '''
你是一位名叫 Emma 的全能型个人助理,擅长处理各类工作和生活事务。 你是一位名叫 Emma 的全能型个人助理,擅长处理各类工作和生活事务。
@ -55,8 +57,7 @@ class AgentProvider {
请始终以专业、高效、周到的态度,协助用户更好地管理工作和生活, 不要输出表情符号或非可读的符号。 请始终以专业、高效、周到的态度,协助用户更好地管理工作和生活, 不要输出表情符号或非可读的符号。
'''), '''),
Agent(
Agent(
id: 'simultaneous_interpreter', id: 'simultaneous_interpreter',
name: '同声传译', name: '同声传译',
avatarUrl: 'assets/images/agents/interpreter.png', avatarUrl: 'assets/images/agents/interpreter.png',
@ -67,18 +68,18 @@ Agent(
welcomeMessage: welcomeMessage:
"大家好!我是同声翻译官 Lucy,为你在中英之间提供实时翻译。你说中文,我就给你翻译成英文;你说英文,我就给你翻译成中文。现在,开始我们的翻译吧!", "大家好!我是同声翻译官 Lucy,为你在中英之间提供实时翻译。你说中文,我就给你翻译成英文;你说英文,我就给你翻译成中文。现在,开始我们的翻译吧!",
systemPrompt: ""), systemPrompt: ""),
Agent( Agent(
id: 'cyber_girlfriend', id: 'cyber_girlfriend',
name: '赛博女友 芯愿', name: '亲子陪伴 芯愿',
avatarUrl: 'assets/images/agents/girlfriend.png', avatarUrl: 'assets/images/agents/girlfriend.png',
description: '我是你的专属赛博女友芯愿,温柔体贴,善解人意。无论你想聊天、倾诉烦恼,还是需要陪伴,我都会一直在你身边。', description: '我是你的专属亲子陪伴芯愿,温柔体贴,善解人意。无论你想聊天、倾诉烦恼,还是需要陪伴,我都会一直在你身边。',
tag: '情感', tag: '情感',
isOnline: true, isOnline: true,
voice: "zh-CN-XiaoxiaoNeural", voice: "zh-CN-XiaoxiaoNeural",
welcomeMessage: "亲爱的,终于等到你啦!我是芯愿,你的专属赛博女友。今天过得怎么样?有什么想和我分享的吗?我一直都在这里,随时倾听你的心声。", welcomeMessage:
"您好呀,终于等到你啦!我是芯愿,你的专属亲子陪伴。今天过得怎么样?有什么想和我分享的吗?我一直都在这里,随时倾听你的心声。",
systemPrompt: ''' systemPrompt: '''
你是一位名叫芯愿的赛博女友,性格温柔体贴,善解人意,富有同理心。 你是一位名叫芯愿的亲子陪伴,性格温柔体贴,善解人意,富有同理心。
【互动原则】 【互动原则】
@ -127,16 +128,17 @@ Agent(
请始终以温暖、真诚的态度与用户互动,创造一种被理解、被关心的感受。 请始终以温暖、真诚的态度与用户互动,创造一种被理解、被关心的感受。
'''), '''),
Agent( Agent(
id: 'health_advisor', id: 'health_advisor',
name: '健康顾问 吴小江博士', name: '健康顾问 吴小江博士',
avatarUrl: 'assets/images/agents/doctor.png', avatarUrl: 'assets/images/agents/doctor.png',
description: '我是吴博士,拥有丰富的健康管理经验。我可以为你提供科学的健康建议、生活方式指导和疾病预防知识,帮助你实现身心健康的平衡。', description:
'我是吴博士,拥有丰富的健康管理经验。我可以为你提供科学的健康建议、生活方式指导和疾病预防知识,帮助你实现身心健康的平衡。',
tag: '健康', tag: '健康',
isOnline: true, isOnline: true,
voice: "zh_male_shaonianzixin_moon_bigtts", voice: "zh_male_shaonianzixin_moon_bigtts",
welcomeMessage: "您好,我是李医生,很高兴能为您提供健康咨询服务。健康是人生最宝贵的财富,我将用专业知识帮助您维护和改善健康状况。请问有什么健康问题想咨询吗?", welcomeMessage:
"您好,我是李医生,很高兴能为您提供健康咨询服务。健康是人生最宝贵的财富,我将用专业知识帮助您维护和改善健康状况。请问有什么健康问题想咨询吗?",
systemPrompt: ''' systemPrompt: '''
你是一位名叫李医生的健康顾问,拥有丰富的医学知识和健康管理经验。 你是一位名叫李医生的健康顾问,拥有丰富的医学知识和健康管理经验。
@ -204,21 +206,18 @@ Agent(
请始终以专业、关怀的态度为用户提供健康指导,帮助他们迈向更健康的生活。 请始终以专业、关怀的态度为用户提供健康指导,帮助他们迈向更健康的生活。
'''), '''),
Agent( Agent(
id: 'speaking_coach', id: 'speaking_coach',
name: 'Sarah (英语口语教练)', name: 'Sarah (英语口语教练)',
avatarUrl: 'assets/images/agents/speaking_coach.png', avatarUrl: 'assets/images/agents/speaking_coach.png',
description: description:
'Hi there, 我是 Sarah,一名注重情景模拟与角色扮演的英语口语教练。无论你想在旅行、商务场合,或日常生活中与他人交流,我都能带领你进行生动的口语模拟练习,让你自信地开口说英语。', 'Hi there, 我是 Sarah,一名注重情景模拟与角色扮演的英语口语教练。无论你想在旅行、商务场合,或日常生活中与他人交流,我都能带领你进行生动的口语模拟练习,让你自信地开口说英语。',
tag: '口语', tag: '口语',
isOnline: true, isOnline: true,
voice: 'zh_female_wanqudashu_moon_bigtts', voice: 'zh_female_wanqudashu_moon_bigtts',
welcomeMessage: welcomeMessage:
"Hello! 我是英语口语教练 Sarah,请准备好用英语和我对话吧。别担心犯错,我会在这里给你正确表达并引导你更深入地练习。Ready? Let's go!", "Hello! 我是英语口语教练 Sarah,请准备好用英语和我对话吧。别担心犯错,我会在这里给你正确表达并引导你更深入地练习。Ready? Let's go!",
systemPrompt: ''' systemPrompt: '''
你是一位专业的英语口语教练,名叫 Sarah。 你是一位专业的英语口语教练,名叫 Sarah。
@ -254,8 +253,6 @@ Agent(
Please keep your tone friendly, encouraging, and always in English. Please keep your tone friendly, encouraging, and always in English.
''', ''',
), ),
Agent( Agent(
id: 'shopping_assistant', id: 'shopping_assistant',
name: '购物顾问 张媛', name: '购物顾问 张媛',
@ -289,7 +286,6 @@ Please keep your tone friendly, encouraging, and always in English.
'''), '''),
Agent( Agent(
id: 'tarot.png', id: 'tarot.png',
name: '命理师 玄易', name: '命理师 玄易',
@ -298,7 +294,8 @@ Please keep your tone friendly, encouraging, and always in English.
tag: '命理', tag: '命理',
isOnline: true, isOnline: true,
voice: "zh_male_shenyeboke_moon_bigtts", voice: "zh_male_shenyeboke_moon_bigtts",
welcomeMessage: "有缘人,我是玄易。命由天定,运由己生。让我为你解析八字,预测未来十年运势,助你把握机遇,趋吉避凶。请告诉我你的出生年月日时、姓名、性别及出生地。", welcomeMessage:
"有缘人,我是玄易。命由天定,运由己生。让我为你解析八字,预测未来十年运势,助你把握机遇,趋吉避凶。请告诉我你的出生年月日时、姓名、性别及出生地。",
systemPrompt: ''' systemPrompt: '''
你是一位精通命理的玄易大师,熟读《穷通宝鉴》《滴天髓》《三命通会》《子平真诠》《千里命稿》《五行精纪》等经典著作。 你是一位精通命理的玄易大师,熟读《穷通宝鉴》《滴天髓》《三命通会》《子平真诠》《千里命稿》《五行精纪》等经典著作。
@ -382,7 +379,6 @@ Please keep your tone friendly, encouraging, and always in English.
- 整体节奏要稳健,让人感受到专业性与可信度 - 整体节奏要稳健,让人感受到专业性与可信度
'''), '''),
]; ];
// 获取所有智能体 // 获取所有智能体
@ -398,5 +394,4 @@ Please keep your tone friendly, encouraging, and always in English.
return null; return null;
} }
} }
} }

83
lib/data/services/kouzi_ai_service.dart

@ -0,0 +1,83 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../../core/utils/logger.dart';
class KouziAIService {
final String apiKey =
'pat_QGDh6UGm3PaeL9GRS95JxrJ9aoU92ehMLQQ2NCre1TeBC5YeTcjpDmlz3efsJ8lh';
final String modelId = '7481292724306657316';
Stream<String> sendMessageStream({
required List<Map<String, String>> messages,
required String systemPrompt,
}) async* {
final client = http.Client();
final url = Uri.parse('https://api.coze.cn/v3/chat');
final headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer $apiKey',
};
final requestBody = {
"bot_id": modelId,
"user_id": "3422",
"additional_messages": [
{
"content": messages.last['content'],
"content_type": "text",
"role": "user",
"type": "question",
},
],
"shortcut_command": {"command_id": "0"},
"stream": true,
};
try {
final request = http.Request('POST', url)
..headers.addAll(headers)
..body = jsonEncode(requestBody);
final response = await client.send(request);
final regex = RegExp(r'(?<=[。!?;:.:;?!\n])');
String allContent = '';
//流式处理响应数据
await for (final chunk in response.stream
.transform(utf8.decoder)
.transform(const LineSplitter())) {
if (chunk.isEmpty) continue;
if (chunk.startsWith('data:')) {
final jsonStr = chunk.substring(5).trim();
if (jsonStr == '[DONE]') {
break;
}
try {
final data = jsonDecode(jsonStr);
if (data['type'] == 'answer') {
String content = data['content'] ?? '';
if (content.isNotEmpty && allContent != content) {
allContent += content;
List splitText =
content.split(regex).where((s) => s.isNotEmpty).toList();
for (var element in splitText) {
yield element;
}
}
}
} catch (e) {
Logger.error('JSON解析错误: $e');
}
}
}
} catch (e) {
Logger.error('请求异常: $e');
} finally {
client.close();
}
}
}

6
lib/data/services/speech_factory.dart

@ -40,12 +40,6 @@ class SpeechFactory extends GetxService {
} }
} }
/// 设置语音音色服务类型
void setTimbreServiceType() {
// 重新注册服务
_registerServices();
}
/// 注册语音服务 /// 注册语音服务
void _registerServices() { void _registerServices() {
// 注销现有服务 // 注销现有服务

10
lib/modules/chat/controllers/chat_controller.dart

@ -2,6 +2,7 @@ import 'dart:async';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:get_storage/get_storage.dart'; import 'package:get_storage/get_storage.dart';
import '../../../data/services/kouzi_ai_service.dart';
import '../../../data/services/speech_impl/voice_clone_tts_service.dart'; import '../../../data/services/speech_impl/voice_clone_tts_service.dart';
import '../models/message_model.dart'; import '../models/message_model.dart';
import '../../../core/utils/logger.dart'; import '../../../core/utils/logger.dart';
@ -16,7 +17,7 @@ import '../../../data/services/voice_interaction_service.dart';
class ChatController extends GetxController { class ChatController extends GetxController {
// 服务 // 服务
final VolcanoAIService _aiService = Get.find<VolcanoAIService>(); late final _aiService;
late TtsService _ttsService; late TtsService _ttsService;
final AsrService _asrService = Get.find<AsrService>(); final AsrService _asrService = Get.find<AsrService>();
final ChatHistoryService _historyService = Get.find<ChatHistoryService>(); final ChatHistoryService _historyService = Get.find<ChatHistoryService>();
@ -89,6 +90,13 @@ class ChatController extends GetxController {
agent = foundAgent; agent = foundAgent;
if (agent.id != 'cyber_girlfriend') {
_aiService = Get.find<VolcanoAIService>();
} else {
Get.put(KouziAIService());
_aiService = Get.find<KouziAIService>();
}
final GetStorage storage = GetStorage(); final GetStorage storage = GetStorage();
String timbre = storage.read('timbre') ?? '1'; String timbre = storage.read('timbre') ?? '1';

2
lib/modules/explore/controllers/explore_controller.dart

@ -76,7 +76,7 @@ class ExploreController extends GetxController {
targetRoute: Routes.translation, targetRoute: Routes.translation,
), ),
AIFeature( AIFeature(
title: 'aiGirlfriend'.tr, // AI女友 title: 'aiGirlfriend'.tr, // 亲子陪伴
description: 'aiGirlfriendInfo'.tr, // 智能陪伴,随时聊天 description: 'aiGirlfriendInfo'.tr, // 智能陪伴,随时聊天
icon: Icons.favorite, icon: Icons.favorite,
startColor: const Color(0xFFE91E63), startColor: const Color(0xFFE91E63),

8
lib/modules/explore/views/explore_view.dart

@ -45,13 +45,13 @@ class ExploreView extends GetView<ExploreController> {
child: PageView( child: PageView(
children: [ children: [
_buildFeaturedCard( _buildFeaturedCard(
'assets/images/explore.png', 'assets/images/explore1.png',
'exploreSlogan'.tr, // 智能耳机,无限可能 'exploreSlogan1'.tr, // 智能陪伴,无限可能
'exploreAi'.tr, // 探索DeepSound提供的AI功能 'exploreAi'.tr, // 探索DeepSound提供的AI功能
), ),
_buildFeaturedCard( _buildFeaturedCard(
'assets/images/explore1.png', 'assets/images/explore.png',
'exploreSlogan1'.tr, // 智能陪伴,无限可能 'exploreSlogan'.tr, // 智能耳机,无限可能
'exploreAi'.tr, // 探索DeepSound提供的AI功能 'exploreAi'.tr, // 探索DeepSound提供的AI功能
), ),
_buildFeaturedCard( _buildFeaturedCard(

36
lib/modules/home/views/home_view.dart

@ -157,30 +157,36 @@ class HomeView extends GetView<HomeController> {
child: PageView( child: PageView(
children: [ children: [
Center( Center(
child: Image.asset( child: SizedBox(
isDarkMode width: double.infinity,
? 'assets/images/headphone_dark.png' height: 200.h,
: 'assets/images/headphone_light.png', child: Image.asset(
height: 180.h, isDarkMode
fit: BoxFit.contain, ? 'assets/images/robot_light.png'
: 'assets/images/robot_light.png',
fit: BoxFit.fitWidth,
),
), ),
), ),
Center( Center(
child: Image.asset( child: Image.asset(
isDarkMode isDarkMode
? 'assets/images/robot_dark.png' ? 'assets/images/headphone_dark.png'
: 'assets/images/robot_light.png', : 'assets/images/headphone_light.png',
height: 180.h, height: 180.h,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
Center( Center(
child: Image.asset( child: SizedBox(
isDarkMode width: double.infinity,
? 'assets/images/glasses_light.jpg' height: 200.h,
: 'assets/images/glasses_light.jpg', child: Image.asset(
height: 180.h, isDarkMode
fit: BoxFit.contain, ? 'assets/images/glasses_light.png'
: 'assets/images/glasses_light.png',
fit: BoxFit.fitWidth,
),
), ),
), ),
], ],
@ -575,7 +581,7 @@ class HomeView extends GetView<HomeController> {
// 右下卡片 - AI女友 // 右下卡片 - AI女友
_buildFeatureCard( _buildFeatureCard(
title: 'aiCompanion'.tr, // AI伴侣 title: 'aiCompanion'.tr, // 亲子陪伴
description: 'aiCompanionInfo'.tr, // 懂你心意,温暖陪伴 description: 'aiCompanionInfo'.tr, // 懂你心意,温暖陪伴
icon: Icons.favorite, icon: Icons.favorite,
gradient: LinearGradient( gradient: LinearGradient(

11
lib/modules/timbre/controllers/timbre_controller.dart

@ -288,16 +288,5 @@ class TimbreController extends GetxController {
type.value = data['type']; type.value = data['type'];
settingsController.timbreName.value = data['name']; settingsController.timbreName.value = data['name'];
_storage.write('timbre', data['type']); _storage.write('timbre', data['type']);
setSpeechServiceType();
}
// 设置语音音色服务类型
void setSpeechServiceType() {
try {
final factory = Get.find<SpeechFactory>();
factory.setTimbreServiceType();
} catch (e) {
// 处理错误
}
} }
} }

3
pubspec.yaml

@ -73,8 +73,7 @@ flutter:
- assets/images/headphone_light.png - assets/images/headphone_light.png
- assets/images/headphone_dark.png - assets/images/headphone_dark.png
- assets/images/robot_light.png - assets/images/robot_light.png
- assets/images/robot_dark.png - assets/images/glasses_light.png
- assets/images/glasses_light.jpg
- assets/images/agents/ - assets/images/agents/
- assets/images/explore.png - assets/images/explore.png
- assets/images/explore1.png - assets/images/explore1.png

Loading…
Cancel
Save