YingxuHe's picture
add mic button
e9402b5
raw
history blame contribute delete
654 Bytes
import io
import re
from datetime import datetime
from scipy.io.wavfile import write
import librosa
def get_current_strftime():
return datetime.now().strftime(r'%d-%m-%y-%H-%M-%S')
def bytes_to_array(audio_bytes):
audio_array, _ = librosa.load(
io.BytesIO(audio_bytes),
sr=16000
)
return audio_array
def array_to_bytes(audio_array):
bytes_wav = bytes()
byte_io = io.BytesIO(bytes_wav)
write(byte_io, 16000, audio_array)
return byte_io.read()
def postprocess_voice_transcription(text):
text = re.sub("<.*>:?|\(.*\)|\[.*\]", "", text)
text = re.sub("\s+", " ", text).strip()
return text