From 8417e9daeecbdb3847de401b0fcc6304d246a787 Mon Sep 17 00:00:00 2001 From: Malik Talha Date: Mon, 23 Oct 2023 02:00:01 +0500 Subject: 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 Change-Id: Ic4a382c1cdb78f1a79f985e3d37ce2fb06c53203 --- lib/grpc/voice_agent_client.dart | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 lib/grpc/voice_agent_client.dart (limited to 'lib/grpc/voice_agent_client.dart') 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 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 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 recognizeVoiceCommand( + Stream 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 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 shutdown() async { + await _channel.shutdown(); + } +} -- cgit