Manikeerthan01 commited on
Commit
23c51c5
·
verified ·
1 Parent(s): 33dbb15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -33
app.py CHANGED
@@ -1,32 +1,20 @@
1
- import sounddevice as sd
2
- from scipy.io.wavfile import write
3
  import whisper
4
- import numpy as np
5
  import streamlit as st
6
 
7
- # Streamlit interface
8
  st.title("Audio Transcription with Whisper")
9
 
10
- # Record audio
11
- def record_audio():
12
- fs = 44100
13
- seconds = st.slider("Select recording duration (seconds):", 1, 10, 8)
14
- st.write("Recording Audio - Speak now!")
15
- myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
16
- sd.wait()
17
- write('output.mp3', fs, myrecording)
18
- st.audio('output.mp3', format='audio/mp3')
19
- st.write("Audio recording complete, play audio")
20
 
21
- # Transcribe audio
22
- def transcribe_audio():
23
- model = whisper.load_model("base")
 
24
 
25
- # Load audio and pad/trim it to fit 30 seconds
 
26
  audio = whisper.load_audio("output.mp3")
27
  audio = whisper.pad_or_trim(audio)
28
-
29
- # Make log-Mel spectrogram and move to the same device as the model
30
  mel = whisper.log_mel_spectrogram(audio).to(model.device)
31
 
32
  # Detect the spoken language
@@ -39,16 +27,3 @@ def transcribe_audio():
39
 
40
  # Display the recognized text
41
  st.write(result.text)
42
-
43
- # Main Streamlit application
44
- def main():
45
- st.header("Audio Recorder")
46
- if st.button("Start Recording"):
47
- record_audio()
48
-
49
- st.header("Transcription")
50
- if st.button("Transcribe Audio"):
51
- transcribe_audio()
52
-
53
- if __name__ == "__main__":
54
- main()
 
 
 
1
  import whisper
 
2
  import streamlit as st
3
 
 
4
  st.title("Audio Transcription with Whisper")
5
 
6
+ # File uploader for audio
7
+ uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "m4a"])
 
 
 
 
 
 
 
 
8
 
9
+ if uploaded_file is not None:
10
+ with open("output.mp3", "wb") as f:
11
+ f.write(uploaded_file.getbuffer())
12
+ st.audio("output.mp3")
13
 
14
+ # Transcribe audio
15
+ model = whisper.load_model("base")
16
  audio = whisper.load_audio("output.mp3")
17
  audio = whisper.pad_or_trim(audio)
 
 
18
  mel = whisper.log_mel_spectrogram(audio).to(model.device)
19
 
20
  # Detect the spoken language
 
27
 
28
  # Display the recognized text
29
  st.write(result.text)