File size: 2,048 Bytes
9362e89
5ec3488
 
 
 
9362e89
5ec3488
 
9362e89
5ec3488
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9362e89
5ec3488
 
 
9362e89
 
 
 
 
 
 
 
e1c578a
 
5ec3488
9362e89
 
 
 
5ec3488
2645bd4
e1c578a
9362e89
5ec3488
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from voicefixer import VoiceFixer
import streamlit as st
from audio_recorder_streamlit import audio_recorder
from io import BytesIO
import soundfile as sf
# import noisereduce as nr

st.set_page_config(page_title="VoiceFixer app", page_icon=":notes:")

st.title("Voice Fixer App :notes:")
st.write(
    """
    This app is a mix of [VoiceFixer Model](https://github.com/haoheliu/voicefixer), and a custom
    Streamlit component that [records audio](https://github.com/Joooohan/audio-recorder-streamlit) Online.
    Currently the app shows great results when removing background noises, but 
    speech improvements aren't as obvious.
    """)
#Config files are on voicefixer/base and voicefixer/vocoder/config import
# They were uploaded on hugging face
voicefixer = VoiceFixer()
audio_bytes = audio_recorder(
    pause_threshold= 1.5
)
try:
    data, samplerate = sf.read(BytesIO(audio_bytes))
    #print(samplerate)
    sf.write("original.wav",data,samplerate)
    st.audio(audio_bytes, format = "audio/wav")
    if data.shape[0]>=10000:
        # reduced_noise = nr.reduce_noise(
        #     y= (data[:,0]+data[:,1])/2.0,#data[:,0],#, data X,Should be a single channel
        #     sr=samplerate,
        #     n_fft=512, #512 recommended for speech, 1024 default
        #     stationary=False,
        #     )
        # st.write("[Classic] Background noise reduction:")
        # st.audio(reduced_noise, sample_rate=samplerate)
        placeholder = st.empty()
        placeholder.info("Enhancing Audio...")
        voicefixer.restore(input="original.wav", # low quality .wav/.flac file
                        output="enhanced_output.wav",
                        cuda=False, # GPU acceleration
                        mode=0)
        st.write("[Deep] The Audio without background noises and a little enhancement :ocean:")
        st.audio("enhanced_output.wav")
        placeholder.empty()

        
    else: st.warning("Recorded Audio is too short, try again :relieved:")#wink
except:
    st.info("Try to record some audio :relieved:")