chain audio implemented

This commit is contained in:
2018-08-22 05:40:51 +02:00
parent e6412946e8
commit 8016a3dc92
5 changed files with 58 additions and 2 deletions

View 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)