Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,22 @@
|
|
1 |
import streamlit as st
|
2 |
-
import speech_recognition as sr
|
3 |
import whisper
|
4 |
-
from io import BytesIO
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
# Function to capture audio using the microphone
|
10 |
-
def capture_audio():
|
11 |
-
with sr.Microphone() as source:
|
12 |
-
st.write("Recording...")
|
13 |
-
audio = recognizer.listen(source)
|
14 |
-
st.write("Recording completed")
|
15 |
-
return audio
|
16 |
-
|
17 |
-
# Convert speech to text using Whisper
|
18 |
-
def transcribe_audio(audio):
|
19 |
-
audio_file = BytesIO(audio.get_wav_data())
|
20 |
model = whisper.load_model("base")
|
21 |
-
transcription = model.transcribe(
|
22 |
return transcription['text']
|
23 |
|
24 |
# Streamlit App Interface
|
25 |
-
st.title("
|
26 |
|
27 |
-
st.write("
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
-
try:
|
32 |
-
audio_data = capture_audio()
|
33 |
-
st.write("Transcribing audio...")
|
34 |
-
transcription = transcribe_audio(audio_data)
|
35 |
-
st.write("Transcription:")
|
36 |
-
st.write(transcription)
|
37 |
-
except Exception as e:
|
38 |
-
st.write(f"An error occurred: {e}")
|
39 |
-
|
40 |
-
# Optionally, provide an option to upload audio files
|
41 |
-
uploaded_file = st.file_uploader("Or upload an audio file", type=["wav", "mp3", "ogg"])
|
42 |
|
43 |
if uploaded_file is not None:
|
44 |
-
st.write("Transcribing
|
45 |
-
|
46 |
-
transcription = model.transcribe(uploaded_file)
|
47 |
st.write("Transcription:")
|
48 |
-
st.write(transcription
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import whisper
|
|
|
3 |
|
4 |
+
# Function to transcribe uploaded audio file
|
5 |
+
def transcribe_audio(uploaded_file):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
model = whisper.load_model("base")
|
7 |
+
transcription = model.transcribe(uploaded_file)
|
8 |
return transcription['text']
|
9 |
|
10 |
# Streamlit App Interface
|
11 |
+
st.title("Speech-to-Text Transcription")
|
12 |
|
13 |
+
st.write("Upload an audio file to get the transcription.")
|
14 |
|
15 |
+
# Upload audio file
|
16 |
+
uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "ogg"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
if uploaded_file is not None:
|
19 |
+
st.write("Transcribing audio...")
|
20 |
+
transcription = transcribe_audio(uploaded_file)
|
|
|
21 |
st.write("Transcription:")
|
22 |
+
st.write(transcription)
|