Spaces:
Runtime error
Runtime error
Commit
·
76dc8cb
1
Parent(s):
efd8c27
Upload 2 files
Browse files- app.py +33 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import speech_recognition as sr
|
3 |
+
|
4 |
+
def transcribe_audio(audio_file):
|
5 |
+
recognizer = sr.Recognizer()
|
6 |
+
with sr.AudioFile(audio_file) as source:
|
7 |
+
audio_data = recognizer.record(source)
|
8 |
+
try:
|
9 |
+
text = recognizer.recognize_google(audio_data)
|
10 |
+
return text
|
11 |
+
except sr.UnknownValueError:
|
12 |
+
return "Speech recognition could not understand audio"
|
13 |
+
except sr.RequestError as e:
|
14 |
+
return f"Could not request results; {e}"
|
15 |
+
|
16 |
+
def main():
|
17 |
+
st.title("Audio to Text Converter")
|
18 |
+
|
19 |
+
uploaded_file = st.file_uploader("Upload an audio file", type=["wav"])
|
20 |
+
|
21 |
+
if uploaded_file is not None:
|
22 |
+
st.audio(uploaded_file, format='audio/wav')
|
23 |
+
if st.button("Transcribe"):
|
24 |
+
with st.spinner("Transcribing..."):
|
25 |
+
text_result = transcribe_audio(uploaded_file)
|
26 |
+
st.write("Transcript:", text_result)
|
27 |
+
|
28 |
+
if __name__ == "__main__":
|
29 |
+
main()
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
SpeechRecognition==3.10.1
|
6 |
+
streamlit==1.29.0
|