feat: 新增语音唤醒
唤醒的逻辑跟长按的逻辑不一样,不能像之前那样长按图标来录音,结束长按来结束录音
This commit is contained in:
@@ -3,6 +3,8 @@ import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:ai_chat_assistant/ai_chat_assistant.dart';
|
||||
|
||||
import 'pages/home.dart';
|
||||
|
||||
class VehicleCommandClent extends VehicleCommandHandler {
|
||||
@override
|
||||
AIChatCommandCubit? get commandCubit => super.commandCubit;
|
||||
@@ -13,7 +15,6 @@ class VehicleCommandClent extends VehicleCommandHandler {
|
||||
print('执行车控命令: ${command.type}, 参数: ${command.params}');
|
||||
|
||||
if (commandCubit != null) {
|
||||
|
||||
commandCubit?.emit(AIChatCommandState(
|
||||
commandId: command.commandId,
|
||||
commandType: command.type,
|
||||
@@ -64,6 +65,8 @@ void main() async {
|
||||
AIChatAssistantManager.instance.setupCommandHandle(commandHandler: VehicleCommandClent());
|
||||
|
||||
runApp(const MyApp());
|
||||
|
||||
AIChatAssistantManager.instance.setWakeWordDetection(true);
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@@ -77,18 +80,7 @@ class MyApp extends StatelessWidget {
|
||||
primarySwatch: Colors.blue,
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const ExampleHomePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ExampleHomePage extends StatelessWidget {
|
||||
const ExampleHomePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Scaffold(
|
||||
body: ChatAssistantApp(),
|
||||
home: HomePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
62
example/lib/pages/home.dart
Normal file
62
example/lib/pages/home.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ai_chat_assistant/ai_chat_assistant.dart';
|
||||
|
||||
import 'setting.dart';
|
||||
|
||||
class ChatAssistantPage extends StatelessWidget {
|
||||
const ChatAssistantPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: ChatAssistantApp(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
HomePage({super.key});
|
||||
|
||||
final items = [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.home),
|
||||
label: 'Home',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.settings),
|
||||
label: 'Settings',
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> {
|
||||
int _selectedIndex = 0;
|
||||
|
||||
final List<Widget> _pages = <Widget>[
|
||||
ChatAssistantPage(),
|
||||
SettingPage(),
|
||||
];
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: _pages.elementAt(_selectedIndex),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
items: widget.items,
|
||||
selectedItemColor: Colors.blue,
|
||||
unselectedItemColor: Colors.grey,
|
||||
currentIndex: _selectedIndex,
|
||||
onTap: _onItemTapped,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
29
example/lib/pages/setting.dart
Normal file
29
example/lib/pages/setting.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SettingPage extends StatefulWidget {
|
||||
const SettingPage({super.key});
|
||||
|
||||
@override
|
||||
State<SettingPage> createState() => _SettingPageState();
|
||||
}
|
||||
|
||||
class _SettingPageState extends State<SettingPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('设置'),
|
||||
),
|
||||
body: const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('设置页面'),
|
||||
SizedBox(height: 20),
|
||||
Text('这里可以添加更多设置选项'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user