aboutsummaryrefslogtreecommitdiffstats
path: root/lib/grpc/voice_agent_client.dart
diff options
context:
space:
mode:
authorMalik Talha <talhamalik727x@gmail.com>2023-10-23 02:00:01 +0500
committerMalik Talha <talhamalik727x@gmail.com>2023-10-26 21:36:57 +0500
commit8417e9daeecbdb3847de401b0fcc6304d246a787 (patch)
treea9dafba232ee7e458358861d1356636c079a12da /lib/grpc/voice_agent_client.dart
parent8d38450e46ff3854ade4005c4132edfb1aabb9b4 (diff)
Add flutter voice assistant app
A flutter based gRPC client Voice Assistant made specifically to communicate with the Voice Agent service. SPEC-4906 Signed-off-by: Malik Talha <talhamalik727x@gmail.com> Change-Id: Ic4a382c1cdb78f1a79f985e3d37ce2fb06c53203
Diffstat (limited to 'lib/grpc/voice_agent_client.dart')
-rw-r--r--lib/grpc/voice_agent_client.dart71
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/grpc/voice_agent_client.dart b/lib/grpc/voice_agent_client.dart
new file mode 100644
index 0000000..f25f0d2
--- /dev/null
+++ b/lib/grpc/voice_agent_client.dart
@@ -0,0 +1,71 @@
+import 'dart:async';
+import 'package:grpc/grpc.dart';
+import './generated/voice_agent.pbgrpc.dart';
+
+class VoiceAgentClient {
+ late ClientChannel _channel;
+ late VoiceAgentServiceClient _client;
+
+ VoiceAgentClient(String host, int port) {
+ // Initialize the client channel without connecting immediately
+ _channel = ClientChannel(
+ host,
+ port: port,
+ options: ChannelOptions(
+ credentials: ChannelCredentials.insecure(),
+ ),
+ );
+
+ _client = VoiceAgentServiceClient(_channel);
+ }
+
+ Future<ServiceStatus> checkServiceStatus() async {
+ final empty = Empty();
+ try {
+ final response = await _client.checkServiceStatus(empty);
+ return response;
+ } catch (e) {
+ print('Error calling CheckServiceStatus: $e');
+ // Handle the error gracefully, such as returning an error status
+ return ServiceStatus()..status = false;
+ }
+ }
+
+ Stream<WakeWordStatus> detectWakeWord() {
+ final empty = Empty();
+ try {
+ return _client.detectWakeWord(empty);
+ } catch (e) {
+ print('Error calling DetectWakeWord: $e');
+ // Handle the error gracefully, such as returning a default status
+ return Stream.empty(); // An empty stream as a placeholder
+ }
+ }
+
+ Future<RecognizeResult> recognizeVoiceCommand(
+ Stream<RecognizeControl> controlStream) async {
+ try {
+ final response = await _client.recognizeVoiceCommand(controlStream);
+ return response;
+ } catch (e) {
+ print('Error calling RecognizeVoiceCommand: $e');
+ // Handle the error gracefully, such as returning a default RecognizeResult
+ return RecognizeResult()..status = RecognizeStatusType.REC_ERROR;
+ }
+ }
+
+ Future<ExecuteResult> executeVoiceCommand(ExecuteInput input) async {
+ try {
+ final response = await _client.executeVoiceCommand(input);
+ return response;
+ } catch (e) {
+ print('Error calling ExecuteVoiceCommand: $e');
+ // Handle the error gracefully, such as returning an error status
+ return ExecuteResult()..status = ExecuteStatusType.EXEC_ERROR;
+ }
+ }
+
+ Future<void> shutdown() async {
+ await _channel.shutdown();
+ }
+}