mirror of
https://github.com/FAUSheppy/ths-speech
synced 2025-12-09 18:58:34 +01:00
chain audio implemented
This commit is contained in:
40
python-server/filesystem.py
Normal file
40
python-server/filesystem.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import base64
|
||||
import os.path
|
||||
from pydub import AudioSegment
|
||||
|
||||
def save_audio(filename, base64_string):
|
||||
decoded = None
|
||||
orig_filename = filename[:-4]+"_orig"
|
||||
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)
|
||||
AudioSegment.from_file(orig_filename).export(filename,format="wav")
|
||||
return b"SUCCESS"
|
||||
|
||||
def save_audio_chain(filenames, base64_strings):
|
||||
compleAudio = None
|
||||
for fname in filenames:
|
||||
decoded = None
|
||||
orig_filename = fname[:-4]+"_orig"
|
||||
try:
|
||||
decoded = base64.b64decode(base64_string)
|
||||
except TypeError:
|
||||
return b"ERROR_INVALID_ENCODING_64"
|
||||
with open(orig_filename,"wb") as f:
|
||||
f.write(decoded)
|
||||
if compleAudio == None:
|
||||
completeAudio = AudioSegment.from_file(orig_filename)
|
||||
else:
|
||||
completeAudio += [AudioSegment.from_file(orig_filename)]
|
||||
completeAudio.export(filenames[0],format="wav")
|
||||
|
||||
def save_transcript(filename, transcript):
|
||||
if os.path.isfile(filename):
|
||||
pass
|
||||
with open(filename + "_transcript","w") as f:
|
||||
f.write(transcript)
|
||||
Reference in New Issue
Block a user