File size: 654 Bytes
8573823
e9402b5
8573823
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9402b5
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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