Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -1,17 +1,23 @@
|
|
1 |
# utils.py
|
2 |
-
import sounddevice as sd
|
3 |
-
from scipy.io.wavfile import write
|
4 |
import tempfile
|
5 |
import os
|
6 |
import whisper
|
7 |
import json
|
|
|
8 |
|
9 |
def record_audio(duration=5, fs=44100):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def transcribe_audio(audio_path, language="English"):
|
17 |
model = whisper.load_model("base")
|
|
|
1 |
# utils.py
|
|
|
|
|
2 |
import tempfile
|
3 |
import os
|
4 |
import whisper
|
5 |
import json
|
6 |
+
import streamlit as st
|
7 |
|
8 |
def record_audio(duration=5, fs=44100):
|
9 |
+
try:
|
10 |
+
import sounddevice as sd
|
11 |
+
from scipy.io.wavfile import write
|
12 |
+
|
13 |
+
stt_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
14 |
+
recording = sd.rec(int(duration * fs), samplerate=fs, channels=1)
|
15 |
+
sd.wait()
|
16 |
+
write(stt_file.name, fs, recording)
|
17 |
+
return stt_file.name
|
18 |
+
except ImportError:
|
19 |
+
st.error("Recording not supported in this environment. Please upload an audio file instead.")
|
20 |
+
return None
|
21 |
|
22 |
def transcribe_audio(audio_path, language="English"):
|
23 |
model = whisper.load_model("base")
|