small fixes

This commit is contained in:
2018-08-22 03:36:00 +02:00
parent 034d8b426f
commit 2fb60fce07
4 changed files with 32 additions and 7 deletions

View File

@@ -1,15 +1,29 @@
import speech
import filesystem
MAIN_DIR = b"data/"
def parse_request(data):
''' parse request and call correct function '''
# echo/test connection
# echo/test connection #
cleared_data = is_data_type(b"ECHOREQUEST,",data)
if cleared_data:
return cleared_data
# handle audio transmission #
cleared_data = is_data_type(b"AUDIO_TRANSMISSION,",data)
if cleared_data:
with open("test.wav","wb") as f:
f.write(cleared_data)
return b"SUCCESS"
filename = None
try:
filename, base64_string = cleared_data.split(b',')
filename = MAIN_DIR + filename.split(b"/")[-1] + b".wav"
filename = filename.decode("utf-8")
except ValueError:
return b"ERROR_MALFORMED_REQUEST"
ret = filesystem.save_audio(filename, base64_string)
speech.async_create_transcript(filename)
return ret
# other shit
return b"UNRECOGNIZED_SERVER_OPTION\n"