From 310f2f86728527a0a78650042d7ee51fba771ce1 Mon Sep 17 00:00:00 2001 From: tanlongsheng <252620078@qq.com> Date: Tue, 25 Mar 2025 15:44:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=89=E6=8B=A9=E9=9F=B3?= =?UTF-8?q?=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/data/services/speech_factory.dart | 6 +++ .../controllers/settings_controller.dart | 19 +++++++ lib/modules/settings/views/settings_view.dart | 26 ++++++++++ .../timbre/controllers/timbre_controller.dart | 24 +++++++-- lib/modules/timbre/views/timbre_view.dart | 50 +++++++++++-------- 5 files changed, 101 insertions(+), 24 deletions(-) diff --git a/lib/data/services/speech_factory.dart b/lib/data/services/speech_factory.dart index 93b0850d1..dca9abafe 100644 --- a/lib/data/services/speech_factory.dart +++ b/lib/data/services/speech_factory.dart @@ -41,6 +41,12 @@ class SpeechFactory extends GetxService { } } + /// 设置语音音色服务类型 + void setTimbreServiceType() { + // 重新注册服务 + _registerServices(); + } + /// 注册语音服务 void _registerServices() { // 注销现有服务 diff --git a/lib/modules/settings/controllers/settings_controller.dart b/lib/modules/settings/controllers/settings_controller.dart index a34b590f3..a1f1890b1 100644 --- a/lib/modules/settings/controllers/settings_controller.dart +++ b/lib/modules/settings/controllers/settings_controller.dart @@ -59,6 +59,8 @@ class SettingsController extends GetxController { }, ]; + RxString timbreName = '默认音色'.obs; + //用户信息 static const String userKey = 'user_info'; //final _storage=GetStorage(); @@ -72,6 +74,8 @@ class SettingsController extends GetxController { // 获取系统语言 _getLanguage(); + _getTimbre(); + // 从存储中加载上次保存的主题设置 final savedDarkMode = _themeService.isSavedDarkMode(); @@ -144,6 +148,21 @@ class SettingsController extends GetxController { language.value = data; } + // 获取音色 + void _getTimbre() { + List? timbreList = _storage.read('timbreList'); + String? timbre = _storage.read('timbre'); + if (timbreList != null && timbre != null) { + Map data = timbreList.firstWhere( + (element) => element['type'] == timbre, + orElse: () => {}, + ); + if (data.isNotEmpty) { + timbreName.value = data['name']; + } + } + } + void setLanguage(LanguageModel data) { if (data.value != 'system') { List languageList = data.value.split('_'); diff --git a/lib/modules/settings/views/settings_view.dart b/lib/modules/settings/views/settings_view.dart index 53864d00c..01c8e0243 100644 --- a/lib/modules/settings/views/settings_view.dart +++ b/lib/modules/settings/views/settings_view.dart @@ -339,6 +339,32 @@ class SettingsView extends GetView { // 语音服务选择 _buildSpeechServiceSetting(isDarkMode), + Divider( + height: 1, + color: isDarkMode + ? Colors.white.withOpacity(0.1) + : Colors.grey[200]), + Obx( + () => _buildNavigationSetting( + title: '音色服务', + subtitle: '选择音色语音合成服务', + icon: Icons.photo_camera_front_outlined, + iconBgColor: isDarkMode + ? Colors.cyan[900]!.withOpacity(0.3) + : Colors.cyan[100]!, + iconColor: + isDarkMode ? Colors.cyan[300]! : Colors.cyan[600]!, + value: controller.timbreName.value, + valueStyle: TextStyle( + fontSize: 12.sp, + color: isDarkMode ? Colors.white70 : Colors.grey[500], + ), + onTap: () { + Get.toNamed(Routes.timbre); + }, + isDarkMode: isDarkMode, + ), + ), Divider( height: 1, color: isDarkMode diff --git a/lib/modules/timbre/controllers/timbre_controller.dart b/lib/modules/timbre/controllers/timbre_controller.dart index f85156764..49ff05d10 100644 --- a/lib/modules/timbre/controllers/timbre_controller.dart +++ b/lib/modules/timbre/controllers/timbre_controller.dart @@ -8,7 +8,12 @@ import 'package:path/path.dart' as path; import 'package:path_provider/path_provider.dart'; import 'package:record/record.dart'; +import '../../../data/services/speech_factory.dart'; +import '../../settings/controllers/settings_controller.dart'; + class TimbreController extends GetxController { + final SettingsController settingsController = Get.find(); + final GetStorage _storage = GetStorage(); final _record = AudioRecorder(); @@ -24,7 +29,7 @@ class TimbreController extends GetxController { int _textId = 0; int _segId = 0; - String _taskId = '67e0f5e6025cf871b1de31b2'; + String _taskId = ''; @override void onInit() { @@ -218,7 +223,7 @@ class TimbreController extends GetxController { text.value = ''; dataList.add({ 'type': _taskId, - 'name': '声音复刻$_taskId', + 'name': '声音复刻${dataList.length}', 'description': '复刻本人音色服务', 'isUsable': false }); @@ -254,7 +259,6 @@ class TimbreController extends GetxController { dataList.firstWhereOrNull((item) => item['type'] == id); if (dataMap != null) { dataMap['type'] = body['data']['assetId']; - dataMap['name'] = '声音复刻${body['data']['assetId']}'; dataMap['isUsable'] = true; dataList.refresh(); _storage.write('timbreList', dataList); @@ -280,8 +284,20 @@ class TimbreController extends GetxController { // 选择音色 void selectTone(Map data) { - if (!data['isUsable']) return; + if (!data['isUsable'] || type.value == data['type']) return; type.value = data['type']; + settingsController.timbreName.value = data['name']; _storage.write('timbre', data['type']); + setSpeechServiceType(); + } + + // 设置语音音色服务类型 + void setSpeechServiceType() { + try { + final factory = Get.find(); + factory.setTimbreServiceType(); + } catch (e) { + // 处理错误 + } } } diff --git a/lib/modules/timbre/views/timbre_view.dart b/lib/modules/timbre/views/timbre_view.dart index 2f67131be..dd82c8d55 100644 --- a/lib/modules/timbre/views/timbre_view.dart +++ b/lib/modules/timbre/views/timbre_view.dart @@ -201,26 +201,36 @@ class TimbreView extends GetView { ], ), ), - Container( - width: 24.w, - height: 24.w, - margin: EdgeInsets.only(left: 12.w), - decoration: BoxDecoration( - color: controller.type.value == data['type'] - ? (isDarkMode ? Colors.teal[300] : Colors.teal[600]) - : (isDarkMode - ? Colors.white.withOpacity(0.1) - : Colors.grey[300]), - shape: BoxShape.circle, - ), - child: controller.type.value == data['type'] - ? Icon( - Icons.check, - size: 16.w, - color: Colors.white, - ) - : null, - ), + data['isUsable'] + ? Container( + width: 24.w, + height: 24.w, + margin: EdgeInsets.only(left: 12.w), + decoration: BoxDecoration( + color: controller.type.value == data['type'] + ? (isDarkMode ? Colors.teal[300] : Colors.teal[600]) + : (isDarkMode + ? Colors.white.withOpacity(0.1) + : Colors.grey[300]), + shape: BoxShape.circle, + ), + child: controller.type.value == data['type'] + ? Icon( + Icons.check, + size: 16.w, + color: Colors.white, + ) + : null, + ) + : SizedBox( + width: 24.w, + height: 24.w, + child: CircularProgressIndicator( + strokeWidth: 2.w, + valueColor: + const AlwaysStoppedAnimation(Colors.blue), + ), + ), ], ), ),