From 5c42a449d6390392cc3b8d4104f802884a3dbf3b Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 9 Sep 2025 17:48:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89icon=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/widgets/recording_button.dart | 13 ++++++++++++- pubspec.yaml | 2 +- test/mocks/mock_speech_service.dart | 2 -- .../speech_recognition_performance_test.dart | 2 -- test/test_helper.dart | 2 -- test/unit/models_test.dart | 10 ---------- test/unit/yx_asr_service_test.dart | 8 -------- 7 files changed, 13 insertions(+), 26 deletions(-) diff --git a/lib/src/widgets/recording_button.dart b/lib/src/widgets/recording_button.dart index d7011b9..17113cf 100644 --- a/lib/src/widgets/recording_button.dart +++ b/lib/src/widgets/recording_button.dart @@ -8,6 +8,7 @@ import '../models/speech_recognition_error.dart'; /// 简化的语音识别录音按钮组件 /// /// 支持依赖注入,保持简单易用的 API +/// 支持自定义图标、颜色和提示文本 class RecordingButton extends StatefulWidget { /// 语音识别服务实例(可选,默认创建 YxAsrService) final SpeechRecognitionService? speechService; @@ -45,6 +46,12 @@ class RecordingButton extends StatefulWidget { /// 提示文本 final String? tooltip; + /// 空闲状态(未录音)时显示的图标 + final IconData? idleIcon; + + /// 录音状态时显示的图标 + final IconData? recordingIcon; + const RecordingButton({ super.key, this.speechService, @@ -59,6 +66,8 @@ class RecordingButton extends StatefulWidget { this.disabledColor, this.enabled = true, this.tooltip, + this.idleIcon, + this.recordingIcon, }); @override @@ -224,7 +233,9 @@ class _RecordingButtonState extends State bottom: 0, top: 0, child: Icon( - _isListening ? Icons.stop_rounded : Icons.mic_rounded, + _isListening + ? (widget.recordingIcon ?? Icons.stop_rounded) + : (widget.idleIcon ?? Icons.mic_rounded), size: widget.size * 0.55, color: iconColor, ), diff --git a/pubspec.yaml b/pubspec.yaml index e4d3e36..eaf2ee3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: yx_asr description: 基于 sherpa_onnx 的 Flutter 语音识别插件,提供完全离线的实时语音转文字功能。 -version: 1.0.0 +version: 1.0.1 homepage: https://github.com/yuanxuan/yx_asr environment: diff --git a/test/mocks/mock_speech_service.dart b/test/mocks/mock_speech_service.dart index 04c369d..622b4d2 100644 --- a/test/mocks/mock_speech_service.dart +++ b/test/mocks/mock_speech_service.dart @@ -25,8 +25,6 @@ class MockSpeechService implements SpeechRecognitionService { void mockResult(String text, {double confidence = 1.0}) { _resultController.add(SpeechRecognitionResult( recognizedWords: text, - confidence: confidence, - alternatives: [], )); } diff --git a/test/performance/speech_recognition_performance_test.dart b/test/performance/speech_recognition_performance_test.dart index f0b605f..8c4421b 100644 --- a/test/performance/speech_recognition_performance_test.dart +++ b/test/performance/speech_recognition_performance_test.dart @@ -175,8 +175,6 @@ void main() { final result = SpeechRecognitionResult( recognizedWords: '这是一个测试结果', - confidence: 0.95, - alternatives: ['备选1', '备选2', '备选3'], ); stopwatch.start(); diff --git a/test/test_helper.dart b/test/test_helper.dart index 82b9d2b..c2afa58 100644 --- a/test/test_helper.dart +++ b/test/test_helper.dart @@ -43,8 +43,6 @@ class TestHelper { }) { return SpeechRecognitionResult( recognizedWords: text, - confidence: confidence, - alternatives: alternatives, ); } diff --git a/test/unit/models_test.dart b/test/unit/models_test.dart index fc7c27f..b83b36a 100644 --- a/test/unit/models_test.dart +++ b/test/unit/models_test.dart @@ -6,20 +6,14 @@ void main() { test('应该正确创建结果对象', () { final result = SpeechRecognitionResult( recognizedWords: '测试文本', - confidence: 0.95, - alternatives: ['备选1', '备选2'], ); expect(result.recognizedWords, '测试文本'); - expect(result.confidence, 0.95); - expect(result.alternatives, ['备选1', '备选2']); }); test('应该正确转换为 Map', () { final result = SpeechRecognitionResult( recognizedWords: '测试', - confidence: 0.8, - alternatives: [], ); final map = result.toMap(); @@ -38,8 +32,6 @@ void main() { final result = SpeechRecognitionResult.fromMap(map); expect(result.recognizedWords, '从Map创建'); - expect(result.confidence, 0.9); - expect(result.alternatives, ['备选']); }); test('应该处理空的 Map', () { @@ -47,8 +39,6 @@ void main() { final result = SpeechRecognitionResult.fromMap(map); expect(result.recognizedWords, ''); - expect(result.confidence, 0.0); - expect(result.alternatives, []); }); }); diff --git a/test/unit/yx_asr_service_test.dart b/test/unit/yx_asr_service_test.dart index 5220a0a..a08d10e 100644 --- a/test/unit/yx_asr_service_test.dart +++ b/test/unit/yx_asr_service_test.dart @@ -88,20 +88,14 @@ void main() { test('应该正确创建结果对象', () { final result = SpeechRecognitionResult( recognizedWords: '测试文本', - confidence: 0.95, - alternatives: ['备选1', '备选2'], ); expect(result.recognizedWords, '测试文本'); - expect(result.confidence, 0.95); - expect(result.alternatives, ['备选1', '备选2']); }); test('应该正确转换为 Map', () { final result = SpeechRecognitionResult( recognizedWords: '测试', - confidence: 0.8, - alternatives: [], ); final map = result.toMap(); @@ -120,8 +114,6 @@ void main() { final result = SpeechRecognitionResult.fromMap(map); expect(result.recognizedWords, '从Map创建'); - expect(result.confidence, 0.9); - expect(result.alternatives, ['备选']); }); });