mirror of
https://github.com/FAUSheppy/ths-speech
synced 2025-12-08 19:28:33 +01:00
spr
This commit is contained in:
@@ -5,15 +5,34 @@ MAIN_DIR = b"data/"
|
||||
|
||||
def parse_request(data):
|
||||
''' parse request and call correct function '''
|
||||
|
||||
#return b"DUMMY"
|
||||
print(data.split(b",")[0])
|
||||
# echo/test connection #
|
||||
cleared_data = is_data_type(b"ECHOREQUEST,",data)
|
||||
if cleared_data:
|
||||
return cleared_data
|
||||
|
||||
# reply transcript #
|
||||
cleared_data = is_data_type(b"GET_TRANSCRIPT,",data)
|
||||
if cleared_data:
|
||||
filename = data.decode("utf-8")
|
||||
return filesystem.get_transcript().encode("utf-8")
|
||||
|
||||
# get single file info #
|
||||
cleared_data = is_data_type(b"GET_FILEINFO,",data)
|
||||
if cleared_data:
|
||||
filename = data.decode("utf-8")
|
||||
return filesystem.fileinfo(filename).encode("utf-8")
|
||||
|
||||
# get single file info #
|
||||
cleared_data = is_data_type(b"GET_FILEINFO_ALL,",data)
|
||||
if cleared_data:
|
||||
return filesystem.filelist().encode("utf-8")
|
||||
|
||||
# handle audio transmission #
|
||||
cleared_data = is_data_type(b"AUDIO_TRANSMISSION,",data)
|
||||
if cleared_data:
|
||||
print("Handling audio transmission")
|
||||
filename = None
|
||||
try:
|
||||
filename, base64_string = cleared_data.split(b',')
|
||||
@@ -27,17 +46,20 @@ def parse_request(data):
|
||||
|
||||
# handle a chain of audiotransmissions #
|
||||
if data.startswith(b"CHAIN_AUDIO_TRANSMISSION"):
|
||||
files = []
|
||||
base64_strings = []
|
||||
for el in data.split(b"|"):
|
||||
file_str_tuples = []
|
||||
arr = data.split(b"|")
|
||||
for el in arr[1:-1]:
|
||||
filename, base64_string = el.split(b',')
|
||||
filename = MAIN_DIR + filename.split(b"/")[-1] + b".wav"
|
||||
filename = filename.decode("utf-8")
|
||||
files += [filename]
|
||||
base64_strings += [base64_string]
|
||||
filesystem.save_audio_chain(files,base64_string);
|
||||
speech.async_create_transcript(files[0])
|
||||
return b"SUCCESS"
|
||||
file_str_tuples += [(filename,base64_string)]
|
||||
|
||||
if len(file_str_tuples) < 2: # a chain has 2 or more elements
|
||||
return bytes("ERROR_INVALID_NUMBER_FILES_{}".format(len(file_str_tuples)),"utf-8")
|
||||
|
||||
ret = filesystem.save_audio_chain(file_str_tuples);
|
||||
speech.async_create_transcript(file_str_tuples[0][0])
|
||||
return ret
|
||||
|
||||
|
||||
# other shit
|
||||
@@ -80,3 +102,4 @@ def recive_transcribe_request(audiofile):
|
||||
|
||||
def android_unittest_transcribe_request(audiofile):
|
||||
''' the android unittests append a special keyword, requests are dummy handled '''
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user