Spaces:
Build error
Build error
File size: 1,452 Bytes
63bb482 7d07aea 63bb482 7d07aea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import subprocess
import streamlit as st
import speech_recognition as sr
from streaming_stt_nemo import Model
if "sv_load_flash_attention" not in st.session_state:
subprocess.run(
"pip install flash-attn --no-build-isolation",
env={"FLASH_ATTENTION_SKIP_CUDA_BUILD": "TRUE"},
shell=True,
)
st.session_state.sv_load_flash_attention = True
def main():
st.title("Speech to Text Converter")
# Create a recognizer object
r = sr.Recognizer()
# Create a microphone object
mic = sr.Microphone()
# Continuously listen for audio input
with mic as source:
st.write("Listening...")
while True:
try:
# Adjust the ambient noise threshold for better results
r.adjust_for_ambient_noise(source)
# Listen for audio input
audio = r.listen(source)
# Convert audio to text
default_lang = "en"
engines = {
default_lang: Model(default_lang)
}
model = engines[default_lang]
text = model.stt_file(audio)[0]
# Display the converted text
st.write("You said:", text)
except sr.UnknownValueError:
pass
if __name__ == "__main__":
main() |