mirror of
https://github.com/FAUSheppy/ths-speech
synced 2025-12-07 16:21:36 +01:00
fixes for samba
This commit is contained in:
@@ -2,22 +2,28 @@ import base64
|
||||
import os.path
|
||||
import audiosegment_wrapper as AudioSegment
|
||||
|
||||
audiofiles = []
|
||||
FTP_DIR = "/home/ths/"
|
||||
|
||||
def save_audio(filename, base64_string):
|
||||
global audiofiles
|
||||
audiofiles += [filename[:-4]]
|
||||
decoded = None
|
||||
orig_filename = filename[:-4]+"_orig"
|
||||
with open("latestBase64","wb") as f:
|
||||
f.write(base64_string)
|
||||
try:
|
||||
decoded = base64.b64decode(base64_string)
|
||||
except TypeError:
|
||||
return b"ERROR_INVALID_ENCODING_64"
|
||||
#if os.path.isfile(filename):
|
||||
# return b"ERROR_FILE_EXISTS"
|
||||
with open(orig_filename,"wb") as f:
|
||||
f.write(decoded)
|
||||
if os.path.isfile(filename):
|
||||
return b"ERROR_FILE_EXISTS"
|
||||
write_file(orig_filename, decoded)
|
||||
|
||||
seg = AudioSegment.from_file(orig_filename)
|
||||
seg = seg.resample(sample_rate_Hz=32000, sample_width=2, channels=1)
|
||||
|
||||
seg.export(filename,format="wav")
|
||||
seg.export(FTP_DIR + filename,format="wav")
|
||||
|
||||
return b"SUCCESS"
|
||||
|
||||
def save_audio_chain(file_str_tupels):
|
||||
@@ -41,20 +47,31 @@ def save_audio_chain(file_str_tupels):
|
||||
else:
|
||||
completeAudio = completeAudio.resample(sample_rate_Hz=32000, sample_width=2, channels=1)
|
||||
completeAudio.export(file_str_tupels[0][0],format="wav")
|
||||
completeAudio.export(FTP_DIR + file_str_tupels[0][0],format="wav")
|
||||
return b"SUCCESS"
|
||||
|
||||
def save_transcript(filename, transcript):
|
||||
global audiofiles
|
||||
try:
|
||||
audiofiles.remove(filename[:4])
|
||||
except:
|
||||
print("Audiofile not in working list")
|
||||
if os.path.isfile(filename):
|
||||
pass
|
||||
with open(filename + "_transcript","w") as f:
|
||||
f.write(transcript)
|
||||
with open(FTP_DIR + filename + "_transcript","w") as f:
|
||||
f.write(transcript)
|
||||
|
||||
def get_transcript(filename):
|
||||
global audiofiles
|
||||
try:
|
||||
with open("data/" + filename + ".wav_transcript","r") as f:
|
||||
return f.read()
|
||||
except FileNotFoundError:
|
||||
return "File not found on Server!"
|
||||
if filename in audiofiles:
|
||||
return "ERROR_FILE_STILL_IN_WORK"
|
||||
return "ERROR_FILE_NOT_AVAILIABLE"
|
||||
|
||||
def filelist():
|
||||
return ""
|
||||
@@ -64,3 +81,10 @@ def fileinfo(filename):
|
||||
|
||||
def copy_to_output(filename):
|
||||
return ""
|
||||
|
||||
def write_file(filename, data):
|
||||
FTP_DIR = "/home/ths/"
|
||||
with open(FTP_DIR + filename,"wb") as f:
|
||||
f.write(data)
|
||||
with open(filename,"wb") as f:
|
||||
f.write(data)
|
||||
|
||||
@@ -41,6 +41,8 @@ def parse_request(data):
|
||||
except ValueError:
|
||||
return b"ERROR_MALFORMED_REQUEST"
|
||||
ret = filesystem.save_audio(filename, base64_string)
|
||||
if b"ERROR" in ret:
|
||||
return ret
|
||||
speech.async_create_transcript(filename)
|
||||
return ret
|
||||
|
||||
@@ -58,6 +60,8 @@ def parse_request(data):
|
||||
return bytes("ERROR_INVALID_NUMBER_FILES_{}".format(len(file_str_tuples)),"utf-8")
|
||||
|
||||
ret = filesystem.save_audio_chain(file_str_tuples);
|
||||
if b"ERROR" in ret:
|
||||
return ret
|
||||
speech.async_create_transcript(file_str_tuples[0][0])
|
||||
return ret
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import os.path
|
||||
import filesystem
|
||||
import log
|
||||
import transcribe_async
|
||||
import os
|
||||
|
||||
USE_FREE=False
|
||||
USE_PAID=True
|
||||
@@ -15,6 +16,7 @@ def async_create_transcript(filename):
|
||||
def create_and_save_transcript(filename):
|
||||
transcript = analyse(filename)
|
||||
filesystem.save_transcript(filename, transcript)
|
||||
os.system("../permissions.sh")
|
||||
|
||||
def analyse(filename):
|
||||
''' returns the transcripted audio, or None if the analysis fails '''
|
||||
|
||||
@@ -64,6 +64,8 @@ def transcribe_gcs(gcs_uri):
|
||||
ret = ""
|
||||
for result in response.results:
|
||||
# The first alternative is the most likely one for this portion.
|
||||
if len(result.alternatives) < 1:
|
||||
continue
|
||||
ret += result.alternatives[0].transcript
|
||||
print(u'Transcript: {}'.format(result.alternatives[0].transcript))
|
||||
print('Confidence: {}'.format(result.alternatives[0].confidence))
|
||||
|
||||
Reference in New Issue
Block a user