Spaces:
Runtime error
Runtime error
from transformers import pipeline | |
import streamlit as st | |
from st_audiorec import st_audiorec | |
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') | |