Compare commits
3 Commits
ae3a951950
...
988d343cfa
| Author | SHA1 | Date |
|---|---|---|
|
|
988d343cfa | |
|
|
5c42a449d6 | |
|
|
e7ea348bda |
|
|
@ -8,6 +8,7 @@ import '../models/speech_recognition_error.dart';
|
||||||
/// 简化的语音识别录音按钮组件
|
/// 简化的语音识别录音按钮组件
|
||||||
///
|
///
|
||||||
/// 支持依赖注入,保持简单易用的 API
|
/// 支持依赖注入,保持简单易用的 API
|
||||||
|
/// 支持自定义图标、颜色和提示文本
|
||||||
class RecordingButton extends StatefulWidget {
|
class RecordingButton extends StatefulWidget {
|
||||||
/// 语音识别服务实例(可选,默认创建 YxAsrService)
|
/// 语音识别服务实例(可选,默认创建 YxAsrService)
|
||||||
final SpeechRecognitionService? speechService;
|
final SpeechRecognitionService? speechService;
|
||||||
|
|
@ -45,6 +46,12 @@ class RecordingButton extends StatefulWidget {
|
||||||
/// 提示文本
|
/// 提示文本
|
||||||
final String? tooltip;
|
final String? tooltip;
|
||||||
|
|
||||||
|
/// 空闲状态(未录音)时显示的图标
|
||||||
|
final IconData? idleIcon;
|
||||||
|
|
||||||
|
/// 录音状态时显示的图标
|
||||||
|
final IconData? recordingIcon;
|
||||||
|
|
||||||
const RecordingButton({
|
const RecordingButton({
|
||||||
super.key,
|
super.key,
|
||||||
this.speechService,
|
this.speechService,
|
||||||
|
|
@ -59,6 +66,8 @@ class RecordingButton extends StatefulWidget {
|
||||||
this.disabledColor,
|
this.disabledColor,
|
||||||
this.enabled = true,
|
this.enabled = true,
|
||||||
this.tooltip,
|
this.tooltip,
|
||||||
|
this.idleIcon,
|
||||||
|
this.recordingIcon,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -224,7 +233,9 @@ class _RecordingButtonState extends State<RecordingButton>
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
child: Icon(
|
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,
|
size: widget.size * 0.55,
|
||||||
color: iconColor,
|
color: iconColor,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
name: yx_asr
|
name: yx_asr
|
||||||
description: 基于 sherpa_onnx 的 Flutter 语音识别插件,提供完全离线的实时语音转文字功能。
|
description: 基于 sherpa_onnx 的 Flutter 语音识别插件,提供完全离线的实时语音转文字功能。
|
||||||
version: 1.0.0
|
version: 1.0.1
|
||||||
homepage: https://github.com/yuanxuan/yx_asr
|
homepage: https://github.com/yuanxuan/yx_asr
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,6 @@ class MockSpeechService implements SpeechRecognitionService {
|
||||||
void mockResult(String text, {double confidence = 1.0}) {
|
void mockResult(String text, {double confidence = 1.0}) {
|
||||||
_resultController.add(SpeechRecognitionResult(
|
_resultController.add(SpeechRecognitionResult(
|
||||||
recognizedWords: text,
|
recognizedWords: text,
|
||||||
confidence: confidence,
|
|
||||||
alternatives: [],
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -175,8 +175,6 @@ void main() {
|
||||||
|
|
||||||
final result = SpeechRecognitionResult(
|
final result = SpeechRecognitionResult(
|
||||||
recognizedWords: '这是一个测试结果',
|
recognizedWords: '这是一个测试结果',
|
||||||
confidence: 0.95,
|
|
||||||
alternatives: ['备选1', '备选2', '备选3'],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
stopwatch.start();
|
stopwatch.start();
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,6 @@ class TestHelper {
|
||||||
}) {
|
}) {
|
||||||
return SpeechRecognitionResult(
|
return SpeechRecognitionResult(
|
||||||
recognizedWords: text,
|
recognizedWords: text,
|
||||||
confidence: confidence,
|
|
||||||
alternatives: alternatives,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,14 @@ void main() {
|
||||||
test('应该正确创建结果对象', () {
|
test('应该正确创建结果对象', () {
|
||||||
final result = SpeechRecognitionResult(
|
final result = SpeechRecognitionResult(
|
||||||
recognizedWords: '测试文本',
|
recognizedWords: '测试文本',
|
||||||
confidence: 0.95,
|
|
||||||
alternatives: ['备选1', '备选2'],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(result.recognizedWords, '测试文本');
|
expect(result.recognizedWords, '测试文本');
|
||||||
expect(result.confidence, 0.95);
|
|
||||||
expect(result.alternatives, ['备选1', '备选2']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('应该正确转换为 Map', () {
|
test('应该正确转换为 Map', () {
|
||||||
final result = SpeechRecognitionResult(
|
final result = SpeechRecognitionResult(
|
||||||
recognizedWords: '测试',
|
recognizedWords: '测试',
|
||||||
confidence: 0.8,
|
|
||||||
alternatives: [],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final map = result.toMap();
|
final map = result.toMap();
|
||||||
|
|
@ -38,8 +32,6 @@ void main() {
|
||||||
|
|
||||||
final result = SpeechRecognitionResult.fromMap(map);
|
final result = SpeechRecognitionResult.fromMap(map);
|
||||||
expect(result.recognizedWords, '从Map创建');
|
expect(result.recognizedWords, '从Map创建');
|
||||||
expect(result.confidence, 0.9);
|
|
||||||
expect(result.alternatives, ['备选']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('应该处理空的 Map', () {
|
test('应该处理空的 Map', () {
|
||||||
|
|
@ -47,8 +39,6 @@ void main() {
|
||||||
final result = SpeechRecognitionResult.fromMap(map);
|
final result = SpeechRecognitionResult.fromMap(map);
|
||||||
|
|
||||||
expect(result.recognizedWords, '');
|
expect(result.recognizedWords, '');
|
||||||
expect(result.confidence, 0.0);
|
|
||||||
expect(result.alternatives, []);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,20 +88,14 @@ void main() {
|
||||||
test('应该正确创建结果对象', () {
|
test('应该正确创建结果对象', () {
|
||||||
final result = SpeechRecognitionResult(
|
final result = SpeechRecognitionResult(
|
||||||
recognizedWords: '测试文本',
|
recognizedWords: '测试文本',
|
||||||
confidence: 0.95,
|
|
||||||
alternatives: ['备选1', '备选2'],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(result.recognizedWords, '测试文本');
|
expect(result.recognizedWords, '测试文本');
|
||||||
expect(result.confidence, 0.95);
|
|
||||||
expect(result.alternatives, ['备选1', '备选2']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('应该正确转换为 Map', () {
|
test('应该正确转换为 Map', () {
|
||||||
final result = SpeechRecognitionResult(
|
final result = SpeechRecognitionResult(
|
||||||
recognizedWords: '测试',
|
recognizedWords: '测试',
|
||||||
confidence: 0.8,
|
|
||||||
alternatives: [],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final map = result.toMap();
|
final map = result.toMap();
|
||||||
|
|
@ -120,8 +114,6 @@ void main() {
|
||||||
|
|
||||||
final result = SpeechRecognitionResult.fromMap(map);
|
final result = SpeechRecognitionResult.fromMap(map);
|
||||||
expect(result.recognizedWords, '从Map创建');
|
expect(result.recognizedWords, '从Map创建');
|
||||||
expect(result.confidence, 0.9);
|
|
||||||
expect(result.alternatives, ['备选']);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue