import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../controllers/asr_test_controller.dart'; class AsrTestView extends GetView { const AsrTestView({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Azure 语音识别测试'), centerTitle: true, ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ // 识别模式选择 Card( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( '识别模式', style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 8), Obx(() => Row( children: [ Expanded( child: RadioListTile( title: const Text('一次性识别'), value: false, groupValue: controller.isContinuous.value, onChanged: (value) { if (value != null) { controller.isContinuous.value = value; } }, ), ), Expanded( child: RadioListTile( title: const Text('连续识别'), value: true, groupValue: controller.isContinuous.value, onChanged: (value) { if (value != null) { controller.isContinuous.value = value; } }, ), ), ], )), ], ), ), ), const SizedBox(height: 16), // 录音控制 Card( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( '录音控制', style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 16), Center( child: Obx(() => controller.isListening.value ? ElevatedButton.icon( onPressed: () => controller.stopListening(), icon: const Icon(Icons.stop), label: const Text('停止录音'), style: ElevatedButton.styleFrom( backgroundColor: Colors.red, foregroundColor: Colors.white, padding: const EdgeInsets.symmetric( horizontal: 24, vertical: 12, ), ), ) : ElevatedButton.icon( onPressed: () => controller.startListening(), icon: const Icon(Icons.mic), label: const Text('开始录音'), style: ElevatedButton.styleFrom( backgroundColor: Colors.blue, foregroundColor: Colors.white, padding: const EdgeInsets.symmetric( horizontal: 24, vertical: 12, ), ), ), ), ), ], ), ), ), const SizedBox(height: 16), // 识别结果 Expanded( child: Card( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ const Text( '识别结果', style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, ), ), IconButton( icon: const Icon(Icons.clear), onPressed: () => controller.clearResults(), tooltip: '清空结果', ), ], ), const SizedBox(height: 8), Expanded( child: Container( padding: const EdgeInsets.all(8.0), decoration: BoxDecoration( border: Border.all(color: Colors.grey), borderRadius: BorderRadius.circular(4.0), ), child: Obx(() => ListView.builder( itemCount: controller.recognitionResults.length, itemBuilder: (context, index) { final result = controller.recognitionResults[index]; return Padding( padding: const EdgeInsets.symmetric(vertical: 4.0), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( '${index + 1}. ', style: const TextStyle( fontWeight: FontWeight.bold, ), ), Expanded( child: Text(result), ), ], ), ); }, )), ), ), ], ), ), ), ), const SizedBox(height: 16), // 状态显示 Card( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( '状态', style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 8), Obx(() => Text( controller.isListening.value ? '正在录音...' : '就绪', style: TextStyle( color: controller.isListening.value ? Colors.green : Colors.grey, fontWeight: FontWeight.bold, ), )), const SizedBox(height: 8), Obx(() => controller.errorMessage.value.isNotEmpty ? Text( '错误: ${controller.errorMessage.value}', style: const TextStyle( color: Colors.red, ), ) : const SizedBox.shrink()), ], ), ), ), ], ), ), ); } }