Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
GroupD3/clientWithSpeak.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
23 lines (20 sloc)
885 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import socket | |
import win32com.client as wincl | |
client = socket.socket() # Connect to IP:Port | |
port = 12346 | |
client.connect(('localhost', port)) | |
try: | |
while True: | |
msg = input('>') # User inputs a message | |
client.send( msg.encode('utf-8') ) # Encode the messsage in bits and send it to server | |
rawmsg = client.recv(1024) # recieve up to 1024 bytes | |
msg = rawmsg.decode('utf-8').rstrip('\r\n') # Decode received message from bits to string | |
print(msg) # convert and clean the input | |
speak = wincl.Dispatch("SAPI.SpVoice") | |
msg = msg.replace('m/s','meters per second') # So speach reads m/s correctly | |
speak.Speak(msg) | |
except KeyboardInterrupt: | |
print('Shutdown') | |
client.shutdown(1) | |
client.close() |