aboutsummaryrefslogtreecommitdiffstats
path: root/agl_service_voiceagent/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'agl_service_voiceagent/client.py')
-rw-r--r--agl_service_voiceagent/client.py67
1 files changed, 63 insertions, 4 deletions
diff --git a/agl_service_voiceagent/client.py b/agl_service_voiceagent/client.py
index 88ef785..ee7bc52 100644
--- a/agl_service_voiceagent/client.py
+++ b/agl_service_voiceagent/client.py
@@ -14,16 +14,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import sys
+sys.path.append("../")
import time
import grpc
from agl_service_voiceagent.generated import voice_agent_pb2
from agl_service_voiceagent.generated import voice_agent_pb2_grpc
-def run_client(server_address, server_port, action, mode, nlu_engine, recording_time):
+def run_client(server_address, server_port, action, mode, nlu_engine, recording_time,stt_framework,online_mode):
SERVER_URL = server_address + ":" + server_port
nlu_engine = voice_agent_pb2.RASA if nlu_engine == "rasa" else voice_agent_pb2.SNIPS
print("Starting Voice Agent Client...")
print(f"Client connecting to URL: {SERVER_URL}")
+ print("STT Framework:", stt_framework)
with grpc.insecure_channel(SERVER_URL) as channel:
print("Press Ctrl+C to stop the client.")
print("Voice Agent Client started!")
@@ -51,18 +54,74 @@ def run_client(server_address, server_port, action, mode, nlu_engine, recording_
elif action == 'ExecuteVoiceCommand':
if mode == 'auto':
- raise ValueError("[-] Auto mode is not implemented yet.")
+ # raise ValueError("[-] Auto mode is not implemented yet.")
+ stub = voice_agent_pb2_grpc.VoiceAgentServiceStub(channel=channel)
+ stt_framework = voice_agent_pb2.VOSK if stt_framework == "vosk" else voice_agent_pb2.WHISPER
+ online_mode = voice_agent_pb2.ONLINE if online_mode == True else voice_agent_pb2.OFFLINE
+ while(True):
+ wake_request = voice_agent_pb2.Empty()
+ wake_results = stub.DetectWakeWord(wake_request)
+ wake_word_detected = False
+ for wake_result in wake_results:
+ print("Wake word status: ", wake_word_detected)
+ if wake_result.status:
+ print("Wake word status: ", wake_result.status)
+ wake_word_detected = True
+ break
+ print("Wake word detected: ", wake_word_detected)
+ if wake_word_detected:
+ print("[+] Wake Word detected! Recording voice command...")
+ record_start_request = voice_agent_pb2.RecognizeVoiceControl(action=voice_agent_pb2.START, nlu_model=nlu_engine, record_mode=voice_agent_pb2.MANUAL, stt_framework=stt_framework,online_mode=online_mode,)
+ response = stub.RecognizeVoiceCommand(iter([record_start_request]))
+ stream_id = response.stream_id
+
+ time.sleep(recording_time) # pause here for the number of seconds passed by user or default 5 seconds
+
+ record_stop_request = voice_agent_pb2.RecognizeVoiceControl(action=voice_agent_pb2.STOP, nlu_model=nlu_engine, record_mode=voice_agent_pb2.MANUAL, stream_id=stream_id,stt_framework=stt_framework,online_mode=online_mode,)
+ record_result = stub.RecognizeVoiceCommand(iter([record_stop_request]))
+ print("[+] Voice command recording ended!")
+
+ status = "Uh oh! Status is unknown."
+ if record_result.status == voice_agent_pb2.REC_SUCCESS:
+ status = "Yay! Status is success."
+ elif record_result.status == voice_agent_pb2.VOICE_NOT_RECOGNIZED:
+ status = "Voice not recognized."
+ elif record_result.status == voice_agent_pb2.INTENT_NOT_RECOGNIZED:
+ status = "Intent not recognized."
+
+ # Process the response
+ print("Status:", status)
+ print("Command:", record_result.command)
+ print("Intent:", record_result.intent)
+ intent_slots = []
+ for slot in record_result.intent_slots:
+ print("Slot Name:", slot.name)
+ print("Slot Value:", slot.value)
+ i_slot = voice_agent_pb2.IntentSlot(name=slot.name, value=slot.value)
+ intent_slots.append(i_slot)
+
+ if record_result.status == voice_agent_pb2.REC_SUCCESS:
+ print("[+] Executing voice command...")
+ exec_voice_command_request = voice_agent_pb2.ExecuteInput(intent=record_result.intent, intent_slots=intent_slots)
+ response = stub.ExecuteCommand(exec_voice_command_request)
+ print("Response:", response)
+ wake_word_detected = False
+ time.sleep(1)
+
+
elif mode == 'manual':
stub = voice_agent_pb2_grpc.VoiceAgentServiceStub(channel)
+ stt_framework = voice_agent_pb2.VOSK if stt_framework == "vosk" else voice_agent_pb2.WHISPER
+ online_mode = voice_agent_pb2.ONLINE if online_mode == True else voice_agent_pb2.OFFLINE
print("[+] Recording voice command in manual mode...")
- record_start_request = voice_agent_pb2.RecognizeVoiceControl(action=voice_agent_pb2.START, nlu_model=nlu_engine, record_mode=voice_agent_pb2.MANUAL)
+ record_start_request = voice_agent_pb2.RecognizeVoiceControl(action=voice_agent_pb2.START, nlu_model=nlu_engine, record_mode=voice_agent_pb2.MANUAL, stt_framework=stt_framework,online_mode=online_mode,)
response = stub.RecognizeVoiceCommand(iter([record_start_request]))
stream_id = response.stream_id
time.sleep(recording_time) # pause here for the number of seconds passed by user or default 5 seconds
- record_stop_request = voice_agent_pb2.RecognizeVoiceControl(action=voice_agent_pb2.STOP, nlu_model=nlu_engine, record_mode=voice_agent_pb2.MANUAL, stream_id=stream_id)
+ record_stop_request = voice_agent_pb2.RecognizeVoiceControl(action=voice_agent_pb2.STOP, nlu_model=nlu_engine, record_mode=voice_agent_pb2.MANUAL, stream_id=stream_id,stt_framework=stt_framework,online_mode=online_mode,)
record_result = stub.RecognizeVoiceCommand(iter([record_stop_request]))
print("[+] Voice command recording ended!")