mirror of
https://github.com/FAUSheppy/ths-speech
synced 2025-12-08 23:18:35 +01:00
small fixes
This commit is contained in:
0
python-server/data/.empty
Normal file
0
python-server/data/.empty
Normal file
@@ -20,7 +20,6 @@ class AppRequestHandler(socketserver.BaseRequestHandler):
|
|||||||
data += tmp[:-len("\nterminate\n")]
|
data += tmp[:-len("\nterminate\n")]
|
||||||
break
|
break
|
||||||
data += tmp
|
data += tmp
|
||||||
print("Request: {}".format(data))
|
|
||||||
retval = server_interface.parse_request(data)
|
retval = server_interface.parse_request(data)
|
||||||
self.request.send(retval)
|
self.request.send(retval)
|
||||||
self.request.send(b"terminate\n")
|
self.request.send(b"terminate\n")
|
||||||
|
|||||||
@@ -1,15 +1,29 @@
|
|||||||
|
import speech
|
||||||
|
import filesystem
|
||||||
|
|
||||||
|
MAIN_DIR = b"data/"
|
||||||
|
|
||||||
def parse_request(data):
|
def parse_request(data):
|
||||||
''' parse request and call correct function '''
|
''' parse request and call correct function '''
|
||||||
|
|
||||||
# echo/test connection
|
# echo/test connection #
|
||||||
cleared_data = is_data_type(b"ECHOREQUEST,",data)
|
cleared_data = is_data_type(b"ECHOREQUEST,",data)
|
||||||
if cleared_data:
|
if cleared_data:
|
||||||
return cleared_data
|
return cleared_data
|
||||||
|
|
||||||
|
# handle audio transmission #
|
||||||
cleared_data = is_data_type(b"AUDIO_TRANSMISSION,",data)
|
cleared_data = is_data_type(b"AUDIO_TRANSMISSION,",data)
|
||||||
if cleared_data:
|
if cleared_data:
|
||||||
with open("test.wav","wb") as f:
|
filename = None
|
||||||
f.write(cleared_data)
|
try:
|
||||||
return b"SUCCESS"
|
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
|
# other shit
|
||||||
return b"UNRECOGNIZED_SERVER_OPTION\n"
|
return b"UNRECOGNIZED_SERVER_OPTION\n"
|
||||||
|
|||||||
@@ -1,8 +1,20 @@
|
|||||||
import speech_recognition as spr
|
import speech_recognition as spr
|
||||||
def analyse(file_path):
|
import multiprocessing as mp
|
||||||
|
import os.path
|
||||||
|
import filesystem
|
||||||
|
import log
|
||||||
|
|
||||||
|
def async_create_transcript(filename):
|
||||||
|
mp.Process(target=create_and_save_transcript,args=(filename,)).start()
|
||||||
|
|
||||||
|
def create_and_save_transcript(filename):
|
||||||
|
transcript = analyse(filename)
|
||||||
|
filesystem.save_transcript(transcript)
|
||||||
|
|
||||||
|
def analyse(filename):
|
||||||
''' returns the transcripted audio, or None if the analysis fails '''
|
''' returns the transcripted audio, or None if the analysis fails '''
|
||||||
recognizer = spr.Recognizer()
|
recognizer = spr.Recognizer()
|
||||||
with spr.AudioFile(file_path) as source:
|
with spr.AudioFile(filename) as source:
|
||||||
audio = recognizer.record(source)
|
audio = recognizer.record(source)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user