File size: 2,073 Bytes
9528165
835ac33
 
 
24d98ad
489e5a6
bf5d300
489e5a6
 
 
 
 
 
 
bf5d300
 
835ac33
 
c8638c6
 
 
 
 
 
 
 
 
 
9528165
c8638c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9528165
c8638c6
 
9528165
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

from transformers import pipeline
import streamlit as st
from st_audiorec import st_audiorec 
@st.cache_resource
def load_model():
    pipe=pipeline("automatic-speech-recognition","distil-whisper/distil-large-v2")
    return pipe

speech_to_text_model=load_model()

def make_text(audio):
    global speech_to_text_model
    text= speech_to_text_model(audio)
    extract_text=text['text']
    return extract_text

st.title('speech recognition')
col1,col2=st.columns(2)
with col1:
    with st.form(key='record audio'):
        
        #Record an Audio
        wave_audio_data=st_audiorec()
        
        #or upload an audio file
        st.write('Or you can upload an audio file')
        upload=st.file_uploader(label='Upload audio file')

        #submit
        button=st.form_submit_button(label='Convert to Text')
        #if the submit button is pressed 
        if button:
            try:
                #check if audio file
                if wave_audio_data is not None:
                    #do the conversion
                    text=make_text(wave_audio_data)

                    st.write(text)

                else:
                    st.error('Please record an audio', icon='🚨')
            except:
                st.write("we can't process your request at this time")
        else:
            st.success('No Audio data yet')

with col2:
    with st.form(key='file upload '):
         #or upload an audio file
        st.write('Or you can upload an audio file')
        
        upload=st.file_uploader(label='Upload audio file')

        #submit
        button=st.form_submit_button(label='Convert to Text')
        #if the submit button is pressed 
        if button:
            try:
                if upload is not None:
                    text=make_text(upload)

                    st.write(text)

                else:
                    st.error('Please record an audio', icon='🚨')
            except:
                st.write("we can't process your request at this time")
        else:
            st.success('No Audio data yet')