Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import sounddevice as sd
|
3 |
+
import tempfile
|
4 |
+
from scipy.io.wavfile import write
|
5 |
+
import whisper
|
6 |
+
import numpy as np
|
7 |
+
if 'recording' not in st.session_state:
|
8 |
+
st.session_state.recording = False
|
9 |
+
|
10 |
+
def start_recording():
|
11 |
+
st.session_state.recording = True
|
12 |
+
st.write("Recording started... Click 'Stop' to end.")
|
13 |
+
return sd.rec(int(10 * 44100), samplerate=44100, channels=1, dtype='float64', blocking=False)
|
14 |
+
|
15 |
+
def stop_recording(recording):
|
16 |
+
st.session_state.recording = False
|
17 |
+
sd.stop()
|
18 |
+
st.write("Converting speech to text...")
|
19 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.wav')
|
20 |
+
write(temp_file.name, 44100, recording)
|
21 |
+
return temp_file.name
|
22 |
+
|
23 |
+
def transcribe_audio(file_path):
|
24 |
+
model = whisper.load_model("base")
|
25 |
+
result = model.transcribe(file_path)
|
26 |
+
return result['text']
|
27 |
+
|
28 |
+
# Streamlit UI
|
29 |
+
st.title("🗣️Brise")
|
30 |
+
|
31 |
+
if st.button('Start Recording') and not st.session_state.recording:
|
32 |
+
st.session_state.audio_data = start_recording()
|
33 |
+
|
34 |
+
if st.button('Stop Recording') and st.session_state.recording:
|
35 |
+
file_path = stop_recording(st.session_state.audio_data)
|
36 |
+
transcription = transcribe_audio(file_path)
|
37 |
+
st.text_area("Transcription", value=transcription, height=200)
|