-
Notifications
You must be signed in to change notification settings - Fork 0
/
vocal_client.py
63 lines (48 loc) · 2.27 KB
/
vocal_client.py
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
import threading
import voice
from client_socket import ClientSocket
def voice_command(clientsocket):
"""Show available commands and send user choice to the server.
This function will (until terminated by the user) show the available
set of commands provided by the application. It then will call another
function to listen and treat the user audio input. After this, it will
check the response for errors and listen again in case it find any of them.
Then, this function will print the audio command translated to text and will
send this data to the server.
Parameters
----------
clientsocket : ClientSocket
Instance of the class that handles socket connections on the client side.
"""
while True:
try:
text = input("\nHit ENTER for a new command.\nCTRL + C to quit.\n")
if text == "":
# Showing first instructions
print(voice.get_options())
# Listening from microphone
sentence = voice.listen_sentence_from_mic(voice.recognizer, voice.microphone)
# Checking for errors
while sentence["error"]:
print("ERROR: {}".format(sentence["error"]))
print("Say something: ")
sentence = voice.listen_sentence_from_mic(voice.recognizer, voice.microphone)
# Print sentence
print("Your command was: {}".format(sentence["transcription"]))
# Sending command via socket
clientsocket.send_command(sentence["transcription"].encode())
except (KeyboardInterrupt, SystemExit):
print("\n\nYou've finished this program. Thanks for using it. ;)")
break
if __name__ == "__main__":
host = "192.168.0.24"
port = 6002
# Creates an instance of the class that handles sockets
client_socket = ClientSocket(host, port)
# Creating thread to send instructions to the server
voice_command_thread = threading.Thread(target=voice_command, args=(client_socket,))
# Creating thread to check the status sent by the server
checking_thread = threading.Thread(target=client_socket.check_status)
# Starting all threads
voice_command_thread.start()
checking_thread.start()