Compare commits
No commits in common. "988d343cfaf025eea672c51a7e5a153e86f4eac1" and "ae3a9519503f4394e8025f9f120947b2df9bcd04" have entirely different histories.
988d343cfa
...
ae3a951950
|
|
@ -8,7 +8,6 @@ import '../models/speech_recognition_error.dart';
|
||||||
/// 简化的语音识别录音按钮组件
|
/// 简化的语音识别录音按钮组件
|
||||||
///
|
///
|
||||||
/// 支持依赖注入,保持简单易用的 API
|
/// 支持依赖注入,保持简单易用的 API
|
||||||
/// 支持自定义图标、颜色和提示文本
|
|
||||||
class RecordingButton extends StatefulWidget {
|
class RecordingButton extends StatefulWidget {
|
||||||
/// 语音识别服务实例(可选,默认创建 YxAsrService)
|
/// 语音识别服务实例(可选,默认创建 YxAsrService)
|
||||||
final SpeechRecognitionService? speechService;
|
final SpeechRecognitionService? speechService;
|
||||||
|
|
@ -46,12 +45,6 @@ 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,
|
||||||
|
|
@ -66,8 +59,6 @@ class RecordingButton extends StatefulWidget {
|
||||||
this.disabledColor,
|
this.disabledColor,
|
||||||
this.enabled = true,
|
this.enabled = true,
|
||||||
this.tooltip,
|
this.tooltip,
|
||||||
this.idleIcon,
|
|
||||||
this.recordingIcon,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -233,9 +224,7 @@ class _RecordingButtonState extends State<RecordingButton>
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
child: Icon(
|
child: Icon(
|
||||||
_isListening
|
_isListening ? Icons.stop_rounded : Icons.mic_rounded,
|
||||||
? (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.1
|
version: 1.0.0
|
||||||
homepage: https://github.com/yuanxuan/yx_asr
|
homepage: https://github.com/yuanxuan/yx_asr
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ 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,6 +175,8 @@ void main() {
|
||||||
|
|
||||||
final result = SpeechRecognitionResult(
|
final result = SpeechRecognitionResult(
|
||||||
recognizedWords: '这是一个测试结果',
|
recognizedWords: '这是一个测试结果',
|
||||||
|
confidence: 0.95,
|
||||||
|
alternatives: ['备选1', '备选2', '备选3'],
|
||||||
);
|
);
|
||||||
|
|
||||||
stopwatch.start();
|
stopwatch.start();
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ class TestHelper {
|
||||||
}) {
|
}) {
|
||||||
return SpeechRecognitionResult(
|
return SpeechRecognitionResult(
|
||||||
recognizedWords: text,
|
recognizedWords: text,
|
||||||
|
confidence: confidence,
|
||||||
|
alternatives: alternatives,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,20 @@ 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();
|
||||||
|
|
@ -32,6 +38,8 @@ 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', () {
|
||||||
|
|
@ -39,6 +47,8 @@ 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,14 +88,20 @@ 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();
|
||||||
|
|
@ -114,6 +120,8 @@ 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