1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
import 'package:protos/val_api.dart';
import '../../export.dart';
import '../models/voice_assistant_state.dart';
class VoiceAssistantStateNotifier extends Notifier<VoiceAssistantState>{
@override
VoiceAssistantState build() {
return const VoiceAssistantState.initial();
}
void updateVoiceAssistantState(VoiceAssistantState newState){
state = newState;
}
void updateVoiceAssistantStateWith({
bool? isWakeWordMode,
bool? isVoiceAssistantEnable,
bool? voiceAssistantOverlay,
bool? isOnlineMode,
bool? isOnlineModeAvailable,
String? wakeWord,
SttModel? sttModel,
String? streamId,
bool? isCommandProcessing,
String? commandProcessingText,
int? recordingTime,
bool? buttonPressed,
bool? isRecording,
String? command,
String? commandResponse,
bool? isWakeWordDetected,
bool? showOverLay,
}){
state = state.copyWith(
isWakeWordMode: isWakeWordMode,
isVoiceAssistantEnable: isVoiceAssistantEnable,
voiceAssistantOverlay: voiceAssistantOverlay,
isOnlineMode: isOnlineMode,
isOnlineModeAvailable: isOnlineModeAvailable,
wakeWord: wakeWord,
sttModel: sttModel,
streamId: streamId,
isCommandProcessing: isCommandProcessing,
commandProcessingText: commandProcessingText,
recordingTime: recordingTime,
buttonPressed: buttonPressed,
isRecording: isRecording,
command: command,
commandResponse: commandResponse,
isWakeWordDetected: isWakeWordDetected,
showOverLay: showOverLay,
);
}
void resetToDefaults(){
state = const VoiceAssistantState.initial();
}
void updateWakeWordDetected(bool isWakeWordDetected){
state = state.copyWith(isWakeWordDetected: isWakeWordDetected);
}
void toggleShowOverlay(bool value){
state = state.copyWith(showOverLay: value);
}
bool toggleWakeWordMode(){
state = state.copyWith(isWakeWordMode: !state.isWakeWordMode);
return state.isWakeWordMode;
}
Future<void> toggleVoiceAssistant(ServiceStatus status) async {
bool prevState = state.isVoiceAssistantEnable;
if(!prevState){
if(status.status){
state = state.copyWith(isVoiceAssistantEnable: !state.isVoiceAssistantEnable);
state = state.copyWith(wakeWord: status.wakeWord);
state = state.copyWith(isOnlineModeAvailable: status.onlineMode);
}
else{
debugPrint("Failed to start the Voice Assistant");
}
}
else{
state = state.copyWith(isVoiceAssistantEnable: !state.isVoiceAssistantEnable);
if(state.isWakeWordMode){
state = state.copyWith(isWakeWordMode: false);
}
}
}
void toggleVoiceAssistantOverlay(){
state = state.copyWith(voiceAssistantOverlay: !state.voiceAssistantOverlay);
}
void toggleOnlineMode(){
state = state.copyWith(isOnlineMode: !state.isOnlineMode);
}
void updateWakeWord(String wakeWord){
state = state.copyWith(wakeWord: wakeWord);
}
void updateSttModel(SttModel sttModel){
state = state.copyWith(sttModel: sttModel);
}
void updateStreamId(String streamId){
state = state.copyWith(streamId: streamId);
}
void updateIsCommandProcessing(bool isCommandProcessing){
state = state.copyWith(isCommandProcessing: isCommandProcessing);
}
void updateCommandProcessingText(String commandProcessingText){
state = state.copyWith(commandProcessingText: commandProcessingText);
}
void updateRecordingTime(int recordingTime){
state = state.copyWith(recordingTime: recordingTime);
}
void updateIsRecording(){
state = state.copyWith(isRecording: !state.isRecording);
}
void updateCommand(String? command){
state = state.copyWith(command: command);
}
void updateCommandResponse(String? commandResponse){
state = state.copyWith(commandResponse: commandResponse);
}
bool toggleButtonPressed(){
bool prevState = state.buttonPressed;
state = state.copyWith(buttonPressed: !state.buttonPressed);
return !prevState;
}
void updateButtonPressed(bool buttonPressed){
state = state.copyWith(buttonPressed: buttonPressed);
}
}
|