aboutsummaryrefslogtreecommitdiffstats
path: root/lib/widgets
diff options
context:
space:
mode:
authorAnuj-S62 <anuj603362@gmail.com>2024-07-11 15:18:31 +0530
committerAnuj-S62 <anuj603362@gmail.com>2024-07-21 19:52:11 +0530
commit0b59086cdddd40689e57969aa7914ba38f1ec2dd (patch)
tree975c38663f57d497eeab0e2649e51308aef9a755 /lib/widgets
parentecd34435c1a74b39bf41d59ad479fdc85d0afb7b (diff)
Update Voice Agent Flutter App
- update voice-agent flutter app to use whisper AI for speech-to-text functionality. - Integrated SharedPreferences to store the application state. Bug-AGL: SPEC-5200 Change-Id: I9a05b1d135c1fa07949333391ff828f166b7fe8e Signed-off-by: Anuj-S62 <anuj603362@gmail.com>
Diffstat (limited to 'lib/widgets')
-rw-r--r--lib/widgets/assistant_mode_choice.dart8
-rw-r--r--lib/widgets/nlu_engine_choice.dart6
-rw-r--r--lib/widgets/online_mode_choice.dart148
-rw-r--r--lib/widgets/stt_model_choice.dart148
4 files changed, 308 insertions, 2 deletions
diff --git a/lib/widgets/assistant_mode_choice.dart b/lib/widgets/assistant_mode_choice.dart
index c2afe5b..2c776df 100644
--- a/lib/widgets/assistant_mode_choice.dart
+++ b/lib/widgets/assistant_mode_choice.dart
@@ -70,6 +70,9 @@
// }
import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+import '../models/app_state.dart';
enum AssistantMode { wakeWord, manual }
@@ -92,7 +95,10 @@ class AssistantModeChoiceState extends State<AssistantModeChoice> {
@override
void initState() {
super.initState();
- _selectedMode = AssistantMode.manual; // Initialize the selection
+ final appState = context.read<AppState>();
+ _selectedMode = appState.isWakeWordMode
+ ? AssistantMode.wakeWord
+ : AssistantMode.manual; // Initialize the selection
_theme = widget.theme;
print(widget.theme);
}
diff --git a/lib/widgets/nlu_engine_choice.dart b/lib/widgets/nlu_engine_choice.dart
index 32db7dd..53a4aaa 100644
--- a/lib/widgets/nlu_engine_choice.dart
+++ b/lib/widgets/nlu_engine_choice.dart
@@ -68,6 +68,9 @@
// }
import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+import '../models/app_state.dart';
enum NLUEngine { snips, rasa }
@@ -90,7 +93,8 @@ class _NLUEngineChoiceState extends State<NLUEngineChoice> {
@override
void initState() {
super.initState();
- _selectedEngine = NLUEngine.snips; // Initialize the selection
+ final appState = context.read<AppState>();
+ _selectedEngine = appState.intentEngine == "snips" ? NLUEngine.snips : NLUEngine.rasa;
_theme = widget.theme;
}
diff --git a/lib/widgets/online_mode_choice.dart b/lib/widgets/online_mode_choice.dart
new file mode 100644
index 0000000..3146d15
--- /dev/null
+++ b/lib/widgets/online_mode_choice.dart
@@ -0,0 +1,148 @@
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+import '../models/app_state.dart';
+
+enum OnlineModeEnum{
+ enabled,
+ disabled
+}
+
+class OnlineModeChoice extends StatefulWidget {
+ final Function(OnlineModeEnum) onModeChanged;
+ final String theme;
+
+ const OnlineModeChoice({
+ Key? key,
+ required this.onModeChanged,
+ required this.theme
+ }) : super(key: key);
+
+ @override
+ State<OnlineModeChoice> createState() => _OnlineModeChoiceState();
+}
+
+class _OnlineModeChoiceState extends State<OnlineModeChoice> {
+ late OnlineModeEnum _selectedMode;
+ late String _theme;
+
+ @override
+ void initState() {
+ super.initState();
+ final appState = context.read<AppState>();
+ _selectedMode = appState.onlineMode ? OnlineModeEnum.enabled : OnlineModeEnum.disabled;
+ _theme = widget.theme;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: <Widget>[
+ InkWell(
+ onTap: () => _onModelChanged(OnlineModeEnum.disabled),
+ borderRadius: BorderRadius.only(
+ topLeft: Radius.circular(20.0),
+ bottomLeft: Radius.circular(20.0),
+ ),
+ child: Container(
+ padding: EdgeInsets.symmetric(horizontal: 17.5, vertical: 5.0),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.only(
+ topLeft: Radius.circular(20.0),
+ bottomLeft: Radius.circular(20.0),
+ ),
+ color: _selectedMode == OnlineModeEnum.disabled
+ ? Colors.green
+ : _theme == "dark" || _theme == "textured-dark"
+ ? Colors.black
+ : Colors.white,
+ border: Border.all(
+ color: Colors.transparent,
+ ),
+ ),
+ child: Row(
+ children: [
+ Icon(
+ _selectedMode == OnlineModeEnum.disabled
+ ? Icons.check
+ : Icons.cloud_off_outlined,
+ color: _selectedMode == OnlineModeEnum.disabled
+ ? Colors.white
+ : Colors.green,
+ ),
+ SizedBox(width: 8),
+ Text(
+ 'Disabled',
+ style: TextStyle(
+ fontWeight: FontWeight.bold,
+ fontSize: 17,
+ color: _selectedMode == OnlineModeEnum.disabled
+ ? Colors.white
+ : Colors.green,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ InkWell(
+ onTap: () => _onModelChanged(OnlineModeEnum.enabled),
+ borderRadius: BorderRadius.only(
+ topRight: Radius.circular(20.0),
+ bottomRight: Radius.circular(20.0),
+ ),
+ child: Container(
+ padding: EdgeInsets.symmetric(horizontal: 17.5, vertical: 5.0),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.only(
+ topRight: Radius.circular(20.0),
+ bottomRight: Radius.circular(20.0),
+ ),
+ color: _selectedMode == OnlineModeEnum.enabled
+ ? Colors.green
+ : _theme == "dark" || _theme == "textured-dark"
+ ? Colors.black
+ : Colors.white,
+ border: Border.all(
+ color: Colors.transparent,
+ ),
+ ),
+ child: Row(
+ children: [
+ Icon(
+ _selectedMode == OnlineModeEnum.enabled
+ ? Icons.check
+ : Icons.cloud_done_outlined,
+ color: _selectedMode == OnlineModeEnum.enabled
+ ? Colors.white
+ : Colors.green,
+ ),
+ SizedBox(width: 8),
+ Text(
+ 'Enabled',
+ style: TextStyle(
+ fontWeight: FontWeight.bold,
+ fontSize: 17,
+ color: _selectedMode == OnlineModeEnum.enabled
+ ? Colors.white
+ : Colors.green,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+
+ void _onModelChanged(OnlineModeEnum newMode) {
+ setState(() {
+ _selectedMode = newMode;
+ });
+
+ // Call the callback function to notify the engine change
+ widget.onModeChanged(newMode);
+ }
+} \ No newline at end of file
diff --git a/lib/widgets/stt_model_choice.dart b/lib/widgets/stt_model_choice.dart
new file mode 100644
index 0000000..fc0e099
--- /dev/null
+++ b/lib/widgets/stt_model_choice.dart
@@ -0,0 +1,148 @@
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+import '../models/app_state.dart';
+
+enum STTModel{
+ vosk,
+ whisper
+}
+
+class STTModelChoice extends StatefulWidget {
+ final Function(STTModel) onModelChanged;
+ final String theme;
+
+ const STTModelChoice({
+ Key? key,
+ required this.onModelChanged,
+ required this.theme
+ }) : super(key: key);
+
+ @override
+ State<STTModelChoice> createState() => _STTModelChoiceState();
+}
+
+class _STTModelChoiceState extends State<STTModelChoice> {
+ late STTModel _selectedModel;
+ late String _theme;
+
+ @override
+ void initState() {
+ super.initState();
+ final appState = context.read<AppState>();
+ _selectedModel = appState.sttFramework == "vosk" ? STTModel.vosk : STTModel.whisper;
+ _theme = widget.theme;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: <Widget>[
+ InkWell(
+ onTap: () => _onModelChanged(STTModel.vosk),
+ borderRadius: BorderRadius.only(
+ topLeft: Radius.circular(20.0),
+ bottomLeft: Radius.circular(20.0),
+ ),
+ child: Container(
+ padding: EdgeInsets.symmetric(horizontal: 17.5, vertical: 5.0),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.only(
+ topLeft: Radius.circular(20.0),
+ bottomLeft: Radius.circular(20.0),
+ ),
+ color: _selectedModel == STTModel.vosk
+ ? Colors.green
+ : _theme == "dark" || _theme == "textured-dark"
+ ? Colors.black
+ : Colors.white,
+ border: Border.all(
+ color: Colors.transparent,
+ ),
+ ),
+ child: Row(
+ children: [
+ Icon(
+ _selectedModel == STTModel.vosk
+ ? Icons.check
+ : Icons.transcribe_sharp,
+ color: _selectedModel == STTModel.vosk
+ ? Colors.white
+ : Colors.green,
+ ),
+ SizedBox(width: 8),
+ Text(
+ 'Vosk',
+ style: TextStyle(
+ fontWeight: FontWeight.bold,
+ fontSize: 17,
+ color: _selectedModel == STTModel.vosk
+ ? Colors.white
+ : Colors.green,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ InkWell(
+ onTap: () => _onModelChanged(STTModel.whisper),
+ borderRadius: BorderRadius.only(
+ topRight: Radius.circular(20.0),
+ bottomRight: Radius.circular(20.0),
+ ),
+ child: Container(
+ padding: EdgeInsets.symmetric(horizontal: 17.5, vertical: 5.0),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.only(
+ topRight: Radius.circular(20.0),
+ bottomRight: Radius.circular(20.0),
+ ),
+ color: _selectedModel == STTModel.whisper
+ ? Colors.green
+ : _theme == "dark" || _theme == "textured-dark"
+ ? Colors.black
+ : Colors.white,
+ border: Border.all(
+ color: Colors.transparent,
+ ),
+ ),
+ child: Row(
+ children: [
+ Icon(
+ _selectedModel == STTModel.whisper
+ ? Icons.check
+ : Icons.transcribe_sharp,
+ color: _selectedModel == STTModel.whisper
+ ? Colors.white
+ : Colors.green,
+ ),
+ SizedBox(width: 8),
+ Text(
+ 'Whisper',
+ style: TextStyle(
+ fontWeight: FontWeight.bold,
+ fontSize: 17,
+ color: _selectedModel == STTModel.whisper
+ ? Colors.white
+ : Colors.green,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+
+ void _onModelChanged(STTModel newModel) {
+ setState(() {
+ _selectedModel = newModel;
+ });
+
+ // Call the callback function to notify the engine change
+ widget.onModelChanged(newModel);
+ }
+} \ No newline at end of file